Merge branch 'wip/grc/draw' of http://gnuradio.org/git/jblum
authorJohnathan Corgan <jcorgan@corganenterprises.com>
Tue, 8 Dec 2009 03:40:21 +0000 (22:40 -0500)
committerJohnathan Corgan <jcorgan@corganenterprises.com>
Tue, 8 Dec 2009 03:40:21 +0000 (22:40 -0500)
grc/gui/Block.py
grc/gui/Param.py
grc/gui/Port.py
grc/gui/Utils.py

index 8c65bf06f104a2dd347856460d347775c813ff9f..27143e070420ccdd6cec709f0b2d098e509a5e30 100644 (file)
@@ -29,6 +29,7 @@ from Constants import \
 import pygtk
 pygtk.require('2.0')
 import gtk
+import pango
 
 BLOCK_MARKUP_TMPL="""\
 #set $foreground = $block.is_valid() and 'black' or 'red'
@@ -130,8 +131,11 @@ class Block(Element):
                layout.set_markup(Utils.parse_template(BLOCK_MARKUP_TMPL, block=self))
                self.label_width, self.label_height = layout.get_pixel_size()
                #display the params
-               for param in filter(lambda p: p.get_hide() not in ('all', 'part'), self.get_params()):
-                       layout = param.get_layout()
+               markups = [param.get_markup() for param in self.get_params() if param.get_hide() not in ('all', 'part')]
+               if markups:
+                       layout = gtk.DrawingArea().create_pango_layout('')
+                       layout.set_spacing(LABEL_SEPARATION*pango.SCALE)
+                       layout.set_markup('\n'.join(markups))
                        layouts.append(layout)
                        w,h = layout.get_pixel_size()
                        self.label_width = max(w, self.label_width)
@@ -151,12 +155,11 @@ class Block(Element):
                        else: w_off = 0
                        pixmap.draw_layout(gc, w_off, h_off, layout)
                        h_off = h + h_off + LABEL_SEPARATION
-               #create vertical and horizontal images
-               self.horizontal_label = image = pixmap.get_image(0, 0, width, height)
+               #create vertical and horizontal pixmaps
+               self.horizontal_label = pixmap
                if self.is_vertical():
-                       self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), height, width)
-                       for i in range(width):
-                               for j in range(height): vimage.put_pixel(j, width-i-1, image.get_pixel(i, j))
+                       self.vertical_label = self.get_parent().new_pixmap(height, width)
+                       Utils.rotate_pixmap(gc, self.horizontal_label, self.vertical_label)
                #calculate width and height needed
                self.W = self.label_width + 2*BLOCK_LABEL_PADDING
                self.H = max(*(
@@ -179,9 +182,9 @@ class Block(Element):
                )
                #draw label image
                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)
+                       window.draw_drawable(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)
+                       window.draw_drawable(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1)
                #draw ports
                for port in self.get_ports(): port.draw(gc, window)
 
index cb8bfdc5291accc624977e4bbbaf27d8768bdfa3..b3018dab216a59b43b8539b72abb1a35172585bf 100644 (file)
@@ -165,11 +165,9 @@ class Param(Element):
                if self.get_options(): return EnumEntryParam(self, *args, **kwargs)
                return EntryParam(self, *args, **kwargs)
 
-       def get_layout(self):
+       def get_markup(self):
                """
-               Create a layout based on the current markup.
-               @return the pango layout
+               Get the markup for this param.
+               @return a pango markup string
                """
-               layout = gtk.DrawingArea().create_pango_layout('')
-               layout.set_markup(Utils.parse_template(PARAM_MARKUP_TMPL, param=self))
-               return layout
+               return Utils.parse_template(PARAM_MARKUP_TMPL, param=self)
index 6763f6cbd553f61ab7673095f247687000e06dc4..2896d04c18e0efae889198a503ed1bf99aaeaf52 100644 (file)
@@ -97,12 +97,11 @@ class Port(Element):
                gc.set_foreground(self._bg_color)
                pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
                pixmap.draw_layout(gc, 0, 0, layout)
-               #create the images
-               self.horizontal_label = image = pixmap.get_image(0, 0, self.w, self.h)
+               #create vertical and horizontal pixmaps
+               self.horizontal_label = pixmap
                if self.is_vertical():
-                       self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), self.h, self.w)
-                       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))
+                       self.vertical_label = self.get_parent().get_parent().new_pixmap(self.h, self.w)
+                       Utils.rotate_pixmap(gc, self.horizontal_label, self.vertical_label)
 
        def draw(self, gc, window):
                """
@@ -117,9 +116,9 @@ class Port(Element):
                X,Y = self.get_coordinate()
                (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels
                if self.is_horizontal():
-                       window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
+                       window.draw_drawable(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
                elif self.is_vertical():
-                       window.draw_image(gc, self.vertical_label, 0, 0, x+X+(self.H-self.h)/2, y+Y+(self.W-self.w)/2, -1, -1)
+                       window.draw_drawable(gc, self.vertical_label, 0, 0, x+X+(self.H-self.h)/2, y+Y+(self.W-self.w)/2, -1, -1)
 
        def get_connector_coordinate(self):
                """
index 83036a4b858c0c4eb5460738be7eb2f3e4002e6d..b5489d56e7ac5cc2c866ee385f9625605a40e750 100644 (file)
@@ -19,8 +19,31 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 
 from Constants import POSSIBLE_ROTATIONS
 from Cheetah.Template import Template
+import pygtk
+pygtk.require('2.0')
+import gtk
 import gobject
 
+def rotate_pixmap(gc, src_pixmap, dst_pixmap, angle=gtk.gdk.PIXBUF_ROTATE_COUNTERCLOCKWISE):
+       """
+       Load the destination pixmap with a rotated version of the source pixmap.
+       The source pixmap will be loaded into a pixbuf, rotated, and drawn to the destination pixmap.
+       The pixbuf is a client-side drawable, where a pixmap is a server-side drawable.
+       @param gc the graphics context
+       @param src_pixmap the source pixmap
+       @param dst_pixmap the destination pixmap
+       @param angle the angle to rotate by
+       """
+       width, height = src_pixmap.get_size()
+       pixbuf = gtk.gdk.Pixbuf(
+               colorspace=gtk.gdk.COLORSPACE_RGB,
+               has_alpha=False, bits_per_sample=8,
+               width=width, height=height,
+       )
+       pixbuf.get_from_drawable(src_pixmap, src_pixmap.get_colormap(), 0, 0, 0, 0, -1, -1)
+       pixbuf = pixbuf.rotate_simple(angle)
+       dst_pixmap.draw_pixbuf(gc, pixbuf, 0, 0, 0, 0)
+
 def get_rotated_coordinate(coor, rotation):
        """
        Rotate the coordinate by the given rotation.