From 1937f756fd4027ace86316fc6fb1433cd832e6eb Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Tue, 5 Apr 2016 22:03:43 +0200
Subject: grc: separate core and OOT block trees via the category of each block

Each block get assigned a module based on the root of its category.
The category is set via a block_tree.xml or else from its <category> tag.
The category root is only interpreted as module name if it is in square brackets.
Else the default module 'Others' is used.
---
 grc/gui/BlockTreeWindow.py | 41 ++++++++++++++++++++++++-----------------
 1 file changed, 24 insertions(+), 17 deletions(-)

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

diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index 4279e8c61d..6ba5144fa4 100644
--- a/grc/gui/BlockTreeWindow.py
+++ b/grc/gui/BlockTreeWindow.py
@@ -124,33 +124,42 @@ class BlockTreeWindow(gtk.VBox):
         # map categories to iters, automatic mapping for root
         self._categories = {tuple(): None}
         self._categories_search = {tuple(): None}
-        # add blocks and categories
-        self.platform.load_block_tree(self)
         self.platform.block_docstrings_loaded_callback = self.update_docs
+        self.repopulate()
 
     def clear(self):
-        self.treestore.clear();
-        self._categories = {tuple(): None}
+        self.treestore.clear()
+        self._categories = {(): None}
+
+    def repopulate(self):
+        self.clear()
+        for block in self.platform.blocks.itervalues():
+            if block.category:
+                self.add_block(block)
+        self.expand_module_in_tree()
+
+    def expand_module_in_tree(self, module_name='Core'):
+        self.treeview.collapse_all()
+        core_module_iter = self._categories.get((module_name,))
+        if core_module_iter:
+            self.treeview.expand_row(self.treestore.get_path(core_module_iter), False)
 
     ############################################################
     ## Block Tree Methods
     ############################################################
-    def add_block(self, category, block=None, treestore=None, categories=None):
+    def add_block(self, block, treestore=None, categories=None):
         """
         Add a block with category to this selection window.
         Add only the category when block is None.
 
         Args:
-            category: the category list or path string
             block: the block object or None
         """
-        if treestore is None:
-            treestore = self.treestore
-        if categories is None:
-            categories = self._categories
+        treestore = treestore or self.treestore
+        categories = categories or self._categories
+
+        category = tuple(filter(str, block.category))  # tuple is hashable, remove empty cats
 
-        if isinstance(category, (str, unicode)): category = category.split('/')
-        category = tuple(filter(lambda x: x, category))  # tuple is hashable
         # add category and all sub categories
         for i, cat_name in enumerate(category):
             sub_category = category[:i+1]
@@ -160,9 +169,8 @@ class BlockTreeWindow(gtk.VBox):
                 treestore.set_value(iter_, KEY_INDEX, '')
                 treestore.set_value(iter_, DOC_INDEX, Utils.parse_template(CAT_MARKUP_TMPL, cat=cat_name))
                 categories[sub_category] = iter_
+
         # add block
-        if block is None:
-            return
         iter_ = treestore.insert_before(categories[category], None)
         treestore.set_value(iter_, NAME_INDEX, block.get_name())
         treestore.set_value(iter_, KEY_INDEX, block.get_key())
@@ -226,7 +234,7 @@ class BlockTreeWindow(gtk.VBox):
         key = widget.get_text().lower()
         if not key:
             self.treeview.set_model(self.treestore)
-            self.treeview.collapse_all()
+            self.expand_module_in_tree()
         else:
             matching_blocks = filter(lambda b: key in b.get_key().lower() or key in b.get_name().lower(),
                                      self.platform.blocks.values())
@@ -234,8 +242,7 @@ class BlockTreeWindow(gtk.VBox):
             self.treestore_search.clear()
             self._categories_search = {tuple(): None}
             for block in matching_blocks:
-                self.add_block(block.get_category() or 'None', block,
-                               self.treestore_search, self._categories_search)
+                self.add_block(block, self.treestore_search, self._categories_search)
             self.treeview.set_model(self.treestore_search)
             self.treeview.expand_all()
 
