commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 04/25: grc: optionally hide all variable bl


From: git
Subject: [Commit-gnuradio] [gnuradio] 04/25: grc: optionally hide all variable blocks
Date: Fri, 27 May 2016 19:14:58 +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 c1231897581423b6402beaba02c2b22b3445925c
Author: Sebastian Koslowski <address@hidden>
Date:   Sat May 7 13:32:45 2016 +0200

    grc: optionally hide all variable blocks
---
 grc/core/Block.py        | 16 ++++++++--------
 grc/core/Element.py      |  5 +++++
 grc/core/FlowGraph.py    | 18 ++++++++----------
 grc/gui/ActionHandler.py | 12 +++++++-----
 grc/gui/Actions.py       |  6 ++++++
 grc/gui/Bars.py          |  1 +
 grc/gui/FlowGraph.py     | 16 ++++++++++++++--
 7 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/grc/core/Block.py b/grc/core/Block.py
index c2111fe..ab4174c 100644
--- a/grc/core/Block.py
+++ b/grc/core/Block.py
@@ -30,7 +30,6 @@ from . Constants import (
     BLOCK_ENABLED, BLOCK_BYPASSED, BLOCK_DISABLED
 )
 from . Element import Element
-from . FlowGraph import _variable_matcher
 
 
 def _get_keys(lst):
@@ -149,15 +148,16 @@ class Block(Element):
         # indistinguishable from normal GR blocks. Make explicit
         # checks for them here since they have no work function or
         # buffers to manage.
