commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10824 - in gnuradio/branches/developers/jblum/grc/grc


From: jblum
Subject: [Commit-gnuradio] r10824 - in gnuradio/branches/developers/jblum/grc/grc/src: gui platforms/gui
Date: Tue, 14 Apr 2009 00:35:51 -0600 (MDT)

Author: jblum
Date: 2009-04-14 00:35:50 -0600 (Tue, 14 Apr 2009)
New Revision: 10824

Modified:
   gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
   gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Block.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Connection.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Element.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
   gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Port.py
Log:
Drawing refactor.
All drawing routines stem from the expose event.
Call queue_draw to signal expose event.
Pass graphics context (gc) and drawable (window) to each element's draw routine.



Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py 
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/ActionHandler.py 
2009-04-14 06:35:50 UTC (rev 10824)
@@ -302,7 +302,7 @@
                elif state == Actions.FLOW_GRAPH_SCREEN_CAPTURE:
                        file_path = 
SaveImageFileDialog(self.get_page().get_file_path()).run()
                        if file_path is not None:
-                               pixmap = 
self.get_flow_graph().get_drawing_area().pixmap
+                               pixmap = self.get_flow_graph().get_pixmap()
                                width, height = pixmap.get_size()
                                pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 
0, 8, width, height)
                                pixbuf.get_from_drawable(pixmap, 
pixmap.get_colormap(), 0, 0, 0, 0, width, height)
@@ -354,7 +354,7 @@
                
Actions.get_action_from_name(Actions.FLOW_GRAPH_SAVE).set_sensitive(not 
self.get_page().get_saved())
                self.main_window.update()
                #draw the flow graph
-               self.get_flow_graph().draw()
+               self.get_flow_graph().queue_draw()
 
        def update_exec_stop(self):
                """

Modified: gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py   
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/gui/DrawingArea.py   
2009-04-14 06:35:50 UTC (rev 10824)
@@ -61,14 +61,7 @@
                self.connect("enter-notify-event", self._handle_focus_event, 
True)
                #pixmap for drawing
                self.pixmap = None
-               self.gc = None
 
-       def draw(self):
-               """
-               Draw the pixmap onto this drawing area.
-               """
-               self.window.draw_drawable(self.gc, self.pixmap, 0, 0, 0, 0, -1, 
-1)
-
        
##########################################################################
        ## Handlers
        
##########################################################################
@@ -117,11 +110,12 @@
 
        def _handle_window_expose(self, widget, event):
                """
-               Called when the window initially appears or is resized: create 
a new pixmap, draw the flow graph.
+               Called when window is exposed, resized, or queue_draw is called.
                """
-               self.gc = self.window.new_gc()
+               gc = self.window.new_gc()
                width, height = self.get_size_request()
                if not self.pixmap or (width, height) != self.pixmap.get_size():
                        self.pixmap = gtk.gdk.Pixmap(self.window, width, 
height, -1)
-               self._main_window.get_flow_graph().draw()
-               return True
+               #double buffering: draw to pixmap, then draw pixmap
+               self._main_window.get_flow_graph().draw(gc, self.pixmap)
+               self.window.draw_drawable(gc, self.pixmap, 0, 0, 0, 0, -1, -1)

Modified: gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Block.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Block.py       
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Block.py       
2009-04-14 06:35:50 UTC (rev 10824)
@@ -167,22 +167,22 @@
                                for j in range(height): vimage.put_pixel(j, 
width-i-1, image.get_pixel(i, j))
                map(lambda p: p._create_labels(), self.get_ports())
 
-       def draw(self, window):
+       def draw(self, gc, window):
                """
                Draw the signal block with label and inputs/outputs.
+               @param gc the graphics context
                @param window the gtk window to draw on
                """
                x, y = self.get_coordinate()
                #draw main block
-               Element.draw(self, window, BG_color=self.bg_color)
+               Element.draw(self, gc, window, BG_color=self.bg_color)
                #draw label image
-               gc = self.get_gc()
                if self.is_horizontal():
                        window.draw_image(gc, self.horizontal_label, 0, 0, 
x+BLOCK_LABEL_PADDING, y+(self.H-self.label_height)/2, -1, -1)
                elif self.is_vertical():
                        window.draw_image(gc, self.vertical_label, 0, 0, 
x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1)
                #draw ports
-               map(lambda p: p.draw(window), self.get_ports())
+               for port in self.get_ports(): port.draw(gc, window)
 
        def what_is_selected(self, coor, coor_m=None):
                """