-- 
cgit v1.2.3


From 0e1b7106f64a81bbf6a6a6fd85b291d1a406ac0e Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Wed, 25 May 2016 17:03:42 +0200
Subject: grc: add helpful tooltips to Core and Others in block tree

---
 grc/gui/BlockTreeWindow.py | 44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

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

diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index 6ba5144fa4..f49eb6c4fe 100644
--- a/grc/gui/BlockTreeWindow.py
+++ b/grc/gui/BlockTreeWindow.py
@@ -23,7 +23,8 @@ import gtk
 import gobject
 
 from . import Actions, Utils
-from .Constants import DEFAULT_BLOCKS_WINDOW_WIDTH, DND_TARGETS
+from . import Constants
+
 
 NAME_INDEX = 0
 KEY_INDEX = 1
@@ -54,7 +55,27 @@ $encode($line)#slurp
 undocumented#slurp
 #end if"""
 
-CAT_MARKUP_TMPL = """Category: $cat"""
+CAT_MARKUP_TMPL = """
+#set $name = $cat[-1]
+#if len($cat) > 1
+Category: $cat[-1]
+##
+#elif $name == 'Core'
+Module: Core
+
+This subtree is meant for blocks included with GNU Radio (in-tree).
+##
+#elif $name == $default_module
+This subtree holds all blocks (from OOT modules) that specify no module name. \
+The module name is the root category enclosed in square brackets.
+
+Please consider contacting OOT module maintainer for any block in here \
+and kindly ask to update their GRC Block Descriptions or Block Tree to include a module name.
+#else
+Module: $name
+##
+#end if
+""".strip()
 
 
 class BlockTreeWindow(gtk.VBox):
@@ -113,13 +134,13 @@ class BlockTreeWindow(gtk.VBox):
         column.set_sort_column_id(0)
         self.treestore.set_sort_column_id(0, gtk.SORT_ASCENDING)
         # setup drag and drop
-        self.treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, DND_TARGETS, gtk.gdk.ACTION_COPY)
+        self.treeview.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, Constants.DND_TARGETS, gtk.gdk.ACTION_COPY)
         self.treeview.connect('drag-data-get', self._handle_drag_get_data)
         # make the scrolled window to hold the tree view
         scrolled_window = gtk.ScrolledWindow()
         scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
         scrolled_window.add_with_viewport(self.treeview)
-        scrolled_window.set_size_request(DEFAULT_BLOCKS_WINDOW_WIDTH, -1)
+        scrolled_window.set_size_request(Constants.DEFAULT_BLOCKS_WINDOW_WIDTH, -1)
         self.pack_start(scrolled_window)
         # map categories to iters, automatic mapping for root
         self._categories = {tuple(): None}
@@ -161,14 +182,15 @@ class BlockTreeWindow(gtk.VBox):
         category = tuple(filter(str, block.category))  # tuple is hashable, remove empty cats
 
         # add category and all sub categories
-        for i, cat_name in enumerate(category):
-            sub_category = category[:i+1]
-            if sub_category not in categories:
-                iter_ = treestore.insert_before(categories[sub_category[:-1]], None)
-                treestore.set_value(iter_, NAME_INDEX, cat_name)
+        for level, parent_cat_name in enumerate(category, 1):
+            parent_category = category[:level]
+            if parent_category not in categories:
+                iter_ = treestore.insert_before(categories[parent_category[:-1]], None)
+                treestore.set_value(iter_, NAME_INDEX, parent_cat_name)
                 treestore.set_value(iter_, KEY_INDEX, '')
-                treestore.set_value(iter_, DOC_INDEX, Utils.parse_template(CAT_MARKUP_TMPL, cat=cat_name))
-                categories[sub_category] = iter_
+                treestore.set_value(iter_, DOC_INDEX, Utils.parse_template(
+                    CAT_MARKUP_TMPL, cat=parent_category, default_module=Constants.DEFAULT_BLOCK_MODULE_NAME))
+                categories[parent_category] = iter_
 
         # add block
         iter_ = treestore.insert_before(categories[category], None)
-- 
cgit v1.2.3