[pypy-svn] r18045 - pypy/dist/pypy/translator/tool/pygame

arigo at codespeak.net arigo at codespeak.net
Sat Oct 1 12:22:06 CEST 2005


Author: arigo
Date: Sat Oct  1 12:22:00 2005
New Revision: 18045

Modified:
   pypy/dist/pypy/translator/tool/pygame/drawgraph.py
   pypy/dist/pypy/translator/tool/pygame/graphclient.py
   pypy/dist/pypy/translator/tool/pygame/graphdisplay.py
Log:
A bit of reorganization: on remote connexions, the status bar "loading..."
text immediately disappeared while waiting for the page to arrive, which gave
the user the impression that clicking on a link didn't go anywhere.


Modified: pypy/dist/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pygame/drawgraph.py	(original)
+++ pypy/dist/pypy/translator/tool/pygame/drawgraph.py	Sat Oct  1 12:22:00 2005
@@ -93,6 +93,21 @@
 def display_async_cmd(**kwds):                
     pygame.event.post(pygame.event.Event(USEREVENT, **kwds))
 
+EventQueue = []
+
+def wait_for_events():
+    if not EventQueue:
+        EventQueue.append(pygame.event.wait())
+        EventQueue.extend(pygame.event.get())
+
+def wait_for_async_cmd():
+    # wait until another thread pushes a USEREVENT in the queue
+    while True:
+        wait_for_events()
+        e = EventQueue.pop(0)
+        if e.type in (USEREVENT, QUIT):   # discard all other events
+            break
+    EventQueue.insert(0, e)   # re-insert the event for further processing
 
 
 class Node:

Modified: pypy/dist/pypy/translator/tool/pygame/graphclient.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pygame/graphclient.py	(original)
+++ pypy/dist/pypy/translator/tool/pygame/graphclient.py	Sat Oct  1 12:22:00 2005
@@ -5,7 +5,9 @@
 
 import autopath
 from pypy.translator.tool.pygame.drawgraph import GraphLayout
-from pypy.translator.tool.pygame.drawgraph import display_async_cmd, display_async_quit
+from pypy.translator.tool.pygame.drawgraph import display_async_cmd
+from pypy.translator.tool.pygame.drawgraph import display_async_quit
+from pypy.translator.tool.pygame.drawgraph import wait_for_async_cmd
 from pypy.translator.tool.graphserver import MissingPage, portutil
 from pypy.tool.udir import udir
 import py
@@ -89,6 +91,7 @@
 
     def initiate_display(self, key, link=None):
         self.put_msg((key, link))
+        wait_for_async_cmd()
 
     def on_msg(self, msg):
         if msg is None:

Modified: pypy/dist/pypy/translator/tool/pygame/graphdisplay.py
==============================================================================
--- pypy/dist/pypy/translator/tool/pygame/graphdisplay.py	(original)
+++ pypy/dist/pypy/translator/tool/pygame/graphdisplay.py	Sat Oct  1 12:22:00 2005
@@ -5,6 +5,7 @@
 from pygame.locals import *
 from pypy.translator.tool.pygame.drawgraph import GraphRenderer
 from pypy.translator.tool.pygame.drawgraph import Node, Edge
+from pypy.translator.tool.pygame.drawgraph import EventQueue, wait_for_events
 
 
 METAKEYS = dict([
@@ -230,9 +231,12 @@
 
         pygame.display.flip()
         while True:
-            e = pygame.event.wait()
+            wait_for_events()
+            e = EventQueue.pop(0)
             if e.type in (MOUSEBUTTONDOWN, KEYDOWN, QUIT):
                 break
+        if e.type == QUIT:
+            EventQueue.insert(0, e)   # re-insert a QUIT
         self.must_redraw = True
 
     def input(self, prompt):
@@ -271,11 +275,13 @@
         text = ""
         self.must_redraw = True
         while True:
-            events = [pygame.event.wait()]
-            events.extend(pygame.event.get())
+            wait_for_events()
             old_text = text
+            events = EventQueue[:]
+            del EventQueue[:]
             for e in events:
                 if e.type == QUIT:
+                    EventQueue.insert(0, e)   # re-insert a QUIT
                     return None
                 elif e.type == KEYDOWN:
                     if e.key == K_ESCAPE:
@@ -565,7 +571,7 @@
         return moving
 
     def peek(self, typ):
-        for event in self.events:
+        for event in EventQueue:
             if event.type == typ:
                 return True
         return False
@@ -652,19 +658,17 @@
 
     def run(self):
         self.dragging = self.click_origin = self.click_time = None
-        events = self.events = []
         try:
 
             while True:
 
-                if self.must_redraw and not events:
+                if self.must_redraw and not EventQueue:
                     self.redraw_now()
 
-                if not events:
-                    events.append(pygame.event.wait())
-                    events.extend(pygame.event.get())
+                if not EventQueue:
+                    wait_for_events()
 
-                self.process_event(events.pop(0))
+                self.process_event(EventQueue.pop(0))
 
         except StopIteration:
             pass



More information about the Pypy-commit mailing list