| Re: Text Widget Confession [message #26771 is a reply to message #26626] |
Fri, 21 September 2001 10:28  |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
David Fanning wrote:
>
> Folks,
>
> Alright, I confess. Text widgets have always confused
> the hell out of me. And for years I have avoided using
> them, except in the very simplest way, and then only
> when I could find no alternative. (I've found mind-
> reading only partially successful.)
>
> Here is the deal. I have a text widget with
> a three-element string array in it:
>
> theText = ['Dog', 'Cow', 'Coyote']
>
> When displayed in the text widget it looks like this:
>
> Dog
> Cow
> Coyote
>
> I want to make a selection in the text widget.
> Then, when the user says "Do It", I want to
> delete any lines that are in the selection.
>
> For example, if the user selects the word "Cow"
> and clicks "Do It", I want to delete the second
> line in the text widget. If the user selects
> "g Cow", I want to delete the first two lines, etc.
>
> Pretty straightforward, don't you think?
>
> But I've been fooling around with this for two hours
> now and haven't come up with anything remotely useful.
>
> I can get the selection offset and length:
>
> selection = Widget_Info(textID, /Text_Select)
>
> In the case in which the word "Cow" is selected,
> the offset is 5 and the length of the selection
> is 3. An offset of 5!? Into what array?
>
> Check the number of characters in the text widget:
>
> numchar = Widget_Info(textID, /Text_Number)
>
> I get 18. Wait a minute. d-o-g-... I have 12
> characters. But I have three elements in my
> string array, and the longest of these elements
> is 6 characters. 3 times 6 = 18. Can it be!?
>
> No, I convert the text to a byte array and use
> the selection offsets and length to try to fish
> the selection out. No luck. An offset of 5
> still doesn't compute.
>
> OK, let's convert the offset to "column and line"
> values. That "line" business sounds promising.
>
> cl = Widget_Info(textID, Text_Offset_To_XY=selection[0])
> Print, cl
> 2 1
>
> Well, column equals 2 is confusing. But line 1 looks
> promising. I'm definitely in line 1!!! But, if I select
> "ow" instead of "Cow" I now get the values 0 and 2 for
> column and line. Sigh...
>
> Here is some example code I'm using to explore the
> possibilities. Does anyone have any ideas?
>
> Cheers,
>
> David
>
Dear David,
I will explain what happens.
The text in the text widget if you set ysize=1 will be a long line
of 'DogCowCoyote'.
Then if you click somewhere in the text you get the offset right
back.
OK you like to have each word in a line, the smalles ysize could be 3.
Now Dog gets a linebreak character at the end, Cow and Coyote too.
That's the reason why you have at the end of Coyote an offset of 14
characters
by linux. Windows has two characters 10b and 13b at each line this means
an
offset of about 16.
This makes it very difficulty to use a text widget instead of the table
or list
widget.
I would prefer the list widget. It's very easy to exchange it in your
code.
cheers
Reimar
--
Reimar Bauer
Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
http://www.fz-juelich.de/icg/icg1/
============================================================ ======
a IDL library at ForschungsZentrum Juelich
http://www.fz-juelich.de/icg/icg1/idl_icglib/idl_lib_intro.h tml
http://www.fz-juelich.de/zb/text/publikation/juel3786.html
============================================================ ======
read something about linux / windows
http://www.suse.de/de/news/hotnews/MS.html
|
|
|
|