how to program an interrupt button?

Manolo Gouy (mgouy@biomserv.univ-lyon1.fr)
Tue, 11 Mar 1997 12:56:44 +0100

To subscribers of the xforms list from mgouy@biomserv.univ-lyon1.fr (Manolo Gouy) :

I would like to know how to best program an interrupt button using Xforms.

Problem to be solved:
A potentially long computation is performed by an Xforms program, and I want
the user to be able to interrupt it by pressing on an interrupt button.

First solution:
I first did like that:

The interrupt button sets global variable interrupted to TRUE when it gets
pressed.

interrupted = FALSE;
while (condition) {
fl_check_forms();
if( interrupted ) break;
.....
here code that performs one iteration out of the many the computation
involves
.....
}

Result:
This coding works, that is, the computation gets done and is interruptable,
but the program is slow, that is, the cpu seems unused, and the duration of
the computation is much, much longer than without the fl_check_forms() call.

Second solution:
Then I did like that:

XEvent new_event;
FL_FORM *form; /* the form where the interrupt button sits */
interrupted = FALSE;
while (condition) {
if( XCheckWindowEvent(fl_display, form->window, ~(long)0, &new_event)){
XPutBackEvent(fl_display, &new_event);
fl_check_forms();
if(interrupted) break;
}
.....
here code that performs one iteration out of the many the computation
involves
.....
}

Result:
This coding works, that is, the computation gets done and is interruptable.
And now the computation is as fast as if no extra code to allow for interruption
was added.

So I should be happy, but am not because this is not XForms programming,
but really X programming, with calls to XCheckWindowEvent and XPutBackEvent.

Is there any pure XForms-way of obtaining the same result?
I tried using fl_XEventsQueued(QueuedAlready), but failed.

__________________________________________________________________________
| Manolo Gouy |
| Laboratoire de biometrie, genetique et biologie des populations |
| UMR CNRS 5558 | E-MAIL : mgouy@biomserv.univ-lyon1.fr |
| Universite C. Bernard - Lyon 1 | Tel : +33 4-72-43-12-87 |
| 69622 Villeurbanne, France | Fax : +33 4-78-89-27-19 |
|_________________________________|________________________________________|
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/xforms-archive/