commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/05: grc: add block comments


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/05: grc: add block comments
Date: Sat, 4 Apr 2015 17:45:40 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 3271e9f31c11a4fc36a3989e236f2dc919bda86b
Author: Sebastian Koslowski <address@hidden>
Date:   Tue Mar 24 15:50:45 2015 +0100

    grc: add block comments
---
 grc/base/Block.py    | 12 ++++++++++++
 grc/gui/Block.py     | 29 +++++++++++++++++++++++++++++
 grc/gui/FlowGraph.py |  8 +++++++-
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/grc/base/Block.py b/grc/base/Block.py
index 128cc5e..5670d11 100644
--- a/grc/base/Block.py
+++ b/grc/base/Block.py
@@ -185,6 +185,17 @@ class Block(Element):
                              })
                     ))
 
+        self.get_params().append(self.get_parent().get_parent().Param(
+                block=self,
+                n=odict({'name': 'Comment',
+                         'key': 'comment',
+                         'type': 'string',
+                         'hide': 'part',
+                         'value': '',
+                         'tab': ADVANCED_PARAM_TAB
+                         })
+                ))
+
 
     def back_ofthe_bus(self, portlist):
         portlist.sort(key=lambda p: p._type == 'bus')
@@ -226,6 +237,7 @@ class Block(Element):
     def get_children(self): return self.get_ports() + self.get_params()
     def get_children_gui(self): return self.get_ports_gui() + self.get_params()
     def get_block_wrapper_path(self): return self._block_wrapper_path
+    def get_comment(self): return self.get_param('comment').get_value()
 
     ##############################################
     # Access Params
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 11c1caf..5d3ae45 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 f8be2f6..d512a67 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



reply via email to

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