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.
15 # Check for immediate stdwin event
17 event
= stdwinq
.pollevent()
19 mainloop
.dispatch(event
)
22 # Use sleep for very short delays or if there are no windows
24 if msecs
< 100 or mainloop
.countwindows() == 0:
26 time
.sleep(msecs
* 0.001)
29 # Post a timer event on an arbitrary window and wait for it
31 window
= mainloop
.anywindow()
32 window
.settimer(msecs
/100)
33 event
= stdwinq
.getevent()
35 if event
[0] <> WE_TIMER
:
36 mainloop
.dispatch(event
)
39 return int(1000 * time
.time())
41 q
= sched
.scheduler(millitimer
, delayfunc
)
43 # Export functions enter, enterabs and cancel just like a scheduler
49 # Emptiness check must check both queues
52 return q
.empty() and mainloop
.countwindows() == 0
54 # Run until there is nothing left to do
59 mainloop
.dispatch(stdwinq
.getevent())