-        is_virtual_or_pad = self._key in (
+        self.is_virtual_or_pad = self._key in (
             "virtual_source", "virtual_sink", "pad_source", "pad_sink")
-        is_variable = self._key.startswith('variable')
+        self.is_variable = self._key.startswith('variable')
+        self.is_import = (self._key == 'import')
 
         # Disable blocks that are virtual/pads or variables
-        if is_virtual_or_pad or is_variable:
+        if self.is_virtual_or_pad or self.is_variable:
             self._flags += BLOCK_FLAG_DISABLE_BYPASS
 
-        if not (is_virtual_or_pad or is_variable or self._key == 'options'):
+        if not (self.is_virtual_or_pad or self.is_variable or self._key == 
'options'):
             self.get_params().append(self.get_parent().get_parent().Param(
                 block=self,
                 n=odict({'name': 'Block Alias',
@@ -168,7 +168,7 @@ class Block(Element):
                          })
             ))
 
-        if (len(sources) or len(sinks)) and not is_virtual_or_pad:
+        if (len(sources) or len(sinks)) and not self.is_virtual_or_pad:
             self.get_params().append(self.get_parent().get_parent().Param(
                     block=self,
                     n=odict({'name': 'Core Affinity',
@@ -178,7 +178,7 @@ class Block(Element):
                              'tab': ADVANCED_PARAM_TAB
                              })
                     ))
-        if len(sources) and not is_virtual_or_pad:
+        if len(sources) and not self.is_virtual_or_pad:
             self.get_params().append(self.get_parent().get_parent().Param(
                     block=self,
                     n=odict({'name': 'Min Output Buffer',
@@ -253,7 +253,7 @@ class Block(Element):
                 self.add_error_message('Check "{}" did not 
evaluate.'.format(check))
 
         # For variables check the value (only if var_value is used
-        if _variable_matcher.match(self.get_key()) and self._var_value != 
'$value':
+        if self.is_variable and self._var_value != '$value':
             value = self._var_value
             try:
                 value = self.get_var_value()
diff --git a/grc/core/Element.py b/grc/core/Element.py
index b96edb0..67c36e1 100644
--- a/grc/core/Element.py
+++ b/grc/core/Element.py
@@ -100,6 +100,7 @@ class Element(object):
     is_flow_graph = False
 
     is_block = False
+
     is_dummy_block = False
 
     is_connection = False
@@ -107,3 +108,7 @@ class Element(object):
     is_port = False
 
     is_param = False
+
+    is_variable = False
+
+    is_import = False
diff --git a/grc/core/FlowGraph.py b/grc/core/FlowGraph.py
index 2f33baf..949eeca 100644
--- a/grc/core/FlowGraph.py
+++ b/grc/core/FlowGraph.py
@@ -18,7 +18,7 @@
 import imp
 import time
 from itertools import ifilter, chain
-from operator import methodcaller
+from operator import methodcaller, attrgetter
 
 import re
 
@@ -27,7 +27,6 @@ from .Constants import FLOW_GRAPH_FILE_FORMAT_VERSION
 from .Element import Element
 from .utils import odict, expr_utils
 
-_variable_matcher = re.compile('^(variable\w*)$')
 _parameter_matcher = re.compile('^(parameter)$')
 _monitors_searcher = re.compile('(ctrlport_monitor)')
 _bussink_searcher = re.compile('^(bus_sink)$')
@@ -72,32 +71,31 @@ class FlowGraph(Element):
     ##############################################
     def get_imports(self):
         """
-        Get a set of all import statments in this flow graph namespace.
+        Get a set of all import statements in this flow graph namespace.
 
         Returns:
             a set of import statements
         """
-        imports = sum([block.get_imports() for block in 
self.get_enabled_blocks()], [])
-        imports = sorted(set(imports))
-        return imports
+        imports = sum([block.get_imports() for block in 
self.iter_enabled_blocks()], [])
+        return sorted(set(imports))
 
     def get_variables(self):
         """
         Get a list of all variables in this flow graph namespace.
-        Exclude paramterized variables.
+        Exclude parameterized variables.
 
         Returns:
             a sorted list of variable blocks in order of dependency (indep -> 
dep)
         """
-        variables = filter(lambda b: _variable_matcher.match(b.get_key()), 
self.iter_enabled_blocks())
+        variables = filter(attrgetter('is_variable'), 
self.iter_enabled_blocks())
         return expr_utils.sort_objects(variables, methodcaller('get_id'), 
methodcaller('get_var_make'))
 
     def get_parameters(self):
         """
-        Get a list of all paramterized variables in this flow graph namespace.
+        Get a list of all parameterized variables in this flow graph namespace.
 
         Returns:
-            a list of paramterized variables
+            a list of parameterized variables
         """
         parameters = filter(lambda b: _parameter_matcher.match(b.get_key()), 
self.iter_enabled_blocks())
         return parameters
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 1d81674..422d107 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -136,6 +136,7 @@ class ActionHandler:
                 Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB,
                 Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY,
                 Actions.FLOW_GRAPH_OPEN_QSS_THEME,
+                Actions.TOGGLE_HIDE_VARIABLES,
                 Actions.SELECT_ALL,
             ):
                 action.set_sensitive(True)
@@ -413,16 +414,17 @@ class ActionHandler:
             action.save_to_preferences()
             for page in self.main_window.get_pages():
                 page.get_flow_graph().create_shapes()
-        elif action == Actions.TOGGLE_SNAP_TO_GRID:
-            action.save_to_preferences()
-        elif action == Actions.TOGGLE_SHOW_BLOCK_COMMENTS:
-            action.save_to_preferences()
-        elif action == Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB:
+        elif action in (Actions.TOGGLE_SNAP_TO_GRID,
+                        Actions.TOGGLE_SHOW_BLOCK_COMMENTS,
+                        Actions.TOGGLE_SHOW_CODE_PREVIEW_TAB):
             action.save_to_preferences()
         elif action == Actions.TOGGLE_SHOW_FLOWGRAPH_COMPLEXITY:
             action.save_to_preferences()
             for page in self.main_window.get_pages():
                 page.get_flow_graph().update()
+        elif action == Actions.TOGGLE_HIDE_VARIABLES:
+            Actions.NOTHING_SELECT()
+            action.save_to_preferences()
         ##################################################
         # Param Modifications
         ##################################################
diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py
index ce5bc4e..e267029 100644
--- a/grc/gui/Actions.py
+++ b/grc/gui/Actions.py
@@ -329,6 +329,12 @@ TOGGLE_HIDE_DISABLED_BLOCKS = ToggleAction(
     stock_id=gtk.STOCK_MISSING_IMAGE,
     keypresses=(gtk.keysyms.d, gtk.gdk.CONTROL_MASK),
 )
+TOGGLE_HIDE_VARIABLES = ToggleAction(
+    label='Hide Variables',
+    tooltip='Hide all variable blocks',
+    preference_name='hide_variables',
+    default=False,
+)
 TOGGLE_AUTO_HIDE_PORT_LABELS = ToggleAction(
     label='Auto-Hide _Port Labels',
     tooltip='Automatically hide port labels',
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py
index b758f3c..c0c4bee 100644
--- a/grc/gui/Bars.py
+++ b/grc/gui/Bars.py
@@ -102,6 +102,7 @@ MENU_BAR_LIST = (
         Actions.SAVE_REPORTS,
         Actions.CLEAR_REPORTS,
         None,
+        Actions.TOGGLE_HIDE_VARIABLES,
         Actions.TOGGLE_HIDE_DISABLED_BLOCKS,
         Actions.TOGGLE_AUTO_HIDE_PORT_LABELS,
         Actions.TOGGLE_SNAP_TO_GRID,
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 9c6bd8f..c3a88e9 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -363,7 +363,8 @@ class FlowGraph(Element, _Flowgraph):
         Returns:
             true if changed, otherwise false.
         """
-        if not self.get_selected_blocks(): return False
+        if not self.get_selected_blocks():
+            return False
         #initialize min and max coordinates
         min_x, min_y = self.get_selected_block().get_coordinate()
         max_x, max_y = self.get_selected_block().get_coordinate()
@@ -428,10 +429,14 @@ class FlowGraph(Element, _Flowgraph):
             window.draw_rectangle(gc, False, x, y, w, h)
         #draw blocks on top of connections
         hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
+        hide_variables = Actions.TOGGLE_HIDE_VARIABLES.get_active()
         blocks = sorted(self.blocks, key=methodcaller('get_enabled'))
+
         for element in chain(self.connections, blocks):
             if hide_disabled_blocks and not element.get_enabled():
                 continue  # skip hidden disabled blocks and connections
+            if hide_variables and (element.is_variable or element.is_import):
+                continue  # skip hidden disabled blocks and connections
             element.draw(gc, window)
         #draw selected blocks on top of selected connections
         for selected_element in self.get_selected_connections() + 
self.get_selected_blocks():
@@ -515,9 +520,16 @@ class FlowGraph(Element, _Flowgraph):
         selected_port = None
         selected = set()
         #check the elements
+        hide_disabled_blocks = Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active()
+        hide_variables = Actions.TOGGLE_HIDE_VARIABLES.get_active()
         for element in reversed(self.get_elements()):
+            if hide_disabled_blocks and not element.get_enabled():
+                continue  # skip hidden disabled blocks and connections
+            if hide_variables and (element.is_variable or element.is_import):
+                continue  # skip hidden disabled blocks and connections
             selected_element = element.what_is_selected(coor, coor_m)
-            if not selected_element: continue
+            if not selected_element:
+                continue
             # hidden disabled connections, blocks and their ports can not be 
selected
             if Actions.TOGGLE_HIDE_DISABLED_BLOCKS.get_active() and (
                 selected_element.is_block and not 
selected_element.get_enabled() or



reply via email to

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