For Programmers: Free Programming Magazines  


Home > Archive > Tcl > October 2005 > How to find out if bitmaps or images exists?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to find out if bitmaps or images exists?
MartinLemburg@UGS

2005-10-20, 7:00 pm

Hello,

is there any way to detect if a given image name (bitmap or photo)
exists?

Do images have associated commands? The docs gave me this impression,
but ... e.g. ... I don't find any command for the built-in bitmap
questhead, nor an alias.

How can I, providing a tcl API, test for the photo/bitmaps existens?

Best regards,

Martin Lemburg

Pat Thoyts

2005-10-20, 7:00 pm

"MartinLemburg@UGS" <martin.lemburg.ugs@gmx.net> writes:

>Hello,
>
>is there any way to detect if a given image name (bitmap or photo)
>exists?
>
>Do images have associated commands? The docs gave me this impression,
>but ... e.g. ... I don't find any command for the built-in bitmap
>questhead, nor an alias.
>
>How can I, providing a tcl API, test for the photo/bitmaps existens?
>
>Best regards,
>
>Martin Lemburg


image names returns a list of all images present in the interpreter.

images create creates an image and its associated command. Because
image creation will silently overwrite other commands you are advised
to create images in their own namespaces.

At least on windows some of the core Tk images are not really present
- instead the use of the name is recognised and the approprate windows
stock image is called up for you. Also Tk avoids creating images
unless you use them. If you call tk::MessageBox and then call image
names you will suddenly find it populated with images in the
::tk::dialog namespace.

--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
MartinLemburg@UGS

2005-10-21, 3:58 am

Thanks Pat,

so ... if I expect a valid image name to be given to a procedure, I
only can check for a command associated with that image name or use
"image names" to validate this name.

If, like in tk_dialog, the internal bitmap name "questhead" would be
given, I would have to raise an error, because I have no chance to
prove its existense, right?

What's about having the "built-in" images more public and accessable
like all other application made images? E.g. in side a sub namespace of
the ::tk namespace?

Best regards,

Martin

suchenwi

2005-10-21, 7:57 am

proc image'exists name {expr ![catch {image width $name}]}

39 % image'exists image1
1
44 % image'exists image2
0
But as you mention "questhead", that's a bitmap, not an image (even
though [image] also has a "bitmap" subtype...)

MartinLemburg@UGS

2005-10-21, 7:57 am

Ok, that's the way I would do it too, but that's only a workaround.

And ... no matter if "bitmap" or "photo" ... I have only the "image"
command and the image associated commands to take in charge, right?

Ok - that's enough to know.

I still would suggest to change the way of providing the built-in
bitmaps.

Since they are only created on the fly (if needed by a tcl proc or
command), they are not really accessable, but are published in the demo
as built-in, accessable bitmaps.

Why not creating them at startup, putting them into the namespace ::tk
or ::tk::bitmaps and using them instead of creating them on the fly?
Than every "one" can use them if needed.

Best regards,

Martin

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com