So, I did get it to do what I want, though I don't entirely understand
why it works. It seems that widget_event(/nowait) returns the "bare
bones" structure of {ID:0, TOP:0, HANDLER:0} for all times that the
mouse is *inside* the widget. When you move out, it will add the tag
"ENTER". So it was simple enough to test on whether or not the
"ENTER" tag exists or not. I've attached a quick script to illustrate
it. The first function is from the IDL astro-library maintained by W.
Landsman --- just in case someone else is interested in this. I'm not
sure it was worth all the time I spent on this, but it was a fun
exercise! Now to figure out why widget_event changes its return
structure like that, and whether or not I can trust this in the
future....
function tag_exist, str, tag,index=index,
top_level=top_level,recurse=recurse, $
quiet=quiet
;
; check quantity of input
;
compile_opt idl2
if n_params() lt 2 then begin
print,'Use: status = tag_exist(structure, tag_name)'
return,0b
endif
;
; check quality of input
;
if size(str,/TNAME) ne 'STRUCT' or size(tag,/TNAME) ne 'STRING' then
begin
if not keyword_set(quiet) then begin
if size(str,/TNAME) ne 'STRUCT' then help,str
if size(tag,/TNAME) ne 'STRING' then help,tag
print,'Use: status = tag_exist(str, tag)'
print,'str = structure variable'
print,'tag = string variable'
endif
return,0b
endif
tn = tag_names(str)
nt = where(tn eq strupcase(tag)) & index=nt[0]
no_match = index EQ -1
if no_match and not keyword_set(top_level) then begin
status= 0b
for i=0,n_elements(tn)-1 do begin
if size(str.(i),/TNAME) eq 'STRUCT' then $
status=tag_exist(str.(i),tag,index=index)
if status then return,1b
endfor
return,0b
endif else return,~no_match
end
pro test2_event,event
widget_control,event.id,get_uvalue=uval ;name of UVALUE of the event
eventtype=tag_names(event,/str) ;event type
event1=(strsplit(eventtype,'_',/ext))(1) ;2nd element of event type
case event1 of
'TRACKING': begin
if event.enter then begin
widget_control,event.id,get_value=text
orig=text(0)
text=orig+' '
len=strlen(text)
exist=1b & i=0L
while exist do begin
i=i mod len
widget_control,event.id,set_value=string(shift(byte(text),-
i))
++i
exist=1b-tag_exist(widget_event(event.id,/nowait),'ENTER')
if exist then wait,0.2
endwhile
widget_control,event.id,set_value=orig
endif
end
'BUTTON': begin
case uval of
'CLOSE': widget_control,event.top,/destroy
else:
endcase
end
else:
endcase
end
pro test2
base=widget_base(/col)
lab=widget_label(base,xsize=100,value='This is a long string in a
small box',$
/tracking,ysize=24,/sunken)
w=widget_button(base,val='Close',uval='CLOSE')
widget_control,base,/realize
xmanager,'test2',base,/no_block
end
On Dec 1, 3:56 pm, David Fanning <n...@dfanning.com> wrote:
> Russell writes:
>> So I have a large GUI I've been working on, and there are several
>> widget_labels all over the place. The xsizes of these regions are
>> fixed, but the text that can populate them is to be decided by the
>> User. In general, the text will be much longer than the widget_label
>> can accommodate, so I thought it would be helpful to add some type of
>> scrolling to the text inside a widget_label. My hope was that when
>> the User places the mouse over the widget_label that the text beneath
>> it would scroll. I can use /tracking_events to tell when the mouse
>> enters or leaves the widget_label, but I don't know how to interrupt
>> the event loop, something like:
>
>> while event.enter eq 1 do begin
>> scroll_text,event.id
>> endwhile
>
>> because as this while loop begins, it never exits back to the main
>> event handler to even know if the mouse leaves or not. My gut tells
>> me I need widget_event, but I can't really see how to make that
>> happen....
>
>> Any advice?
>
> Forget it. Ain't gonna happen. :-)
>
> Cheers,
>
> David
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.idlcoyote.com/
> Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|