comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Text Widget Confession
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Text Widget Confession [message #26626] Fri, 21 September 2001 09:08 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
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

************************************************************
PRO Example_Event, event
Widget_Control, event.top, Get_UValue=textID

; Get the current text selection.

selection = Widget_Info(textID, /Text_Select)
Print, ""
Print, 'Selection Offset: ', selection[0]
Print, 'Selection Length: ', selection[1]

; Print the number of characters in the text value.

numchar = Widget_Info(textID, /Text_Number)
Print, 'Number of Characters in Text Widget: ', numchar

; Try to find the word using the offsets and lengths.
; No luck

Widget_Control, textID, Get_Value=theText
array = Byte(theText)
IF selection[1] NE 0 THEN BEGIN
word = array[selection[0]:selection[0]+selection[1]-1]
Print, 'Bytes Selected: ', word
Print, 'Selected Word: ', String(word)
ENDIF ELSE Print, 'No Selection'

; Get the selected text. OK, I can find the selected
; text, but what lines do I have?

Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
Print, 'Selected Text: ', selectText

; Try to convert text offset to columns and lines (?).

cl = Widget_Info(textID, Text_Offset_To_XY=selection[0])
Print, 'Offset starts in this column: ', cl[0]
Print, 'Offset starts in this line: ', cl[1]

END; -----------------------------------

PRO Example
tlb = Widget_Base(Column=1)
button = Widget_Button(tlb, Value='Do It')
textID = Widget_Text(tlb, Scr_XSize=100, $
YSize=20,Value=['Dog', 'Cow', 'Coyote'])
Widget_Control, tlb, /Realize, Set_UValue=textID
XManager, 'example', tlb, /No_Block
END; -----------------------------------
************************************************************

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26724 is a reply to message #26626] Tue, 25 September 2001 12:44 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> P.S. Are you ready for a Contour puzzle, or do
> you have to go back to work?

What do you mean! I *am* at work. I just can't come up with a function
to fit a distribution that seems to be a power function degrading into a
linear one after a while, so I am trying to convince myself that I am
solving some important issue, and for that reason making no progress on
the damn fit. I am almost at the point of making a lookup table :-(

Cheers,
Pavel

P.S. What the heck, send the Contour. Craig will be done with it before
I even figure out what the problem is :-)
Re: Text Widget Confession [message #26725 is a reply to message #26626] Tue, 25 September 2001 12:17 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:

> I am sorry. I forgot there some inferior platforms are confused about
> all the CR-LF and such...
> The following Beta 2.02.0001-20010925-b has been tested on Mac, W2K and
> HP-UX. Sorry, I am out of platforms. Besides, it is backwards compatible
> with IDL 5.3 now. Other requests?

Well, I can't find anything wrong with it.
But I'm pretty easy to please. I'm going to see
what everyone else has to say before I get my
check book out again. :-)

Well done, Sir!

Cheers,

David

P.S. Are you ready for a Contour puzzle, or do
you have to go back to work?

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26726 is a reply to message #26626] Tue, 25 September 2001 10:33 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> Oh, I don't think so. :-(
>
> In fact, this may be worse.
> But keep working.

I am sorry. I forgot there some inferior platforms are confused about
all the CR-LF and such...
The following Beta 2.02.0001-20010925-b has been tested on Mac, W2K and
HP-UX. Sorry, I am out of platforms. Besides, it is backwards compatible
with IDL 5.3 now. Other requests?

;****************
PRO Example_Event, event
Widget_Control, event.top, Get_UValue=textID
Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
Widget_Control, textID, Get_Value=theText
; Added line
loc = Widget_Info(textID, /Text_Select)
loc = loc[0] - loc[1]*(!version.os_family eq 'Windows')
; End added line
jt = strjoin(thetext, string(1b))
js = strjoin(selecttext, string(1b))
rs = jt
; Modified line
strput, rs, string( byte(js) < 2b), strpos(jt, js, loc)
; End modified line
good_rows = where(strsplit(rs, string(1b), /extract) $
eq theText, count)
if count ne 0 then theText = theText[good_rows]
Widget_Control, textID, Set_Value=theText
END; -----------------------------------;****************

Cheers,
Pavel
Re: Text Widget Confession [message #26728 is a reply to message #26626] Tue, 25 September 2001 09:22 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:

> Ok. Version 2.01-1723-b01.67, beta release. Bugs fixed: one letter
> selections and wierd combinations of such will not confuse the program.
> Changes: One line change, but was very hard, because you gotta know
> which line to change.
> Disclaimer: if works as promised or does not, the author bears no
> responsibility. Use with caution, may cause amazement and dizziness due
> to unbelievable reliability. Do not acknowledge the author for the fear
> of overwhelming response and eternal admiration.

Oh, I don't think so. :-(

In fact, this may be worse.

Grab the recorder, which has this algorithm implemented:

ftp://ftp.dfanning.com/pub/dfanning/outgoing/misc/recorder__ define.pro

Then, try this:

IDL> o=obj_new('recorder', text=['dog','cow','coyote','dog','rooster'])
IDL> o->gui

Now select the second "dog". Click delete. The first dog disappears.

Now select from the last "e" in coyote to the first "r" in
rooster. Click delete. *Everything* disappears!

Don't forget to destroy that object!

IDL> Obj_Destroy, o

But keep working. I haven't spent that *entire* $100 on
beer... yet. :-)

Cheers,

David

P.S. Let's just say if anyone solves this one, I have
another little puzzler involving contour plots that is
also causing me to pull my hair out. :-(

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26730 is a reply to message #26626] Tue, 25 September 2001 08:57 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Ok. Version 2.01-1723-b01.67, beta release. Bugs fixed: one letter
selections and wierd combinations of such will not confuse the program.
Changes: One line change, but was very hard, because you gotta know
which line to change.
Disclaimer: if works as promised or does not, the author bears no
responsibility. Use with caution, may cause amazement and dizziness due
to unbelievable reliability. Do not acknowledge the author for the fear
of overwhelming response and eternal admiration.

PRO Example_Event, event
Widget_Control, event.top, Get_UValue=textID
Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
Widget_Control, textID, Get_Value=theText
; Added line
loc = (Widget_Info(textID, /Text_Select))[0]
; End added line
jt = strjoin(thetext, string(1b))
js = strjoin(selecttext, string(1b))
rs = jt
; Modified line
strput, rs, string( byte(js) < 2b), strpos(jt, js, loc)
; End modified line
junk = where(strsplit(rs, string(1b), /extract) $
ne theText, comp=good_rows, ncomp=count)
if count ne 0 then theText = theText[good_rows]
Widget_Control, textID, Set_Value=theText
END; -----------------------------------

Cheers,
Pavel
Re: Text Widget Confession [message #26736 is a reply to message #26626] Mon, 24 September 2001 12:46 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Don J Lindler (lindler@rockit.gsfc.nasa.gov) writes:

> I have not run the code, but it looks to me that if your text widget had
> something like:
>
> hog
> dog
> dig
>
> and you selected the og from dog and the d from dig. The code would select
> the og from hog and the d from dog. The strpos would find the first
> occurence of the string.

W-A-A-I-I-T, don't cash that check!!!

Humm. Alright. In the actual application there
is probably a very small chance something like this
could happen, but it is not impossible.

The code is simple enough, I'll make it available
for anyone who wants to have a go at solving this
problem. You can find it here:

ftp://ftp.dfanning.com/pub/dfanning/outgoing/misc/recorder__ define.pro

You will get it running like this:

IDL> o = obj_new('recorder', text=['pig','dog','cow','pig','coyote'])
IDL> o->gui

You can add text to it like this:

IDL> o->AddText, 'rooster'

The code you want to fool around with is in the object
method named Recorder::DeleteIt.

So many people are involved now I should offer a prize.
OK, First Prize is Liam's book, Last Prize is my book. :-(

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26737 is a reply to message #26626] Mon, 24 September 2001 12:10 Go to previous message
Paul van Delst is currently offline  Paul van Delst
Messages: 364
Registered: March 1997
Senior Member
Don J Lindler wrote:
>
> I have not run the code, but it looks to me that if your text widget had
> something like:
>
> hog
> dog
> dig
>
> and you selected the og from dog and the d from dig. The code would select
> the og from hog and the d from dog.

You don't happen to write under a psuedonym of Dr Seuss do you? :o)

paulv

--
Paul van Delst Religious and cultural
CIMSS @ NOAA/NCEP purity is a fundamentalist
Ph: (301)763-8000 x7274 fantasy
Fax:(301)763-8545 V.S.Naipaul
Re: Text Widget Confession [message #26738 is a reply to message #26626] Mon, 24 September 2001 11:41 Go to previous message
Don J Lindler is currently offline  Don J Lindler
Messages: 19
Registered: April 2001
Junior Member
I have not run the code, but it looks to me that if your text widget had
something like:

hog
dog
dig

and you selected the og from dog and the d from dig. The code would select
the og from hog and the d from dog. The strpos would find the first
occurence of the string.

Don
lindler@rockit.gsfc.nasa.gov


"David Fanning" <david@dfanning.com> wrote in message
news:MPG.1619113bbea36aa89896c2@news.frii.com...
> Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:
>
>> David Fanning wrote:
>>>
>>> It turns out a list widget, although simplifying my
>>> life, made other things more complicated.
>>
>> You could use widget_text, then, by modifying the code above to include
>> the following (sorry for not providing this to start with :-):
>>
>> junk = where(strsplit(rs, string(1b), /extract) $
>> ne theText, comp=good_rows, ncomp=count)
>> if count ne 0 then theText = theText[good_rows]
>> Widget_Control, textID, Set_Value=theText
>>
>> Its not copyrighted, you know :-)
>
> No, I realize it's not copyrighted. But I feel
> obligated to send you a check for $100 anyway
> to compensate you for your time and effort. :-)
>
> Cheers,
>
> David
>
> P.S. In case you are interested, here is the final
> code responding to the Delete button:
>
> ************************************************************ ************
> PRO Recorder::DeleteIt, event
>
> ; The method event handler deletes text lines in the current selection.
>
> ; Get the current text selection.
>
> Widget_Control, self.textID, Get_Value=selectText, /Use_Text_Select
>
> ; Get the text itself.
>
> theText = *self.text
>
> ; Hocus-pocus provided by Pavel Romashkin to circumvent
> ; RSI-supplied nonsense. V-E_R-Y clever! :-)
>
> jt = StrJoin(theText, String(1b))
> js = StrJoin(selectText, String(1b))
> rs = jt
> StrPut, rs, String( Byte(js) < 2b), StrPos(jt, js)
> selection = Where(StrSplit(rs, String(1b), /Extract) NE thetext)
>
> ; Error checking. Look for no selection values.
>
> IF N_Elements(selection) EQ 1 THEN BEGIN
> IF selection[0] EQ -1 THEN RETURN
> ENDIF
>
> ; Error checking. Look for no overlap between the two vectors.
>
> overlap = self->SetDifference(Indgen(N_Elements(*self.text)), selection)
> IF N_Elements(overlap) EQ 1 THEN BEGIN
> IF overlap[0] EQ -1 THEN BEGIN
> *self.text = ""
> ENDIF ELSE BEGIN
> *self.text = (*self.text)[overlap]
> ENDELSE
> ENDIF ELSE *self.text = (*self.text)[overlap]
>
>
> Widget_Control, self.textID, Set_Value=*self.text
>
> END
> ************************************************************ ************
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26741 is a reply to message #26626] Mon, 24 September 2001 09:46 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:

> David Fanning wrote:
>>
>> It turns out a list widget, although simplifying my
>> life, made other things more complicated.
>
> You could use widget_text, then, by modifying the code above to include
> the following (sorry for not providing this to start with :-):
>
> junk = where(strsplit(rs, string(1b), /extract) $
> ne theText, comp=good_rows, ncomp=count)
> if count ne 0 then theText = theText[good_rows]
> Widget_Control, textID, Set_Value=theText
>
> Its not copyrighted, you know :-)

