[pypy-svn] r7290 - pypy/trunk/src/pypy/translator/tool/pygame

bob at codespeak.net bob at codespeak.net
Tue Nov 16 16:59:29 CET 2004


Author: bob
Date: Tue Nov 16 16:59:29 2004
New Revision: 7290

Modified:
   pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
   pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
Log:
ugly mouseover highlighting



Modified: pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/drawgraph.py	Tue Nov 16 16:59:29 2004
@@ -19,11 +19,21 @@
     }
 re_nonword=re.compile(r'(\W+)')
 
+def highlight_color(color):
+    intensity = sum(color)
+    components = []
+    if color == (0,0,0):
+        return (255, 0, 255)
+    elif color == (255,255,255):
+        return (255, 255, 0)
+    return color[1:] + color[:1]
+
 def getcolor(name, default):
     if name in COLOR:
         return COLOR[name]
     elif name.startswith('#') and len(name) == 7:
-        return (int(name[1:3],16), int(name[3:5],16), int(name[5:7],16))
+        rval = COLOR[name] = (int(name[1:3],16), int(name[3:5],16), int(name[5:7],16))
+        return rval
     else:
         return default
 
@@ -70,6 +80,10 @@
         self.shape = shape
         self.color = color
         self.fillcolor = fillcolor
+        self.highlight = False
+
+    def sethighlight(self, which):
+        self.highlight = bool(which)
 
 class Edge:
     label = None
@@ -87,6 +101,10 @@
             self.yl = float(yl)
             rest = rest[3:]
         self.style, self.color = rest
+        self.highlight = False
+
+    def sethighlight(self, which):
+        self.highlight = bool(which)
 
     def bezierpoints(self, resolution=8):
         result = []
@@ -266,6 +284,9 @@
         boxheight = int(node.h * self.scale)
         fgcolor = getcolor(node.color, (0,0,0))
         bgcolor = getcolor(node.fillcolor, (255,255,255))
+        if node.highlight:
+            fgcolor = highlight_color(fgcolor)
+            bgcolor = highlight_color(bgcolor)
 
         text = node.label
         lines = text.replace('\\l','\\l\n').replace('\r','\r\n').split('\n')
@@ -357,6 +378,8 @@
         edgeheadcmd = []
         for edge in self.graphlayout.edges:
             fgcolor = getcolor(edge.color, (0,0,0))
+            if edge.highlight:
+                fgcolor = highlight_color(fgcolor)
             points = [self.map(*xy) for xy in edge.bezierpoints()]
             
             def drawedgebody(points=points, fgcolor=fgcolor):

Modified: pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/pygame/graphdisplay.py	Tue Nov 16 16:59:29 2004
@@ -90,6 +90,7 @@
         self.font = pygame.font.Font(self.STATUSBARFONT, 16)
         self.viewers_history = []
         self.forward_viewers_history = []
+        self.highlight_obj = None
         self.viewer = None
         self.method_cache = {}
         self.key_cache = {}
@@ -249,6 +250,16 @@
             info = self.layout.links[word]
             self.setstatusbar(info)
             self.sethighlight(word)
+            return
+        node = self.viewer.node_at_position(pos)
+        if node:
+            self.sethighlight(obj=node)
+            return
+        edge = self.viewer.edge_at_position(pos)
+        if edge:
+            self.sethighlight(obj=edge)
+            return
+        self.sethighlight()
 
     def notifyclick(self, pos):
         word = self.viewer.at_position(pos)
@@ -270,12 +281,19 @@
                 else:
                     self.look_at_node(edge.tail)
 
-    def sethighlight(self, word=None):
+    def sethighlight(self, word=None, obj=None):
         self.viewer.highlightwords = {}
         for name in self.layout.links:
             self.viewer.highlightwords[name] = ((128,0,0), None)
         if word:
             self.viewer.highlightwords[word] = ((255,255,80), (128,0,0))
+        if self.highlight_obj is not None:
+            self.highlight_obj.sethighlight(False)
+        if obj is not None:
+            obj.sethighlight(True)
+        self.highlight_obj = obj
+        self.must_redraw = True
+            
 
     def animation(self, expectedtime=0.6):
         start = time.time()
@@ -317,7 +335,7 @@
             else:
                 bumpscale = 0.0
             self.statusbarinfo = None
-            self.sethighlight(None)
+            self.sethighlight()
             for t in self.animation():
                 self.viewer.setscale(startscale*(1-t) + endscale*t +
                                      bumpscale*t*(1-t))



More information about the Pypy-commit mailing list