tk again (question)
Tim Writer
tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Mon Mar 1 23:31:49 UTC 2004
"Peter L. Peres" <plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org> writes:
> On Mon, 1 Mar 2004, Tim Writer wrote:
>
> --snip--
> >
> > The format of the list returned by itemconfigure is documented (more or less)
> > by "man Tk_ConfigureInfo". This should help:
> >
> > # This first part is identical to your script
> > set c .c
> > canvas $c
> > pack $c
> > $c create rectangle 10 10 20 20 -fill blue -tags {one two}
> > set o [$c itemconfigure 1]
> >
> > # Now create a script to create another rectangle with same attributes
> > set script [list $c create rectangle 30 30 40 40]
> > foreach configSpec $o {
> > foreach {argvName dbName dbClass defValue curValue} $configSpec {}
> > lappend script $argvName $curValue
> > }
> >
> > # Create new rectangle
> > eval $script
>
> This is clear. Now I understand that I only need to record those options
> which are different from default to recreate the options, so I could
> write:
>
> ...
> foreach configSpec $o {
> foreach {argvName dbName dbClass defValue curValue} \
> $configSpec {} {
Careful! You have an extra set of braces above. This:
foreach {argvName dbName dbClass defValue curValue} $configSpec {}
is the same as:
foreach {argvName dbName dbClass defValue curValue} $configSpec {
# do nothing
}
which is a shorthand (idiomatic Tcl) for:
set argvName [lindex $configSpec 0]
set dbName [lindex $configSpec 1]
set dbClass [lindex $configSpec 2]
set defValue [lindex $configSpec 3]
set curValue [lindex $configSpec 4]
If this was Perl, you might write:
my ($argvName, $dbName, $dbClass, $defValue, $curValue) = @configSpec;
> # not sure about != {} or != "" - should be the same
> if {($curValue != {}) && ($defValue != $curValue)} {
> lappend script $argvName $curValue
> }
I would just write:
if {$curValue != $defValue} {
lappend script $argvName $curValue
}
With your test, if $curValue is {} and $defValue is something other than
{}, you don't record it.
--
tim writer <tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org> starnix inc.
905.771.0017 ext. 225 thornhill, ontario, canada
http://www.starnix.com professional linux services & products
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list