No, I realize it's not copyrighted. But I feel
obligated to send you a check for $100 anyway
to compensate you for your time and effort. :-)

Cheers,

David

P.S. In case you are interested, here is the final
code responding to the Delete button:

************************************************************ ************
PRO Recorder::DeleteIt, event

; The method event handler deletes text lines in the current selection.

; Get the current text selection.

Widget_Control, self.textID, Get_Value=selectText, /Use_Text_Select

; Get the text itself.

theText = *self.text

; Hocus-pocus provided by Pavel Romashkin to circumvent
; RSI-supplied nonsense. V-E_R-Y clever! :-)

jt = StrJoin(theText, String(1b))
js = StrJoin(selectText, String(1b))
rs = jt
StrPut, rs, String( Byte(js) < 2b), StrPos(jt, js)
selection = Where(StrSplit(rs, String(1b), /Extract) NE thetext)

; Error checking. Look for no selection values.

IF N_Elements(selection) EQ 1 THEN BEGIN
IF selection[0] EQ -1 THEN RETURN
ENDIF

; Error checking. Look for no overlap between the two vectors.

overlap = self->SetDifference(Indgen(N_Elements(*self.text)), selection)
IF N_Elements(overlap) EQ 1 THEN BEGIN
IF overlap[0] EQ -1 THEN BEGIN
*self.text = ""
ENDIF ELSE BEGIN
*self.text = (*self.text)[overlap]
ENDELSE
ENDIF ELSE *self.text = (*self.text)[overlap]


