home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Lib / stdwin / stdwinq.py < prev    next >
Text File  |  1991-08-16  |  1KB  |  54 lines

  1. # Replacements for getevent() and pollevent(),
  2. # and new functions ungetevent() and sync().
  3.  
  4.  
  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().
  8.  
  9.  
  10. import stdwin
  11.  
  12.  
  13. # Events read ahead are stored in this queue.
  14. #
  15. queue = []
  16.  
  17.  
  18. # Replacement for getevent().
  19. #
  20. def getevent():
  21.     if queue:
  22.         event = queue[0]
  23.         del queue[0]
  24.         return event
  25.     else:
  26.         return stdwin.getevent()
  27.  
  28.  
  29. # Replacement for pollevent().
  30. #
  31. def pollevent():
  32.     if queue:
  33.         return getevent()
  34.     else:
  35.         return stdwin.pollevent()
  36.  
  37.  
  38. # Push an event back in the queue.
  39. #
  40. def ungetevent(event):
  41.     queue.insert(0, event)
  42.  
  43.  
  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.)
  48. #
  49. def sync():
  50.     while 1:
  51.         event = stdwin.pollevent()
  52.         if not event: break
  53.         queue.append(event)
  54.