[shpy-commit] r2850 - shpy/trunk/dist/shpy

arigo@codespeak.net arigo@codespeak.net
Tue, 20 Jan 2004 14:57:13 +0100 (MET)


Author: arigo
Date: Tue Jan 20 14:57:13 2004
New Revision: 2850

Modified:
   shpy/trunk/dist/shpy/ui_pygame.py
Log:
Improved details in repaint event handling.


Modified: shpy/trunk/dist/shpy/ui_pygame.py
==============================================================================
--- shpy/trunk/dist/shpy/ui_pygame.py	(original)
+++ shpy/trunk/dist/shpy/ui_pygame.py	Tue Jan 20 14:57:13 2004
@@ -12,7 +12,7 @@
 FONT = None
 HEIGHT = 24
 
-REPAINTEVENT = USEREVENT
+WAKEUPEVENT = USEREVENT
 
 
 class InputCell:
@@ -194,11 +194,16 @@
             self.cursor.x += 1
 
     def run(self):
-        invalid = True
+        repaintdelay = 0
+        self.invalid = True
         while 1:
-            if invalid:
-                self.repaint()
-                invalid = False
+            if self.invalid:
+                if repaintdelay and pygame.event.peek():
+                    repaintdelay -= 1   # don't repaint right now, process next event first
+                else:
+                    self.invalid = False
+                    self.repaint()
+                    repaintdelay = 10
             event = pygame.event.wait()
             print event
             if event.type == KEYDOWN:
@@ -210,15 +215,13 @@
                     if method:
                         method()
                         self.notifychanges(self.cursor)
-                        invalid = True
+                        self.invalid = True
                         break
             if event.type == QUIT:
                 break
-            if event.type == REPAINTEVENT:
-                invalid = True
             if event.type == VIDEORESIZE:
                 pygame.display.set_mode(event.size, RESIZABLE)
-                invalid = True
+                self.invalid = True
 
     def close(self):
         print "trying to quit the gateway ..."
@@ -227,7 +230,8 @@
         pygame.quit()
 
     def postrepaintevent(self):
-        pygame.event.post(pygame.event.Event(REPAINTEVENT))
+        self.invalid = True
+        pygame.event.post(pygame.event.Event(WAKEUPEVENT))
 
     def notifychanges(self, *structures):
         lines = [representstructure(structure) for structure in structures]