Widget_Control, self.textID, Set_Value=*self.text

END
************************************************************ ************

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26743 is a reply to message #26626] Mon, 24 September 2001 08:52 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> It turns out a list widget, although simplifying my
> life, made other things more complicated.

You could use widget_text, then, by modifying the code above to include
the following (sorry for not providing this to start with :-):

junk = where(strsplit(rs, string(1b), /extract) $
ne theText, comp=good_rows, ncomp=count)
if count ne 0 then theText = theText[good_rows]
Widget_Control, textID, Set_Value=theText

Its not copyrighted, you know :-)
Cheers,
Pavel
Re: Text Widget Confession [message #26751 is a reply to message #26626] Sun, 23 September 2001 16:21 Go to previous message
Andrew Cool is currently offline  Andrew Cool
Messages: 219
Registered: January 1996
Senior Member
David Fanning wrote:
>
> Andrew Cool (cooladjc@chariot.net.au) writes:
>
>> Here's a Fortran-ish, Saturday night, looking thing that will return
>> the correct line number for (hopefully) any text file that you suck
>> into the text widget with Dialog_Pickfile.
>
> Well, I'm grateful for any solution, even a Fortran-ish one. :-)
>
> It turns out a list widget, although simplifying my
> life, made other things more complicated. For example,
> one of the requirements is that we be able to cut
> and paste information in the "form" into an application
> like Excel. You can do this from a text widget, but
> not from a List widget, even though the two look identical
> on the display.
>
> (And while I'm on the topic, how come you can't
> send anything but graphics output commands to the
> Printer? Does this make any sense to you!?)

No, but what does Windows?

Why not do what we did in the Good Ol' Days? Grab the printer manual
and write your own driver?

Andrew


------------------------------------------------------------ ---------
Andrew D. Cool .->-.
Electromagnetics & Propagation Group `-<-'
Surveillance Systems Division Transmitted on
Defence Science & Technology Organisation 100% recycled
PO Box 1500, Salisbury electrons
South Australia 5108

Phone : 061 8 8259 5740 Fax : 061 8 8259 6673
Email : andrew.cool@dsto.defence.gov.au
------------------------------------------------------------ ---------
Re: Text Widget Confession [message #26754 is a reply to message #26626] Sun, 23 September 2001 10:00 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Andrew Cool (cooladjc@chariot.net.au) writes:

> Here's a Fortran-ish, Saturday night, looking thing that will return
> the correct line number for (hopefully) any text file that you suck
> into the text widget with Dialog_Pickfile.

Well, I'm grateful for any solution, even a Fortran-ish one. :-)

It turns out a list widget, although simplifying my
life, made other things more complicated. For example,
one of the requirements is that we be able to cut
and paste information in the "form" into an application
like Excel. You can do this from a text widget, but
not from a List widget, even though the two look identical
on the display.

(And while I'm on the topic, how come you can't
send anything but graphics output commands to the
Printer? Does this make any sense to you!?)

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26763 is a reply to message #26626] Sat, 22 September 2001 03:27 Go to previous message
A. D. &amp; J.C. Cool is currently offline  A. D. &amp; J.C. Cool
Messages: 16
Registered: February 2000
Junior Member
David Fanning wrote:
>
> P.S. Let's just say the only thing that confuses me
> more than how text widgets work is string manipulation. :-(
>
> I'll give Pavel credit, though. He's done it!
>
> I did learn one new thing today, though. I eventually
> went to a multiple selection list widget, which--of course--
> returns an array of the text indices I *don't* want. I want
> the inverse of this. So I found a fabulous SetDifference
> function on that Coyote site that allowed me to fix my
> text array in one line. Neat! :-)
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155

David,

Here's a Fortran-ish, Saturday night, looking thing that will return
the correct line number for (hopefully) any text file that you suck
into the text widget with Dialog_Pickfile.

Andrew


PRO Which_Text_Line_event, ev

widget_control,ev.id,get_value = value

vsize = SIZE(value)
line_len = strlen(value)
line_tot = intarr(vsize(1))
line_tot(0) = line_len(0)

; some smart buggar can vectorise this...

FOR i = 1,vsize(1)-1 DO BEGIN
line_tot(i) = TOTAL(line_len(0:i))
END

cr_line_tot = line_tot + (indgen(vsize(1))+1)*2
xol = widget_info(ev.id,/text_select)
xy = widget_info(ev.id,text_offset_to_xy=xol(0))

FOR line_count = vsize(1)-1,0,-1 DO BEGIN
if xol(0) ge cr_line_tot(line_count) THEN GOTO, stop_line_inc
END

stop_line_inc:
print,'Correct line= ',line_count + 2

END


PRO Which_Text_Line

;22-Sep-2001 Andrew Cool v1.00 Find line number of (start of)
selected text in a
; text widget, taking into account extra
2 characters
; per line.

base = widget_base()
text_id =
widget_text(base,xsize=80,ysize=20,/scroll,/all_events,/NO_N EWLINE)

file = dialog_pickfile(path='c:\idl',filter='*.pro')
if file(0) EQ '' THEN RETURN

text = strarr(3000)
line=''
count = 0
openr,lun,file,/get
While NOT EOF(lun) DO BEGIN
readf,lun,line
text(count) = line
count = count + 1
END
free_lun,lun
close,lun
text = text(0:count-2)

; text = ['Sing a song of sixpence',$
; 'The birds began to sing',$
; 'Four and twenty blackbirds',$
; 'Baked in a pie',$
; 'When the pie was opened',$
; 'The birds began to sing',$
; 'Wasn"t that a dainty dish',$
; 'To set',$
; 'Before',$
; 'The King?']

widget_control,text_id,set_value=text
widget_control,text_id,/use_text_select

widget_control,base,/real

Xmanager,'Which_Text_Line',base

END
Re: Text Widget Confession [message #26766 is a reply to message #26626] Fri, 21 September 2001 11:34 Go to previous message
R.Bauer is currently offline  R.Bauer
Messages: 1424
Registered: November 1998
Senior Member
David Fanning wrote:
>
> Don J Lindler (lindler@rockit.gsfc.nasa.gov) writes:
>
>> I think you are confused because you chose an unfornunate example.
>> ['Dog','Cow','Coyote']
>
> Well, I have to think simply or *nothing* works. :-)
>
>> The length of the lines are 5, 5, and 8 which add to 18. I assume it is the
>> characters in the line plus a line feed and <cr>. So that Line 0 starts at
>> offset 0, line 1 starts at offset 5 and line 3 starts at offset 10.
>
> Of course, I immediately assumed that each line had
> a carriage return and a line feed. But the odd thing
> is that I can't recover them. Where are they? Converting
> the text to a byte array results in zeros, but no 10s or 13s.
> (Not to mention there are not enough 0s either.)

for linux please try
['Dog'+string(10b)+'Cow'+string(10b)+'Coyote'+string(10b)]
and ysize=1

this gives the same result as Davids list and ysize=3.


But I was not able to reproduce this on windows.

Reimar



>
>> Since the Text_Offset_to_XY keyword in Widget_Info does not seem to work
>> right, you will have to compute the offsets to each line manually by
>> accummulating the string lengths plus 2 for all previous lines.
>
> Well, yes, but surely this is not what RSI had in mind
> here, is it? I mean, this isn't object graphics, right?
>
>> Wouldn't a list widget work better for what you are doing?
>
> Of course, and that is exactly how I solved the problem.
> But it didn't really clear up any of my questions. :-)
>
> Cheers,
>
> David
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155

--
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
Re: Text Widget Confession [message #26767 is a reply to message #26626] Fri, 21 September 2001 11:19 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:

> PRO Example_Event, event
> Widget_Control, event.top, Get_UValue=textID
> Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
> Widget_Control, textID, Get_Value=theText
> jt = strjoin(thetext, string(1b))
> js = strjoin(selecttext, string(1b))
> rs = jt
> strput, rs, string( byte(js) < 2b), strpos(jt, js)
> print, where(strsplit(rs, string(1b), /extract) ne thetext)
> END; -----------------------------------

Duh! How come I didn't think of that!?

Cheers,

David

P.S. Let's just say the only thing that confuses me
more than how text widgets work is string manipulation. :-(

I'll give Pavel credit, though. He's done it!

I did learn one new thing today, though. I eventually
went to a multiple selection list widget, which--of course--
returns an array of the text indices I *don't* want. I want
the inverse of this. So I found a fabulous SetDifference
function on that Coyote site that allowed me to fix my
text array in one line. Neat! :-)

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26768 is a reply to message #26626] Fri, 21 September 2001 11:08 Go to previous message
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
David Fanning wrote:
>
> Wouldn't a list widget work better for what you are doing?
>
> Of course, and that is exactly how I solved the problem.
> But it didn't really clear up any of my questions. :-)

David,
I could not believe you'd give up so easily :-(
The following code seems to do what you want with WIDGET_TEXT on both
Mac and W2K. I am sorry folks but I am too dumb for all your LFs and CRs
so I just ignored it all.
It only prints the index of items to be deleted from the origunal value
of the widget. But that should be fairly easy to set up.
Cheers,
Pavel

;****************
PRO Example_Event, event
Widget_Control, event.top, Get_UValue=textID
Widget_Control, textID, Get_Value=selectText, /Use_Text_Select
Widget_Control, textID, Get_Value=theText
jt = strjoin(thetext, string(1b))
js = strjoin(selecttext, string(1b))
rs = jt
strput, rs, string( byte(js) < 2b), strpos(jt, js)
print, where(strsplit(rs, string(1b), /extract) ne thetext)
END; -----------------------------------
;****************
PRO Example
tlb = Widget_Base(Column=1)
button = Widget_Button(tlb, Value='Do It')
textID = Widget_Text(tlb, Scr_XSize=100, $
YSize=20,Value=['Dog', 'Cow', 'Coyote'])
Widget_Control, tlb, /Realize, Set_UValue=textID
XManager, 'example', tlb, /No_Block
END; -----------------------------------
;****************
Re: Text Widget Confession [message #26769 is a reply to message #26626] Fri, 21 September 2001 11:03 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Don J Lindler (lindler@rockit.gsfc.nasa.gov) writes:

> I think you are confused because you chose an unfornunate example.
> ['Dog','Cow','Coyote']

Well, I have to think simply or *nothing* works. :-)

> The length of the lines are 5, 5, and 8 which add to 18. I assume it is the
> characters in the line plus a line feed and <cr>. So that Line 0 starts at
> offset 0, line 1 starts at offset 5 and line 3 starts at offset 10.

Of course, I immediately assumed that each line had
a carriage return and a line feed. But the odd thing
is that I can't recover them. Where are they? Converting
the text to a byte array results in zeros, but no 10s or 13s.
(Not to mention there are not enough 0s either.)

> Since the Text_Offset_to_XY keyword in Widget_Info does not seem to work
> right, you will have to compute the offsets to each line manually by
> accummulating the string lengths plus 2 for all previous lines.

Well, yes, but surely this is not what RSI had in mind
here, is it? I mean, this isn't object graphics, right?

> Wouldn't a list widget work better for what you are doing?

Of course, and that is exactly how I solved the problem.
But it didn't really clear up any of my questions. :-)

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: Text Widget Confession [message #26770 is a reply to message #26626] Fri, 21 September 2001 10:43 Go to previous message
Don J Lindler is currently offline  Don J Lindler
Messages: 19
Registered: April 2001
Junior Member
"David Fanning" <david@dfanning.com> wrote in message
news:MPG.161513d4da1fb1889896b9@news.frii.com...
> 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.)
> ...

David,

I think you are confused because you chose an unfornunate example.
['Dog','Cow','Coyote']

The length of the lines are 5, 5, and 8 which add to 18. I assume it is the
characters in the line plus a line feed and <cr>. So that Line 0 starts at
offset 0, line 1 starts at offset 5 and line 3 starts at offset 10.

Since the Text_Offset_to_XY keyword in Widget_Info does not seem to work
right, you will have to compute the offsets to each line manually by
accummulating the string lengths plus 2 for all previous lines.

Wouldn't a list widget work better for what you are doing?

Don Lindler
lindler@rockit.gsfc.nasa.gov
Re: Text Widget Confession [message #26771 is a reply to message #26626] Fri, 21 September 2001 10:28 Go to previous message
R.Bauer is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: A distracting puzzle
Next Topic: Xmanager R US

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:36:48 PDT 2025

Total time taken to generate the page: 0.00619 seconds