summaryrefslogtreecommitdiffstats
path: root/Lib/lib-stdwin/WindowSched.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-04-07 13:41:50 (GMT)
committerGuido van Rossum <guido@python.org>1991-04-07 13:41:50 (GMT)
commit2d844d1ddc581c80116c88be5854720bcf84f3e0 (patch)
tree7aaca4e789dd1394d8eff7484dfced08a635983f /Lib/lib-stdwin/WindowSched.py
parentfa5406496750f9f0717457341041297b4173430f (diff)
downloadcpython-2d844d1ddc581c80116c88be5854720bcf84f3e0.zip
cpython-2d844d1ddc581c80116c88be5854720bcf84f3e0.tar.gz
cpython-2d844d1ddc581c80116c88be5854720bcf84f3e0.tar.bz2
Initial revision
Diffstat (limited to 'Lib/lib-stdwin/WindowSched.py')
-rw-r--r--Lib/lib-stdwin/WindowSched.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/Lib/lib-stdwin/WindowSched.py b/Lib/lib-stdwin/WindowSched.py
new file mode 100644
index 0000000..19be2b1
--- /dev/null
+++ b/Lib/lib-stdwin/WindowSched.py
@@ -0,0 +1,57 @@
+# Combine a real-time scheduling queue and stdwin event handling.
+# Uses the millisecond timer.
+
+import stdwin
+from stdwinevents import WE_TIMER
+import WindowParent
+import sched
+import time
+
+# Delay function called by the scheduler when it has nothing to do.
+# Return immediately when something is done, or when the delay is up.
+#
+def delayfunc(msecs):
+ #
+ # Check for immediate stdwin event
+ #
+ event = stdwin.pollevent()
+ if event:
+ WindowParent.Dispatch(event)
+ return
+ #
+ # Use millisleep for very short delays or if there are no windows
+ #
+ if msecs < 100 or WindowParent.CountWindows() = 0:
+ time.millisleep(msecs)
+ return
+ #
+ # Post a timer event on an arbitrary window and wait for it
+ #
+ window = WindowParent.AnyWindow()
+ window.settimer(msecs/100)
+ event = stdwin.getevent()
+ window.settimer(0)
+ if event[0] <> WE_TIMER:
+ WindowParent.Dispatch(event)
+
+q = sched.scheduler().init(time.millitimer, delayfunc)
+
+# Export functions enter, enterabs and cancel just like a scheduler
+#
+enter = q.enter
+enterabs = q.enterabs
+cancel = q.cancel
+
+# Emptiness check must check both queues
+#
+def empty():
+ return q.empty() and WindowParent.CountWindows() = 0
+
+# Run until there is nothing left to do
+#
+def run():
+ while not empty():
+ if q.empty():
+ WindowParent.Dispatch(stdwin.getevent())
+ else:
+ q.run()