summaryrefslogtreecommitdiff
path: root/grc/gui/BlockTreeWindow.py
diff options
context:
space:
mode:
Diffstat (limited to 'grc/gui/BlockTreeWindow.py')
-rw-r--r--grc/gui/BlockTreeWindow.py85
1 files changed, 57 insertions, 28 deletions
diff --git a/grc/gui/BlockTreeWindow.py b/grc/gui/BlockTreeWindow.py
index 4279e8c61d..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,56 +134,65 @@ 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}
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]
- 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
- 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 +256,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 +264,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()