diff options
author | Guido van Rossum <guido@python.org> | 1993-01-04 09:16:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-01-04 09:16:51 (GMT) |
commit | fea2af1e9b0c99cac6cb8806c4af651a38e92d07 (patch) | |
tree | e9e0ec3b003498ab942e1c0b7dd3d28951ca2701 /Lib/lib-stdwin/mainloop.py | |
parent | a2b7f40513ba5d75a2063c3fabe47377cd8c0416 (diff) | |
download | cpython-fea2af1e9b0c99cac6cb8806c4af651a38e92d07.zip cpython-fea2af1e9b0c99cac6cb8806c4af651a38e92d07.tar.gz cpython-fea2af1e9b0c99cac6cb8806c4af651a38e92d07.tar.bz2 |
* More changes due to stricter argument passing rules
* Fixed calendar.py, mimetools.py, whrandom.py to cope with time.time()
returning a floating point number. (And fix old bug in calendar)
* Add recursion level to mainloop.mainloop(), to make it reentrant.
Diffstat (limited to 'Lib/lib-stdwin/mainloop.py')
-rw-r--r-- | Lib/lib-stdwin/mainloop.py | 48 |
1 files changed, 33 insertions, 15 deletions
diff --git a/Lib/lib-stdwin/mainloop.py b/Lib/lib-stdwin/mainloop.py index f1fe617..6b574cf 100644 --- a/Lib/lib-stdwin/mainloop.py +++ b/Lib/lib-stdwin/mainloop.py @@ -4,6 +4,9 @@ # - have a 'dispatch' function as a window member +# XXX This is UNIX specific! For the Mac we need to use a simpler version! + + import stdwin, stdwinq from stdwinevents import * @@ -123,23 +126,38 @@ def do_select(): # Python's stdwin.getevent() turns WE_COMMAND/WC_CANCEL events # into KeyboardInterrupt exceptions; these are turned back in events. # +recursion_level = 0 # Hack to make it reentrant def mainloop(): - stdwin_select_handler() # Process events already in stdwin queue - fd = stdwin.fileno() - while 1: - if windows: - registerfd(fd, 'r', stdwin_select_handler) - try: - while windows: + global recursion_level + recursion_level = recursion_level + 1 + try: + stdwin_select_handler() # Process events already in queue + fd = stdwin.fileno() + while 1: + if windows: + if recursion_level == 1: + registerfd(fd, 'r', stdwin_select_handler) + try: + while windows: + do_select() + stdwin_select_handler() + finally: + if recursion_level == 1: + unregisterfd(fd) + elif fdlist: + while fdlist and not windows: do_select() - stdwin_select_handler() - finally: - unregisterfd(fd) - elif fdlist: - while fdlist and not windows: - do_select() - else: - break + else: + break + finally: + recursion_level = recursion_level - 1 + + +# Check for events without ever blocking +# +def check(): + stdwin_select_handler() + # XXX Should check for socket stuff as well # Handle stdwin events until none are left |