tk again (question)
Tim Writer
tim-s/rLXaiAEBtBDgjK7y7TUQ at public.gmane.org
Mon Mar 1 17:32:08 UTC 2004
"Peter L. Peres" <plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org> writes:
> I know there are a number of very knowledgeable people here, so I'll ask:
>
> In wish, I have a canvas c with some objects on it. I would like to
> retrieve the object types t, their location l and their config options o
> and store them in a form that can later be passed to a statement like $c
> create $t $l $o to regenerate them on another canvas.
>
> The question is, the command $c itemconfigure $n returns a really strange
> set of options that need to be parsed and altered a lot to be re-parsable
> in a statement like $c create <type> $l $o. Note that the problem appears
> with $o only, the other elements ($t, $l) are easy. The real question
> is: where is this subject treated (book, message etc), if at all ?
> (Obviously there are no answers in my docs or on google - none I could
> find, that is).
>
> Simple script to show problem follows:
>
> set c .c
> canvas $c
> pack $c
> $c create rectangle 10 10 20 20 -fill blue -tags {one two}
> set o [$c itemconfigure 1]
>
> o is:
>
> % {-activedash {} {} {} {}} {-activefill {} {} {} {}} {-activeoutline {}
> {} {} {}} {-activeoutlinestipple {} {} {} {}} {-activestipple {} {} {} {}}
> {-activewidth {} {} 0.0 0.0} {-dash {} {} {} {}} {-dashoffset {} {} 0 0}
> {-disableddash {} {} {} {}} {-disabledfill {} {} {} {}} {-disabledoutline
> {} {} {} {}} {-disabledoutlinestipple {} {} {} {}} {-disabledstipple {} {}
> {} {}} {-disabledwidth {} {} 0.0 0} {-fill {} {} {} blue} {-offset {} {}
> 0,0 0,0} {-outline {} {} black black} {-outlineoffset {} {} 0,0 0,0}
> {-outlinestipple {} {} {} {}} {-state {} {} {} {}} {-stipple {} {} {} {}}
> {-tags {} {} {} {one two}} {-width {} {} 1.0 1.0}
>
> (really)
>
> $o is not in a form that can be passed to $c create ... how do I make it
> to be so ? I tried to reformat it using:
>
> foreach l $o {
> foreach i $l {
> if { $i != "" } {
> if {[llength $i]==1} {
> puts -nonewline "$i "
> } else {
> puts -nonewline "{$i} "
> }
> }
> }
> puts " \\"
> }
>
> but several ingredients are missing.
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
--
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