Modified: 
gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Connection.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Connection.py  
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Connection.py  
2009-04-14 06:35:50 UTC (rev 10824)
@@ -106,9 +106,10 @@
                        self.add_line((x1, y1), points[0])
                        self.add_line((x2, y2), points[0])
 
-       def draw(self, window):
+       def draw(self, gc, window):
                """
                Draw the connection.
+               @param gc the graphics context
                @param window the gtk window to draw on
                """
                sink = self.get_sink()
@@ -123,8 +124,7 @@
                self._source_coor = source.get_coordinate()
                #draw
                fg_color = self.get_enabled() and Colors.FG_COLOR or 
Colors.DISABLED_FG_COLOR
-               Element.draw(self, window, FG_color=fg_color)
-               gc = self.get_gc()
+               Element.draw(self, gc, window, FG_color=fg_color)
                gc.foreground = self._foreground
                #draw arrow on sink port
                window.draw_polygon(gc, True, self._arrow)

Modified: 
gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Element.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Element.py     
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Element.py     
2009-04-14 06:35:50 UTC (rev 10824)
@@ -61,17 +61,14 @@
                rotation = rotation or self.get_rotation()
                return rotation in (90, 270)
 
-       def get_gc(self): return self._gc
-
-       def draw(self, window, BG_color=Colors.BG_COLOR, 
FG_color=Colors.FG_COLOR):
+       def draw(self, gc, window, BG_color=Colors.BG_COLOR, 
FG_color=Colors.FG_COLOR):
                """
                Draw in the given window.
+               @param gc the graphics context
                @param window the gtk window to draw on
                @param BG_color the background color
                @param FG_color the foreground color
                """
-               gc = self.get_parent().get_gc()
-               self._gc = gc
                X,Y = self.get_coordinate()
                for (rX,rY),(W,H) in self.areas_dict[self.get_rotation()]:
                        aX = X + rX

Modified: 
gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py   
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/FlowGraph.py   
2009-04-14 06:35:50 UTC (rev 10824)
@@ -65,11 +65,11 @@
        # Access Drawing Area
        
###########################################################################
        def get_drawing_area(self): return self.drawing_area
-       def get_gc(self): return self.get_drawing_area().gc
-       def get_pixmap(self): return self.get_drawing_area().pixmap
+       def queue_draw(self): self.get_drawing_area().queue_draw()
        def get_size(self): return self.get_drawing_area().get_size_request()
        def set_size(self, *args): 
self.get_drawing_area().set_size_request(*args)
        def get_window(self): return self.get_drawing_area().window
+       def get_pixmap(self): return self.get_drawing_area().pixmap
        def get_scroll_pane(self): return self.drawing_area.get_parent()
        def get_ctrl_mask(self): return self.drawing_area.ctrl_mask
 
@@ -248,7 +248,7 @@
                        changed = True
                return changed
 
