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