[REBOL] Re: make port! [scheme: 'event]
From: jeff:rebol at: 22-Jun-2001 7:31
You can be the event loop.
ep: open [
awake: func [port /local p x][
p: first port
x: copy 
print ["Event:" repeat i 8 [append x pick p i]]
;-- Actually have that event happen
; if you didn't DO the event the
; GUI would be non operational.
;-- return true from AWAKE function
; to stop event bubbling.
view/new layout [size 300x300 text "Hello" button "!"]
forever [wait [ep]]
You should see all your events spewing out as you move your
mouse around the window and click on stuff. The AWAKE
function is called when data is available on the port. Instead
of just our simple forever above, we might have:
You can also stick your event port in system/ports/wait-list,
then it will be handled with anything else in the list when
ever WAIT gets called.
If you don't open an event port and you just use VIEW/new for
all your windows, you still have the same ability to be the
event loop: just call WAIT with a timeout somewhere in your
loop. If you trudge through the PREZ dialect engine, that's
how it works-- a loop that manages the show and calls WAIT .2
at one point. This short wait is sufficient for all the GUI
events to be handled and prevents busy looping.
The reason you'd make your own event port is because you want
control over aspects of the port, such as the AWAKE function.