Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to retrieve a text string information

10 views
Skip to first unread message

maura.m...@gmail.com

unread,
Jul 15, 2006, 3:15:17 PM7/15/06
to
I have a GUI made up of a panel (buttons, entries, radiobuttons, menus,
etc..) and a canvas where the GUI user can have some scientific data
displayed in form of isocountour maps.
A new feature I've recently implemented allows for changing the canvas
aspect ratio, which is done by properly rescaling all the objects laid
on the canvas.
Once the lay-out is complete the user can place an arbitrary number of
text strings in arbitrary positions on the canvas. Since these text
strings are not part of the pool of graphic objects that are re-drawn
when the canvas is rescaled or the user browses back/forth among the
last 10 canvas lay-outs, the text strings do not rescale upon changing
the aspect ratio. They stay where they are.
So a special code branch must be developed to make these texts
rescalable and movable as the other graphic items.

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

Uwe Klein

unread,
Jul 15, 2006, 3:36:35 PM7/15/06
to
Hi,

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

Uwe Klein

unread,
Jul 15, 2006, 3:35:14 PM7/15/06
to
Message has been deleted

maura.m...@gmail.com

unread,
Jul 15, 2006, 11:38:40 PM7/15/06
to
It's a great idea but I forsee three possible obstacles at
implementing it.

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

Jeff Godfrey

unread,
Jul 16, 2006, 12:21:01 AM7/16/06
to
<maura.m...@gmail.com> wrote in message
news:1153021120.7...@s13g2000cwa.googlegroups.com...

> It's a great idea but I forsee three possible obstacles at
> implementing it.
>
> 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) ?

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


Cameron Laird

unread,
Jul 16, 2006, 12:53:40 AM7/16/06
to
In article <1153021120.7...@s13g2000cwa.googlegroups.com>,
maura.m...@gmail.com <maura.m...@gmail.com> wrote:
.
.
.

>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 ?
.
.
.
I don't understand the questions. I'm reasonably sure Tk's
answers will be, "Yes". Fonts are a bit annoying to program,
but what I think you want is achievable.

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.

Cameron Laird

unread,
Jul 16, 2006, 12:47:10 AM7/16/06
to
>It's a great idea but I forsee three possible obstacles at
>implementing it.
>
>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) ?
.
.
.
Yes.

Tags are great fun; yes, you can use the same tag on different canvas objects.

0 new messages