commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 05/18: grc: some clean-up


From: git
Subject: [Commit-gnuradio] [gnuradio] 05/18: grc: some clean-up
Date: Tue, 8 Dec 2015 00:31:22 +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 df4f5820cea5c8786f118bf94adb950afe6b2aab
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Nov 11 18:48:28 2015 +0100

    grc: some clean-up
---
 grc/base/FlowGraph.py      |  8 +++++++-
 grc/python/FlowGraph.py    | 15 ++++++++-------
 grc/python/Generator.py    | 32 +++++++++++++++++---------------
 grc/python/flow_graph.tmpl |  5 ++++-
 4 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py
index 5d600e2..b904a84 100644
--- a/grc/base/FlowGraph.py
+++ b/grc/base/FlowGraph.py
@@ -209,6 +209,12 @@ class FlowGraph(Element):
 
     get_children = get_elements
 
+    def iter_enabled_blocks(self):
+        """
+        Get an iterator of all blocks that are enabled and not bypassed.
+        """
+        return ifilter(methodcaller('get_enabled'), self.iter_blocks())
+
     def get_enabled_blocks(self):
         """
         Get a list of all blocks that are enabled and not bypassed.
@@ -216,7 +222,7 @@ class FlowGraph(Element):
         Returns:
             a list of blocks
         """
-        return filter(methodcaller('get_enabled'), self.iter_blocks())
+        return list(self.iter_enabled_blocks())
 
     def get_bypassed_blocks(self):
         """
diff --git a/grc/python/FlowGraph.py b/grc/python/FlowGraph.py
index 9b55cb6..bedf9cc 100644
--- a/grc/python/FlowGraph.py
+++ b/grc/python/FlowGraph.py
@@ -16,11 +16,12 @@ You should have received a copy of the GNU General Public 
License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
+import re
+from operator import methodcaller
 
-import expr_utils
+from . import expr_utils
 from .. base.FlowGraph import FlowGraph as _FlowGraph
 from .. gui.FlowGraph import FlowGraph as _GUIFlowGraph
-import re
 
 _variable_matcher = re.compile('^(variable\w*)$')
 _parameter_matcher = re.compile('^(parameter)$')
@@ -181,8 +182,8 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
         Returns:
             a sorted list of variable blocks in order of dependency (indep -> 
dep)
         """
-        variables = filter(lambda b: _variable_matcher.match(b.get_key()), 
self.get_enabled_blocks())
-        return expr_utils.sort_objects(variables, lambda v: v.get_id(), lambda 
v: v.get_var_make())
+        variables = filter(lambda b: _variable_matcher.match(b.get_key()), 
self.iter_enabled_blocks())
+        return expr_utils.sort_objects(variables, methodcaller('get_id'), 
methodcaller('get_var_make'))
 
     def get_parameters(self):
         """
@@ -191,17 +192,17 @@ class FlowGraph(_FlowGraph, _GUIFlowGraph):
         Returns:
             a list of paramterized variables
         """
-        parameters = filter(lambda b: _parameter_matcher.match(b.get_key()), 
self.get_enabled_blocks())
+        parameters = filter(lambda b: _parameter_matcher.match(b.get_key()), 
self.iter_enabled_blocks())
         return parameters
 
     def get_monitors(self):
         """
         Get a list of all ControlPort monitors
         """
-        monitors = filter(lambda b: _monitors_searcher.search(b.get_key()), 
self.get_enabled_blocks())
+        monitors = filter(lambda b: _monitors_searcher.search(b.get_key()),
+                          self.iter_enabled_blocks())
         return monitors
 
-
     def get_bussink(self):
         bussink = filter(lambda b: _bussink_searcher.search(b.get_key()), 
self.get_enabled_blocks())
 
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index f064c75..ddd32ca 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -24,6 +24,7 @@ import tempfile
 import shlex
 import codecs
 from distutils.spawn import find_executable
+
 from Cheetah.Template import Template
 
 from .. gui import Messages
