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
|