I'm trying to add an image or icon to a menubutton (or regular button) and I don't quite get how it works.
What does the first parameter of image-load represent (i.e. photo as in (image-load photo "x.ppm"))? Should I be working with bitmaps instead of images? How does the result of the load get assigned to the widget? And how does the :anchor or :justify get placed on the icon as opposed to the button text or the button itself?
Is there an example of this anywhere?
Thanks,
Bill
The first paramether is a photo object. You can see an example of how to load an image at the source code for cl-cbr: http://common-lisp.net/project/nixies/download/clcbr_latest.tar.gz
But to add an image to a button you only have to pass Its name as a paramether when creating It. If the image isn't in a valid format, Ltk don't loads It. You can use convert, which is part of ImageMagick, to convert images to ppm.
2006/8/16, Bill Ramsay ramsayw1@verizon.net:
I'm trying to add an image or icon to a menubutton (or regular button) and I don't quite get how it works.
What does the first parameter of image-load represent (i.e. photo as in (image-load photo "x.ppm"))? Should I be working with bitmaps instead of images? How does the result of the load get assigned to the widget? And how does the :anchor or :justify get placed on the icon as opposed to the button text or the button itself?
Is there an example of this anywhere?
Thanks,
Bill _______________________________________________ ltk-user site list ltk-user@common-lisp.net http://common-lisp.net/mailman/listinfo/ltk-user
Felip Alàez Nadal wrote:
The first paramether is a photo object. You can see an example of how to load an image at the source code for cl-cbr: http://common-lisp.net/project/nixies/download/clcbr_latest.tar.gz http://common-lisp.net/project/nixies/download/clcbr_latest.tar.gz
But to add an image to a button you only have to pass Its name as a paramether when creating It. If the image isn't in a valid format, Ltk don't loads It. You can use convert, which is part of ImageMagick, to convert images to ppm.
2006/8/16, Bill Ramsay <ramsayw1@verizon.net mailto:ramsayw1@verizon.net>:
I'm trying to add an image or icon to a menubutton (or regular button) and I don't quite get how it works. What does the first parameter of image-load represent (i.e. photo as in (image-load photo "x.ppm"))? Should I be working with bitmaps instead of images? How does the result of the load get assigned to the widget? And how does the :anchor or :justify get placed on the icon as opposed to the button text or the button itself? Is there an example of this anywhere? Thanks, Bill _______________________________________________ ltk-user site list ltk-user@common-lisp.net <mailto:ltk-user@common-lisp.net> http://common-lisp.net/mailman/listinfo/ltk-user
-- Felip Alàez Nadal
ltk-user site list ltk-user@common-lisp.net http://common-lisp.net/mailman/listinfo/ltk-user
I'm sorry, but I'm missing something here.....
What I'm trying to do is create a square tool button with a graphic in the middle of it. Nothing special.
I seem to have a number of ways of doing this:
1) Ideally, I would just add the filepath to the graphic to the :image parameter when I create the button (i.e :image (directory "x.ppm") This compiles, but gives me a LTK::NAME error when I run it.
2) I can try MAKE-IMAGE to create a photo-image and then use IMAGE-LOAD (i.e. :image (image-load photo (directory "x.ppm")) this will compile but not run. I get a TWO-WAY-STREAM error for descriptors 7 and 6.
3) If I do the same as 2, but not use "directory" it compiles and runs, but there's no image
4) If I do the same as 2, but use MAKE-INSTANCE to create a photo-image, it compiles and runs, but there is no image
I know that in X you have to create a window as the place to draw the loading image and then move or copy the image to the place you want to put it. Isn't that what's happening when you MAKE-IMAGE and then use IMAGE-LOAD. (I don't quite see how this affects the :image assignment for the button).
I'm sure this is not difficult to do, but everything I try fails. What I would like to see is the code for toolbutton with an image in the middle that works. The example you refered me to wasn't quite the same thing.
Sorry for the long reply...
Bill
Hello: The code I send just creates a button with an image on It. Be sure to run It from within the directory It creates.
Felip Alàez Nadal wrote:
Hello: The code I send just creates a button with an image on It. Be sure to run It from within the directory It creates.
-- Felip Alàez Nadal
ltk-user site list ltk-user@common-lisp.net http://common-lisp.net/mailman/listinfo/ltk-user
When I try to run it I get the following error:
debugger invoked on a SB-INT:STREAM-ENCODING-ERROR: encoding error on stream #<SB-SYS:FD-STREAM for "descriptor 6" {9E04D39}> (:EXTERNAL-FORMAT :ASCII): the character with code 242 cannot be encoded.
However, I pretty much do the same thing you are doing:
(let* ((img
(xbut (make-instance 'button :master nil :image (image-load img "x.ppm")))...
In this case I get an error because img is nil. In your code, you do basically the same thing with the variable imatge. I have tried making img a photo-image with (img (make-image)), and in that case the error goes away but the button appears with no image in it (and no other errors). (I've used the ppm image before, so I know it's a good image).
I should note that I'm running this in SBCL on an AMD64 laptop running linux.
I'm sure this works. I just can't figure out what I'm doing wrong.
Bill
On 8/20/06, Bill Ramsay ramsayw1@verizon.net wrote:
Felip Alàez Nadal wrote:
Hello: The code I send just creates a button with an image on It. Be sure to run It from within the directory It creates.
-- Felip Alàez Nadal ________________________________
_______________________________________________ ltk-user site list ltk-user@common-lisp.net http://common-lisp.net/mailman/listinfo/ltk-user When I try to run it I get the following error:
debugger invoked on a SB-INT:STREAM-ENCODING-ERROR: encoding error on stream #<SB-SYS:FD-STREAM for "descriptor 6" {9E04D39}> (:EXTERNAL-FORMAT :ASCII): the character with code 242 cannot be encoded.
However, I pretty much do the same thing you are doing:
(let* ((img (xbut (make-instance 'button :master nil
:image (image-load img "x.ppm")))...
image-load returns nil, it is called only for side-effect (will change it so that it returns the image in the next ltk release)
Peter