diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Block.py | 29 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 8 |
2 files changed, 36 insertions, 1 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 11c1cafc97..5d3ae457da 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -35,6 +35,9 @@ import pango BLOCK_MARKUP_TMPL="""\ #set $foreground = $block.is_valid() and 'black' or 'red' <span foreground="$foreground" font_desc="$font"><b>$encode($block.get_name())</b></span>""" +COMMENT_MARKUP_TMPL="""\ +#set $foreground = $block.get_enabled() and '#444' or '#888' +<span foreground="$foreground" font_desc="$font">$encode($block.get_comment())</span>""" class Block(Element): """The graphical signal block.""" @@ -68,6 +71,7 @@ class Block(Element): }) )) Element.__init__(self) + self._comment_pixmap = None def get_coordinate(self): """ @@ -203,6 +207,23 @@ class Block(Element): for ports in (self.get_sources_gui(), self.get_sinks_gui()) ] )) + self.create_comment_label() + + def create_comment_label(self): + comment = self.get_comment() + if comment: + layout = gtk.DrawingArea().create_pango_layout('') + layout.set_markup(Utils.parse_template(COMMENT_MARKUP_TMPL, block=self, font=BLOCK_FONT)) + width, height = layout.get_pixel_size() + pixmap = self.get_parent().new_pixmap(width, height) + gc = pixmap.new_gc() + gc.set_foreground(Colors.FLOWGRAPH_BACKGROUND_COLOR) + pixmap.draw_rectangle(gc, True, 0, 0, width, height) + pixmap.draw_layout(gc, 0, 0, layout) + self._comment_pixmap = pixmap + else: + self._comment_pixmap = None + def draw(self, gc, window): """ @@ -243,3 +264,11 @@ class Block(Element): port_selected = port.what_is_selected(coor, coor_m) if port_selected: return port_selected return Element.what_is_selected(self, coor, coor_m) + + def draw_comment(self, gc, window): + if not self._comment_pixmap: + return + + x, y = self.get_coordinate() + window.draw_drawable(gc, self._comment_pixmap, 0, 0, x, + y + self.H + BLOCK_LABEL_PADDING, -1, -1) diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index f8be2f6cc3..d512a6793d 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -280,6 +280,12 @@ class FlowGraph(Element): #draw the background gc.set_foreground(Colors.FLOWGRAPH_BACKGROUND_COLOR) window.draw_rectangle(gc, True, 0, 0, W, H) + # draw comments first + hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active() + for block in self.get_blocks(): + if hide_disabled_blocks and not block.get_enabled(): + continue # skip hidden disabled block comments + block.draw_comment(gc, window) #draw multi select rectangle if self.mouse_pressed and (not self.get_selected_elements() or self.get_ctrl_mask()): #coordinates @@ -295,7 +301,7 @@ class FlowGraph(Element): window.draw_rectangle(gc, False, x, y, w, h) #draw blocks on top of connections for element in self.get_connections() + self.get_blocks(): - if Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active() and not element.get_enabled(): + if hide_disabled_blocks and not element.get_enabled(): continue # skip hidden disabled blocks and connections element.draw(gc, window) #draw selected blocks on top of selected connections |