Clarify portability and main program.
[python/dscho.git] / Lib / lib-stdwin / stdwinq.py
blobaf72986d68f23211615865b83b6b28c02edefdf9
1 # Replacements for getevent() and pollevent(),
2 # and new functions ungetevent() and sync().
5 # Every library module should ideally use this instead of
6 # stdwin.{get,poll}event(), so applications can use the services
7 # of ungetevent() and sync().
10 import stdwin
13 # Events read ahead are stored in this queue.
15 queue = []
18 # Replacement for getevent().
20 def getevent():
21 if queue:
22 event = queue[0]
23 del queue[0]
24 return event
25 else:
26 return stdwin.getevent()
29 # Replacement for pollevent().
31 def pollevent():
32 if queue:
33 return getevent()
34 else:
35 return stdwin.pollevent()
38 # Push an event back in the queue.
40 def ungetevent(event):
41 queue.insert(0, event)
44 # Synchronize the display. It turns out that this is the way to
45 # force STDWIN to call XSync(), which some (esoteric) applications need.
46 # (This is stronger than just flushing -- it actually waits for a
47 # positive response from the X server on the last command issued.)
49 def sync():
50 while 1:
51 event = stdwin.pollevent()
52 if not event: break
53 queue.append(event)