tk again (question)

Peter L. Peres plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Sun Feb 29 22:42:48 UTC 2004


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. My tk_version is 8.4something (I know
I should upgrade but is this problem fixed ?). My current idea is to take
the option and print it iff it has an arg that is not null, or zero (or
1.0 ? or ?!!) and to print the first and last arg or list only in that
case. How does that sound ?

tia,
Peter


--
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