@@ -152,11 +153,12 @@ class TopBlockGenerator(object):
         """
         output = list()
 
-        title = self._flow_graph.get_option('title') or 
self._flow_graph.get_option('id').replace('_', ' ').title()
-        imports = self._flow_graph.get_imports()
-        variables = self._flow_graph.get_variables()
-        parameters = self._flow_graph.get_parameters()
-        monitors = self._flow_graph.get_monitors()
+        fg = self._flow_graph
+        title = fg.get_option('title') or fg.get_option('id').replace('_', ' 
').title()
+        imports = fg.get_imports()
+        variables = fg.get_variables()
+        parameters = fg.get_parameters()
+        monitors = fg.get_monitors()
 
         # list of blocks not including variables and imports and parameters 
and disabled
         def _get_block_sort_text(block):
@@ -172,7 +174,7 @@ class TopBlockGenerator(object):
             return code
 
         blocks = expr_utils.sort_objects(
-            filter(lambda b: b.get_enabled() and not b.get_bypassed(), 
self._flow_graph.iter_blocks()),
+            filter(lambda b: b.get_enabled() and not b.get_bypassed(), 
fg.iter_blocks()),
             lambda b: b.get_id(), _get_block_sort_text
         )
         # List of regular blocks (all blocks minus the special ones)
@@ -186,14 +188,14 @@ class TopBlockGenerator(object):
 
         # Filter out virtual sink connections
         cf = lambda c: not (c.is_bus() or c.is_msg() or 
c.get_sink().get_parent().is_virtual_sink())
-        connections = filter(cf, self._flow_graph.get_enabled_connections())
+        connections = filter(cf, fg.get_enabled_connections())
 
-        # Get the virtual blocks and resolve their conenctions
+        # Get the virtual blocks and resolve their connections
         virtual = filter(lambda c: 
c.get_source().get_parent().is_virtual_source(), connections)
         for connection in virtual:
             source = connection.get_source().resolve_virtual_source()
             sink = connection.get_sink()
-            resolved = 
self._flow_graph.get_parent().Connection(flow_graph=self._flow_graph, 
porta=source, portb=sink)
+            resolved = fg.get_parent().Connection(flow_graph=fg, porta=source, 
portb=sink)
             connections.append(resolved)
             # Remove the virtual connection
             connections.remove(connection)
@@ -203,7 +205,7 @@ class TopBlockGenerator(object):
         # that bypass the selected block and remove the existing ones. This 
allows adjacent
         # bypassed blocks to see the newly created connections to downstream 
blocks,
         # allowing them to correctly construct bypass connections.
-        bypassed_blocks = self._flow_graph.get_bypassed_blocks()
+        bypassed_blocks = fg.get_bypassed_blocks()
         for block in bypassed_blocks:
             # Get the upstream connection (off of the sink ports)
             # Use *connections* not get_connections()
@@ -222,7 +224,7 @@ class TopBlockGenerator(object):
                     # Ignore disabled connections
                     continue
                 sink_port = sink.get_sink()
-                connection = 
self._flow_graph.get_parent().Connection(flow_graph=self._flow_graph, 
porta=source_port, portb=sink_port)
+                connection = fg.get_parent().Connection(flow_graph=fg, 
porta=source_port, portb=sink_port)
                 connections.append(connection)
                 # Remove this sink connection
                 connections.remove(sink)
@@ -235,8 +237,8 @@ class TopBlockGenerator(object):
             c.get_source().get_parent().get_id(), 
c.get_sink().get_parent().get_id()
         ))
 
-        connection_templates = 
self._flow_graph.get_parent().get_connection_templates()
-        msgs = filter(lambda c: c.is_msg(), 
self._flow_graph.get_enabled_connections())
+        connection_templates = fg.get_parent().get_connection_templates()
+        msgs = filter(lambda c: c.is_msg(), fg.get_enabled_connections())
         # list of variable names
         var_ids = [var.get_id() for var in parameters + variables]
         # prepend self.
@@ -244,7 +246,7 @@ class TopBlockGenerator(object):
         # list of callbacks
         callbacks = [
             expr_utils.expr_replace(cb, replace_dict)
-            for cb in sum([block.get_callbacks() for block in 
self._flow_graph.get_enabled_blocks()], [])
+            for cb in sum([block.get_callbacks() for block in 
fg.get_enabled_blocks()], [])
         ]
         # map var id to callbacks
         var_id2cbs = dict([
@@ -255,7 +257,7 @@ class TopBlockGenerator(object):
         namespace = {
             'title': title,
             'imports': imports,
-            'flow_graph': self._flow_graph,
+            'flow_graph': fg,
             'variables': variables,
             'parameters': parameters,
             'monitors': monitors,
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 9939006..509c2d0 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -68,7 +68,6 @@ sys.path.append(os.environ.get('GRC_HIER_PATH', 
os.path.expanduser('~/.grc_gnura
 ##$(imp.replace("  # grc-generated hier_block", ""))
 $imp
 #end for
-
 ########################################################
 ##Create Class
 ##  Write the class declaration for a top or hier block.
@@ -82,6 +81,7 @@ $imp
     #import gtk
     #set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
 
+
 class $(class_name)(grc_wxgui.top_block_gui):
 
     def __init__($param_str):
@@ -92,6 +92,7 @@ class $(class_name)(grc_wxgui.top_block_gui):
     #end if
 #elif $generate_options == 'qt_gui'
 
+
 class $(class_name)(gr.top_block, Qt.QWidget):
 
     def __init__($param_str):
@@ -118,6 +119,7 @@ class $(class_name)(gr.top_block, Qt.QWidget):
         self.restoreGeometry(self.settings.value("geometry").toByteArray())
 #elif $generate_options == 'no_gui'
 
+
 class $(class_name)(gr.top_block):
 
     def __init__($param_str):
@@ -126,6 +128,7 @@ class $(class_name)(gr.top_block):
     #set $in_sigs = $flow_graph.get_hier_block_stream_io('in')
     #set $out_sigs = $flow_graph.get_hier_block_stream_io('out')
 
+
 #if $generate_options == 'hb_qt_gui'
 class $(class_name)(gr.hier_block2, Qt.QWidget):
 #else



reply via email to

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