Prev: anybody using the hv3 browser much?
Next: Tcl/Tk 8.5.8: How to check the existence of an image in memory?
From: jmc on 26 Jul 2010 12:17 Hello, On the console, I create an image, and after, try to verify this image is actually created : Here is a "copy and paste" for what I did : (Images) 32 % image create photo testRawImage -data $rawData testRawImage (Images) 33 % info exists testRawImage 0 I believe "info exists" (Tcl) is not the right tool to make a check for the result of a Tk command, but looking in the doc either for "winfo" or "info" command, I can't find anything which suit my need. Thanks in advance. Jean-Marie
From: jmc on 26 Jul 2010 13:18 On 26 juil, 18:33, George Petasis <petas...(a)yahoo.gr> wrote: > ΣÏÎ¹Ï 26/7/2010 7:17 μμ, ο/η jmc ÎγÏαÏε: > > > > > Hello, > > > On the console, I create an image, and after, try to verify this image > > is actually created : > > > Here is a "copy and paste" for what I did : > > > (Images) 32 % image create photo testRawImage -data $rawData > > testRawImage > > (Images) 33 % info exists testRawImage > > 0 > > > I believe "info exists" (Tcl) is not the right tool to make a check > > for the result of a Tk command, but looking in the doc either for > > "winfo" or "info" command, I can't find anything which suit my need. > > > Thanks in advance. > > > Jean-Marie > > There are several way to check: > > 1) image names returns a list of all images. You can check if the image > is in the returned list. > > 2) Another way is to check commands, if you know the image command name: >   llength [info commands image_name] == 1 > > 3) Call the image command directly: <image_name> cget - height, around a > catch statement. > > George (I don't see my preceding reply posted - sorry for repetition) Thanks George : "image names" suit my need Jean-Marie
From: jmc on 26 Jul 2010 16:39 On 26 juil, 19:33, "Gerald W. Lester" <Gerald.Les...(a)KnG- Consulting.net> wrote: > jmc wrote: > > Hello, > > > On the console, I create an image, and after, try to verify this image > > is actually created : > > > Here is a "copy and paste" for what I did : > > > (Images) 32 % image create photo testRawImage -data $rawData > > testRawImage > > (Images) 33 % info exists testRawImage > > 0 > > > I believe "info exists" (Tcl) is not the right tool to make a check > > for the result of a Tk command, but looking in the doc either for > > "winfo" or "info" command, I can't find anything which suit my need. > > While George gave you a solution, I'd like to point out why [info exists] > did not work -- it checks for the existence of a *variable* not a command.. > The [image create] command creates a new command, not a variable. > > -- > +------------------------------------------------------------------------+ > | Gerald W. Lester, President, KNG Consulting LLC | > | Email: Gerald.Les...(a)kng-consulting.net | > +------------------------------------------------------------------------+ Thanks Gerald for this precision. I read this in the doc and forget it quite immediately because it is not clear to me : a) on what does act this "command" (the name of an image for instance) ? b) It seems that this kind of user defined command in Tcl/Tk has not the same meaning as others like "proc". I'm not sure but reading the doc I would bet that "info command" doesn't output image names (defined as command). Jean-Marie
From: jmc on 26 Jul 2010 18:36 On 26 juil, 23:12, "Gerald W. Lester" <Gerald.Les...(a)KnG- Consulting.net> wrote: > jmc wrote: > > On 26 juil, 19:33, "Gerald W. Lester" <Gerald.Les...(a)KnG- > > Consulting.net> wrote: > >> jmc wrote: > >>> Hello, > >>> On the console, I create an image, and after, try to verify this image > >>> is actually created : > >>> Here is a "copy and paste" for what I did : > >>> (Images) 32 % image create photo testRawImage -data $rawData > >>> testRawImage > >>> (Images) 33 % info exists testRawImage > >>> 0 > >>> I believe "info exists" (Tcl) is not the right tool to make a check > >>> for the result of a Tk command, but looking in the doc either for > >>> "winfo" or "info" command, I can't find anything which suit my need. > >> While George gave you a solution, I'd like to point out why [info exists] > >> did not work -- it checks for the existence of a *variable* not a command. > >> The [image create] command creates a new command, not a variable. > > > Thanks Gerald for this precision. I read this in the doc and forget it > > quite immediately because it is not clear to me : > > > a) on what does act this "command" (the name of an image for > > instance) ? > > It acts on the created image. The particular subcommands depend on the type > of image, photo or bitmap. To see what subcommands are available look at > the appropriate man/help page (photo or bitmap). > > > b) It seems that this kind of user defined command in Tcl/Tk has not > > the same meaning as others like "proc". I'm not sure but reading the > > doc I would bet that "info command" doesn't output image names > > (defined as command). > > It indeed has the exact same meaning as other commands. BTW, you lose your > bet on the [info command] -- you owe me a bottle of good beer! :) > > Try: > image create photo testRawImage -data $rawData > info command *RawImage > > -- > +------------------------------------------------------------------------+ > | Gerald W. Lester, President, KNG Consulting LLC | > | Email: Gerald.Les...(a)kng-consulting.net | > +------------------------------------------------------------------------+ Just verified (should have done before...). And yes I can see now the usefullness of patern matching for such command... Ok I loose my bet and I owe you a really good beer! Thanks again for your explanation. Jean-Marie
From: jmc on 26 Jul 2010 20:38 On 27 juil, 01:24, S...(a)ControlQ.com wrote: > On Mon, 26 Jul 2010, jmc wrote: > > Hello, > > > On the console, I create an image, and after, try to verify this image > > is actually created : > > > Here is a "copy and paste" for what I did : > > > (Images) 32 % image create photo testRawImage -data $rawData > > testRawImage > > (Images) 33 % info exists testRawImage > > 0 > > > I believe "info exists" (Tcl) is not the right tool to make a check > > for the result of a Tk command, but looking in the doc either for > > "winfo" or "info" command, I can't find anything which suit my need. > > > Thanks in advance. > > > Jean-Marie > > Jean-Marie, > > I took the slightly different approach of creating the image when > needed, and then caching it, so that you use a simple interface to > reference ALL images ... > > namespace eval img { > array set pic {} > > proc getImage { clr btn } { > set idx [format "%s_%s" $clr $btn] > set ix [lsearch [array names img::pic] $idx] > if { $ix < 0 } { > return [img::newImage $clr $btn] > } > return $img::pic($idx) > } > > proc newImage { clr btn } { > set idx [format "%s_%s" $clr $btn] > set img::pic($idx) {} > if [file exists images/$clr/$btn.gif ] { > set img::pic($idx) [image create photo img_$idx] > $img::pic($idx) read images/$clr/$btn.gif > } > return $img::pic($idx) > } > > } > > grid configure [ttk::button $btn -image [img::getImage $clr $b] -command doSomething ] > -row $r -column $c > > This uses namespaces, and creates an array indexed by the colour and name > of the image file ... if the image exists, the pre-created reference is > returned by getImage, and if not, getImage references newImage to create it, > and saves the reference ... In my case it was convenient to index by colour > and name, but this is entirely dependant upon your problem domain ... it is > particularly useful for icons and button labels ... > > HTH, Cheers, > Rob Sciuk. Thanks Rob. Very interesting. I didn't realize it was possible to store a command in an array. Cool ! Jean-Marie
|
Next
|
Last
Pages: 1 2 Prev: anybody using the hv3 browser much? Next: Tcl/Tk 8.5.8: How to check the existence of an image in memory? |