[REBOL] Re: Interrupting an action
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