My first idea was to limit the number of such text strings to, say, 10.
Then I would push onto a stack some information that identifies the
single text string and allows me to
manipulate it at a later time than its creation date. Upon changing the
canvas aspect ratio I would pop up the stack the text strings
information and apply the proper text coordinates rescaling.
My question sis: which information about the single text string shall I
save onto the stack in order to manipulate the text string later upon
request ?
I'd say the text string coordinates of its lower left corner (or any
other corner), the number of characters, the character font (which
tells me the character width and height), the text orientation,
the character string itself.... what else ?
Maybe I need fewer data ...? Or maybe I can just save the unique ID
that the Tcl interpreter assigns to each object. I guess such ID
identifies the object uniquely thus allows for retrieval of all its
data.
But do I have access to such an ID ? How ?
If I could just save the text IDs onto the stack then how should I
manipulate the text string coordinates through its ID ?
Thanks a lot for your help.
Maura
what about "tagging" these text elements during
creation:
$canv create text .... -tags {special_text tagged_for_rescaling ..}
or later
$canv addtag ..
and then do when it is time to rescale:
foreach item [$canv find withtag {tagged_for_rescaling} ] {
# do the rescaling
}
to keep the items on top
$canv raise tagged_for_rescaling
tagging can be used to advantage,
"find withtag" and imho all other ops that accept tags
allow operating on items selected by logigal ops on tags
i.e tagA||tagB works.
look into the canvas manpage: "ITEM IDS AND TAGS"
uwe
1. Users can place any number of such text strings at will. May I tag
all these text strings the same way (using the same tag) ?
2. By rescaling I mean to multiply the single object y-coordinate by
the inverse of the new aspect ratio. The default aspect ratio is 1:1..
The only other choice is 16:9.
Is this possible by retrieving the text strings through their common
tag ?
I do not use the Tk command "rescale" as it does not result in a canvas
whose aspect ratio is 16:9.
3. Should I need to rescale the text strings font as well (possibly
just choosing a smaller font) is this possible by retrieving the text
strings though the tag ?
Thank you very much for your help.
Maura
Sure. In fact, that's a very common use for tags (tagging "common"
items with a "common" tag).
> 2. Is this possible by retrieving the text strings through their
> common
> tag ?
> 3. Should I need to rescale the text strings font as well (possibly
> just choosing a smaller font) is this possible by retrieving the
> text
> strings though the tag ?
Sure. Say you've tagged your items with the tag "text". You can find
(and modify) all of the text items using something like this:
foreach item [.c find withtag text] {
set oldText [.c itemcget $item text]
.c itemconfigure $item "New Text"
}
In your particular case (finding "text" type canvas elements), you
could also use the canvas "type" subcommand. Something like:
foreach item [.c find all] {
set type [.c type $item]
if {$type eq "text"} {
puts "text item found"
}
}
Note, the above code snippets were just typed into this message, so
while they could contain errors, they should be fairly close... ;^)
Jeff
Do you have a good Tcl reference? Font management should ap-
pear there. If you don't have a book, I recommend one; it
sounds as though you're going to be spending quite a bit of
time with Tcl/Tk, and the investment will pay off.
Tags are great fun; yes, you can use the same tag on different canvas objects.