-       def draw(self):
+       def draw(self, gc, window):
                """
                Draw the background and grid if enabled.
                Draw all of the elements in this flow graph onto the pixmap.
@@ -258,43 +258,39 @@
                        new_size = self.get_option('window_size')
                        if self.get_size() != tuple(new_size): 
self.set_size(*new_size)
                except: pass
-               if self.get_gc():
-                       W,H = self.get_size()
-                       #draw the background
-                       self.get_gc().foreground = Colors.BACKGROUND_COLOR
-                       self.get_pixmap().draw_rectangle(self.get_gc(), True, 
0, 0, W, H)
-                       #draw multi select rectangle
-                       if self.mouse_pressed and (not 
self.get_selected_elements() or self.get_ctrl_mask()):
-                               #coordinates
-                               x1, y1 = self.press_coor
-                               x2, y2 = self.get_coordinate()
-                               #calculate top-left coordinate and width/height
-                               x, y = int(min(x1, x2)), int(min(y1, y2))
-                               w, h = int(abs(x1 - x2)), int(abs(y1 - y2))
-                               #draw
-                               self.get_gc().foreground = Colors.H_COLOR
-                               self.get_pixmap().draw_rectangle(self.get_gc(), 
True, x, y, w, h)
-                               self.get_gc().foreground = Colors.TXT_COLOR
-                               self.get_pixmap().draw_rectangle(self.get_gc(), 
False, x, y, w, h)
-                       #draw blocks on top of connections
-                       for element in self.get_connections() + 
self.get_blocks():
-                               element.draw(self.get_pixmap())
-                       #draw selected blocks on top of selected connections
-                       for selected_element in self.get_selected_connections() 
+ self.get_selected_blocks():
-                               selected_element.draw(self.get_pixmap())
-                       self.get_drawing_area().draw()
+               W,H = self.get_size()
+               #draw the background
+               gc.foreground = Colors.BACKGROUND_COLOR
+               window.draw_rectangle(gc, True, 0, 0, W, H)
+               #draw multi select rectangle
+               if self.mouse_pressed and (not self.get_selected_elements() or 
self.get_ctrl_mask()):
+                       #coordinates
+                       x1, y1 = self.press_coor
+                       x2, y2 = self.get_coordinate()
+                       #calculate top-left coordinate and width/height
+                       x, y = int(min(x1, x2)), int(min(y1, y2))
+                       w, h = int(abs(x1 - x2)), int(abs(y1 - y2))
+                       #draw
+                       gc.foreground = Colors.H_COLOR
+                       window.draw_rectangle(gc, True, x, y, w, h)
+                       gc.foreground = Colors.TXT_COLOR
+                       window.draw_rectangle(gc, False, x, y, w, h)
+               #draw blocks on top of connections
+               for element in self.get_connections() + self.get_blocks():
+                       element.draw(gc, window)
+               #draw selected blocks on top of selected connections
+               for selected_element in self.get_selected_connections() + 
self.get_selected_blocks():
+                       selected_element.draw(gc, window)
 
        def update(self):
                """
                Update highlighting so only the selected is highlighted.
                Call update on all elements.
                """
-               #update highlighting
-               map(lambda e: e.set_highlighted(False), self.get_elements())
-               for selected_element in self.get_selected_elements():
-                       selected_element.set_highlighted(True)
-               #update all elements
-               map(lambda e: e.update(), self.get_elements())
+               selected_elements = self.get_selected_elements()
+               for element in self.get_elements():
+                       element.set_highlighted(element in selected_elements)
+                       element.update()
 
        
##########################################################################
        ## Get Selected
@@ -457,7 +453,6 @@
                        self.handle_states(BLOCK_MOVE)
                        self.element_moved = False
                self.update_selected_elements()
-               self.draw()
 
        def handle_mouse_motion(self, coordinate):
                """
@@ -490,7 +485,8 @@
                #move the selected elements and record the new coordinate
                X, Y = self.get_coordinate()
                if not self.get_ctrl_mask(): self.move_selected((int(x - X), 
int(y - Y)))
-               self.draw()
                self.set_coordinate((x, y))
                #update time
                self.time = time.time()
+               #queue draw for animation
+               self.queue_draw()

Modified: gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Port.py
===================================================================
--- gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Port.py        
2009-04-14 05:20:39 UTC (rev 10823)
+++ gnuradio/branches/developers/jblum/grc/grc/src/platforms/gui/Port.py        
2009-04-14 06:35:50 UTC (rev 10824)
@@ -104,13 +104,13 @@
                        for i in range(self.w):
                                for j in range(self.h): vimage.put_pixel(j, 
self.w-i-1, image.get_pixel(i, j))
 
-       def draw(self, window):
+       def draw(self, gc, window):
                """
                Draw the socket with a label.
+               @param gc the graphics context
                @param window the gtk window to draw on
                """
-               Element.draw(self, window, BG_color=self.BG_color)
-               gc = self.get_gc()
+               Element.draw(self, gc, window, BG_color=self.BG_color)
                gc.foreground = Colors.TXT_COLOR
                X,Y = self.get_coordinate()
                (x,y),(w,h) = self.areas_dict[self.get_rotation()][0] #use the 
first area's sizes to place the labels





reply via email to

[Prev in Thread] Current Thread [Next in Thread]