Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Interrupting an action

 [1/5] from: sanghabum::aol::com at: 15-Jul-2001 6:06


Hi all, If I've got a VID action facet that takes a long time, how can I provide the user with some way of aborting the action? I've tried polling the Console as per the KBHIT thread of some weeks ago. But that takes input from the Console, not the layout. So what code can I use to replace the comment below? ========= unview/all view layout [ Button "long wait" [ ResultField/Text: "Working" show resultField loop 100 [ wait 1 ;;check for escape key/cancel button ] ;loop ResultField/Text: "Finished" show resultField ];action resultField: info ];layout ========= Thanks, Colin.

 [2/5] from: agem:crosswinds at: 15-Jul-2001 15:11


RE: [REBOL] Interrupting an action [Sanghabum--aol--com] wrote:
> Hi all, > If I've got a VID action facet that takes a long time, how can I provide the
<<quoted lines omitted: 16>>
> ];layout > >
[rebol [] unview/all stop: false view layout [ Button "long wait" [ ResultField/Text: "Working" show resultField i: 0 forever [ i: i + 1 ;only all 100 steps os-call if i // 100 [ wait 0 if stop [break] ;some "work" prin random "*?!#@+&()\" ] ] ResultField/Text: pick ["Interrupted" "Finished"] stop show resultField ] ;action button "stop" [ stop: true ] ;layout resultField: info ] ]

 [3/5] from: agem:crosswinds at: 15-Jul-2001 16:25


RE: [REBOL] Re: Interrupting an action [agem--crosswinds--net] wrote:
> RE: [REBOL] Interrupting an action > [Sanghabum--aol--com] wrote:
<<quoted lines omitted: 7>>
> ;only all 100 steps os-call > if i // 100 [
if i // 100 = 0 [ of course.. -Volker

 [4/5] from: arolls:bigpond:au at: 16-Jul-2001 2:34


In this example, the action takes an amount of time that noticeably blocks the gui: view layout [ button "quit" [unview] button "action" [repeat n 2000000 [prin ""]] ] In this example, knowing how long the action takes, we occasionally 'wait for a very short time, so the gui has a possibility of reacting to the user: view layout [ button "quit" [unview] button "action" [ repeat n 2000000 [ if 0 = (n // 100000) [wait 0.01] prin "" ] ] ] The idea is to split your job up into parts. The other way to do it is to modify the feel of one of your gadgets, so that it catches time events. At each time event, you look to see if you have work to do. The button will just set a variable that indicates that a job has started and that we are up to part one . view layout [ b: button [if zero? job [job: 1]] ] ; see what the default feel is first ; copy and paste it probe b/feel ; modify the feel so it contains the below b/feel: [ engage: func [face action event][ if action = 'time [ if job > 0 [ switch job [ 1 [] ; do part one here 2 [] ; do part two here 3 [job: 0] ; do last part here ] job: job + 1 ] ] ] ]

 [5/5] from: sanghabum:aol at: 15-Jul-2001 18:52


Thanks Anton and Volker, You both suggested the trick of wait 0 or wait 0.01---something I'd never have thought of. I've taken your code, Volker, and taken some liberties with it: -- Feel and focus added so both click on "Stop" or Escape key will half the process; -- "Stop: false" inside Action so code can start/stop more than once; --Loop, not Forever, so you can see the difference beween a completed long action, and an interupted one. A question arising from this: assuming a more complicated example where the user has filled in various fields and then clicked "long task" button, Is there any way I can save their current focus, redirect focus to my stop button, and then reset the focus once the "long task" is complete? Thanks again Colin =======Volker's code, altered========== Mylayout: layout [ Button "Long Task" [ stop: false ResultField/Text: "Working" show resultField for i 1 1'000'000 1 [ ;only all 100 steps os-call if i // 100 = 0 [ wait 0 if stop [break] ;some "work" prin [i " "] ] ;if ] ;for ResultField/Text: pick ["Interrupted" "Finished"] stop show resultField ] ;action StopButton: button "Stop" feel [ engage: func [face action event] [ if event/key = #"^[" [stop: true] ; escape key if action = 'down [stop: true] ; mouse down ] ;engage ] ; feel resultField: info ] ;layout unview/all focus StopButton View MyLayout

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted