darken@seas.gwu.edu (04/21/91)
Here's the problem: Say I have a panel with 2 buttons on it. When I hit button #1, I want to start a process which will continue until button #2 is hit. How can I interrupt the notify procedure of button #1 when #2 is hit? As I see it, the pressing of #2 will not be recognized until #1 is completed processing. I looked into events in addition to notifications but nothing works yet and the manual is rather shady in this area. Thanks in advance! Rudy darken@seas.gwu.edu
gordonc@aifh.ed.ac.uk (Gordon Cameron (RA DAI)) (04/25/91)
From article <3098@sparko.gwu.edu>, by darken@seas.gwu.edu: > Here's the problem: > Say I have a panel with 2 buttons on it. When I hit > button #1, I want to start a process which will continue > until button #2 is hit. How can I interrupt the notify > procedure of button #1 when #2 is hit? As I see it, > the pressing of #2 will not be recognized until #1 > is completed processing. I looked into events in > addition to notifications but nothing works yet and > the manual is rather shady in this area. Thanks in > advance! > You could try something like this : /* Globals */ int program_state , finished ; main() { --- --- program_state=DOING_LOOP ; while (running==TRUE) { xv_main_loop(----) if (program_state=DOING_SOMETHING) { /* (1) */ do_something() ; clean_up() ; /* (2) */ program_state=DOING_LOOP ; } } } <Callback routine for button #1> { program_state=DOING_SOMETHING ; notify_stop() ; } <Callback routine for button #2> { finished=TRUE ; } do_something() { finished=FALSE ; /* Insert your code here and in it periodically do this... notify_dispatch() ; if (finished==TRUE) { printf ("Finished off !!!\n") ; return ; // This takes you back to (2) in main } */ } What this does is to run the routine 'do_something' when you press the button #1. How ?? Pressing the button triggers the callback which sets a global variable, and calls notify_stop. The notifier returns to the top level, and then notify_start and xv_main_loop return. This leaves you in position (1) in the code. Since you have set the variable program_state, the routine 'do something' executes. Periodically in this routine, you should make calls to notify_dispatch(), which will make a single pass through the notify cycle. If you have pressed button #2, then all you will have done is to set the variable finished to TRUE. This is detected, and 'do_something' returns so you end up at point (2). You can now do whatever you want before continuing with the application (perhaps doing some graphical output). xv_main_loop then gets called again, and so you are back to where you started. I've set a variable running, which when you unset and do xv_destroy(Frame) will have the effect of quitting the application. (To be complete you should write a notify_interspose_destroy_func which sets the variable running to FALSE, so the window quit works) Hope this is useful - If you're interested, get the O'Reilly book 'XView Programming Manual' by Dan Heller, as its excellent. (see pp 397-400) Gordon Cameron, Department of Artificial Intelligence, University of Edinburgh, Scotland e-mail : gordonc@uk.ac.edai.fh
andrew@resam.dk (Leif Andrew Rump) (04/29/91)
In <1991Apr24.211819.26355@aifh.ed.ac.uk> gordonc@aifh.ed.ac.uk (Gordon Cameron (RA DAI)) writes: >From article <3098@sparko.gwu.edu>, by darken@seas.gwu.edu: >> Here's the problem: >> Say I have a panel with 2 buttons on it. When I hit >> button #1, I want to start a process which will continue >> until button #2 is hit. How can I interrupt the notify >> procedure of button #1 when #2 is hit? As I see it, >> the pressing of #2 will not be recognized until #1 >> is completed processing. I looked into events in >> addition to notifications but nothing works yet and >> the manual is rather shady in this area. Thanks in >> advance! >> >You could try something like this : LOTS OF GOOD CODE DELETED >What this does is to run the routine 'do_something' when you press >the button #1. How ?? Pressing the button triggers the callback >which sets a global variable, and calls notify_stop. >The notifier returns to the top level, and then notify_start >and xv_main_loop return. >Periodically in this routine, you should make calls to >notify_dispatch(), which will make a single pass through the >notify cycle. If you have pressed button #2, then all you will >have done is to set the variable finished to TRUE. This is >detected, and 'do_something' returns so you end up at point (2). >You can now do whatever you want before continuing with the >application (perhaps doing some graphical output). >xv_main_loop then gets called again, and so you are back to where >you started. I've set a variable running, which when you unset >and do xv_destroy(Frame) will have the effect of quitting the >application. >(To be complete you should write a notify_interspose_destroy_func >which sets the variable running to FALSE, so the window quit works) >Hope this is useful - If you're interested, get the O'Reilly book >'XView Programming Manual' by Dan Heller, as its excellent. >(see pp 397-400) Well now we are back to good old MicroSoft Window code! Shouldn't the window manager be able to handle this by itself, like when the user envokes notify_dispatch()? Andrew Leif Andrew Rump, AmbraSoft A/S, Stroedamvej 50, DK-2100 Copenhagen OE, Denmark UUCP: andrew@ambra.dk, phone: +45 39 27 11 77 / Currently at Scandinavian Airline Systems =======/ UUCP: andrew@resam.dk, phone: +45 32 32 51 54 \ SAS, RESAM Project Office, CPHML-V, P.O.BOX 150, DK-2770 Kastrup, Denmark If it's broke, fix it (The MS-DOS way) If it aint broke, don't touch it (The Unix way) If we can't fix it, it ain't broke (Maintainer's Motto) If you can't fix it, fuck it (The U-boat way)