From aaf5aa760a6876d7f5b878c563e002da19157cdb Mon Sep 17 00:00:00 2001
From: Seth Hitefield <sdhitefield@gmail.com>
Date: Fri, 28 Aug 2015 13:55:29 -0400
Subject: grc: Flowgraph complexity. Shows under options block when enabled.

---
 grc/gui/Block.py | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

(limited to 'grc/gui/Block.py')

diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 11273a537b..94ed5802d1 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -21,6 +21,7 @@ from Element import Element
 import Utils
 import Colors
 from .. base import odict
+from .. python.Param import num_to_str
 from Constants import BORDER_PROXIMITY_SENSITIVITY
 from Constants import (
     BLOCK_LABEL_PADDING, PORT_SPACING, PORT_SEPARATION, LABEL_SEPARATION,
@@ -35,9 +36,17 @@ 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="""\
+
+# Includes the additional complexity markup if enabled
+COMMENT_COMPLEXITY_MARKUP_TMPL="""\
 #set $foreground = $block.get_enabled() and '#444' or '#888'
-<span foreground="$foreground" font_desc="$font">$encode($block.get_comment())</span>"""
+#if $complexity
+<span foreground="#444" size="medium" font_desc="$font"><b>$encode($complexity)</b></span>
+#end if
+#if $comment
+<span foreground="$foreground" font_desc="$font">$encode($comment)</span>#slurp
+#end if"""
+
 
 class Block(Element):
     """The graphical signal block."""
@@ -218,11 +227,23 @@ class Block(Element):
         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()
+        comment = self.get_comment()    # Returns None if there are no comments
+        complexity = None
+
+        # Show the flowgraph complexity on the top block if enabled
+        if Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY.get_active() and self.get_key() == "options":
+            complexity = "Complexity: {}bal".format(num_to_str(self.get_parent().get_complexity()))
+
+        layout = gtk.DrawingArea().create_pango_layout('')
+        layout.set_markup(Utils.parse_template(COMMENT_COMPLEXITY_MARKUP_TMPL,
+                                               block=self,
+                                               comment=comment,
+                                               complexity=complexity,
+                                               font=BLOCK_FONT))
+
+        # Setup the pixel map. Make sure that layout is valid
+        width, height = layout.get_pixel_size()
+        if layout and width > 0 and height > 0:
             pixmap = self.get_parent().new_pixmap(width, height)
             gc = pixmap.new_gc()
             gc.set_foreground(Colors.COMMENT_BACKGROUND_COLOR)
-- 
cgit v1.2.3


From e7b408195e7ee58c3983e64d44b844f8332a05cd Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Fri, 25 Sep 2015 13:48:50 +0200
Subject: grc: pad comment boxes like blocks

---
 grc/gui/Block.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

(limited to 'grc/gui/Block.py')

diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 94ed5802d1..7350e4bdfe 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -241,14 +241,17 @@ class Block(Element):
                                                complexity=complexity,
                                                font=BLOCK_FONT))
 
-        # Setup the pixel map. Make sure that layout is valid
+        # Setup the pixel map. Make sure that layout not empty
         width, height = layout.get_pixel_size()
-        if layout and width > 0 and height > 0:
-            pixmap = self.get_parent().new_pixmap(width, height)
+        if width and height:
+            padding = BLOCK_LABEL_PADDING
+            pixmap = self.get_parent().new_pixmap(width + 2 * padding,
+                                                  height + 2 * padding)
             gc = pixmap.new_gc()
             gc.set_foreground(Colors.COMMENT_BACKGROUND_COLOR)
-            pixmap.draw_rectangle(gc, True, 0, 0, width, height)
-            pixmap.draw_layout(gc, 0, 0, layout)
+            pixmap.draw_rectangle(
+                gc, True, 0, 0, width + 2 * padding, height + 2 * padding)
+            pixmap.draw_layout(gc, padding, padding, layout)
             self._comment_pixmap = pixmap
         else:
             self._comment_pixmap = None
-- 
cgit v1.2.3