1 # Combine a real-time scheduling queue and stdwin event handling.
2 # Keeps times in milliseconds.
5 from stdwinevents
import WE_TIMER
10 # Delay function called by the scheduler when it has nothing to do.
11 # Return immediately when something is done, or when the delay is up.
16 # Check for immediate stdwin event
18 event
= stdwinq
.pollevent()
20 mainloop
.dispatch(event
)
23 # Use sleep for very short delays or if there are no windows
25 if msecs
< 100 or mainloop
.countwindows() == 0:
27 time
.sleep(msecs
* 0.001)
30 # Post a timer event on an arbitrary window and wait for it
32 window
= mainloop
.anywindow()
33 window
.settimer(msecs
/100)
34 event
= stdwinq
.getevent()
36 if event
[0] <> WE_TIMER
:
37 mainloop
.dispatch(event
)
40 return time
.time() * 1000
42 q
= sched
.scheduler(millitimer
, delayfunc
)
44 # Export functions enter, enterabs and cancel just like a scheduler
50 # Emptiness check must check both queues
53 return q
.empty() and mainloop
.countwindows() == 0
55 # Run until there is nothing left to do
60 mainloop
.dispatch(stdwinq
.getevent())