Re: Using WIDGET_EVENT to break into loops [message #6711] |
Wed, 07 August 1996 00:00 |
rarback
Messages: 15 Registered: October 1992
|
Junior Member |
|
|
Andyhall@ncsa.uiuc.edu (Andy Hall) writes...
> Hi all.
> I have been writing an application that uses a loop to
> perform animated data visualization, and I wanted to add the
> functionality to stop the loop before the animation was
> complete. In searching for a good way to do this, I came
> accross the following post from this group in answer to a
> similar question:
>
>> Check out the !NEWS IDL Newsletter Volume 6, Number 1 (Summer 96)
>> if you have it. It has an example illustratiing how to do what you
>> are asking.
>>
>> Basically, within the loop in the event handler, you use
>> WIDGET_EVENT() to poll for events generated from the widget
>> heirarchy "represented" by the widget id argument to WIDGET_EVENT().
>>
[snip]
>
> So, I tried the advice above. However, I had a few problems:
>
> The above message (and the IDL help) seem to imply that
> WIDGET_EVENT(id) is a routine that will extract events for the
> hierarchy rooted at id and hand them over to the user to examine.
>
> However, when I call WIDGET_EVENT, the procedure polls the hierarchy
> rooted at id for events, then passes those events to the event handler,
> processes the event, and _then_ returns the event to me.
This is consistent with my reading of the documentation. Event handlers get
called if they are found. The code in the Newsletter used widget_event() to
return an event for a "hierarchy" with a single widget button which had no
handler declared.
> Thus, when I implemented the above code, or rather this code:
>
> WHILE NOT(quit_anim) DO BEGIN
> ...
> quit = widget_event(event.top, /nowait)
^^^^^^^^^
Things would probably work ok if you had specified the widget id of your
button.
I am appending the code from the Newsletter (slightly cleaned up) since it is
instructive and I had to go to the trouble of typing it anyway :-(
----
Harvey Rarback phone: (312)702-9931
CARS fax: (312)702-5454
University of Chicago Internet: rarback@cars3.uchicago.edu
5640 South Ellis Avenue "Make no little plans. They have no magic to
Chicago, IL 60637 stir men's souls."
____________________________________________________________ _______________
Extract this into the file therm.pro:
pro therm_event, event
; construct the thermometer widget
th = widget_base( /column)
cancel = widget_button( th, value='Cancel')
draw = widget_draw( th, xsize=150, ysize=25)
label = widget_label( th, value='0% complete')
widget_control, th, /realize
widget_control, draw, get_value=win
wset, win
; initialize variables before starting processing
count = 0.0 & process = 0
widget_control, /hour
while process eq 0 do begin
num = 25
for i = 0L, 100000 do j = i^2
count = count + 1 & wait, 0.1
if count eq num then process = 1
per = count / num
polyfill, [0,per,per,0], [0,0,1,1], /normal, color = 255
widget_control, label, set_value=strcompress( fix( per*100)) + '% complete'
quit = widget_event( cancel, /nowait, /save)
if quit.id eq cancel then process = 1
endwhile
dummy = widget_event( cancel, /nowait)
widget_control, th, /destroy
end
;*********************************************************** *************
pro therm
base = widget_base( /column)
button = widget_button( base, value = 'Perform long calculations')
widget_control, base, /realize
xmanager, 'therm', base
end
|
|
|