commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 11/13: grc: clean-up Block port counters


From: git
Subject: [Commit-gnuradio] [gnuradio] 11/13: grc: clean-up Block port counters
Date: Fri, 24 Jul 2015 15:33:49 +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 e98dee4f0ec25e3062760f3aeb7642c490e9464a
Author: Sebastian Koslowski <address@hidden>
Date:   Fri Jul 17 17:41:42 2015 +0200

    grc: clean-up Block port counters
---
 grc/python/Block.py | 25 +++++++++++++------------
 grc/python/Port.py  | 13 +++++--------
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/grc/python/Block.py b/grc/python/Block.py
index 548c991..303aa85 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -17,25 +17,19 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 """
 
-from collections import defaultdict
+import itertools
+import collections
 
 from .. base.Constants import BLOCK_FLAG_NEED_QT_GUI, BLOCK_FLAG_NEED_WX_GUI
 from .. base.Block import Block as _Block
 from .. gui.Block import Block as _GUIBlock
+
 from . FlowGraph import _variable_matcher
 import extract_docs
 
 
 class Block(_Block, _GUIBlock):
 
-    def is_virtual_sink(self): return self.get_key() == 'virtual_sink'
-    def is_virtual_source(self): return self.get_key() == 'virtual_source'
-
-    ##for make source to keep track of indexes
-    _source_count = 0
-    ##for make sink to keep track of indexes
-    _sink_count = 0
-
     def __init__(self, flow_graph, n):
         """
         Make a new block from nested data.
@@ -56,6 +50,7 @@ class Block(_Block, _GUIBlock):
         self._callbacks = n.findall('callback')
         self._bus_structure_source = n.find('bus_structure_source') or ''
         self._bus_structure_sink = n.find('bus_structure_sink') or ''
+        self.port_counters = [itertools.count(), itertools.count()]
         #build the block
         _Block.__init__(
             self,
@@ -138,13 +133,13 @@ class Block(_Block, _GUIBlock):
                     master_port.remove_clone(port)
                     ports.remove(port)
                 # add more cloned ports
-                for i in range(num_ports, nports):
+                for j in range(num_ports, nports):
                     port = master_port.add_clone()
-                    ports.insert(ports.index(master_port) + i, port)
+                    ports.insert(ports.index(master_port) + j, port)
 
             self.back_ofthe_bus(ports)
             # renumber non-message/-msg ports
-            domain_specific_port_index = defaultdict(int)
+            domain_specific_port_index = collections.defaultdict(int)
             for port in filter(lambda p: p.get_key().isdigit(), ports):
                 domain = port.get_domain()
                 port._key = str(domain_specific_port_index[domain])
@@ -212,3 +207,9 @@ class Block(_Block, _GUIBlock):
             if 'self.' in callback: return callback
             return 'self.%s.%s'%(self.get_id(), callback)
         return map(make_callback, self._callbacks)
+
+    def is_virtual_sink(self):
+        return self.get_key() == 'virtual_sink'
+
+    def is_virtual_source(self):
+        return self.get_key() == 'virtual_source'
diff --git a/grc/python/Port.py b/grc/python/Port.py
index 765e1d7..249d7ae 100644
--- a/grc/python/Port.py
+++ b/grc/python/Port.py
@@ -100,14 +100,11 @@ class Port(_Port, _GUIPort):
         elif n['domain'] == GR_MESSAGE_DOMAIN:
             n['key'] = n['name']
             n['type'] = 'message'  # for port color
-        if n['type'] == 'msg': n['key'] = 'msg'
-        if dir == 'source' and not n.find('key'):
-            n['key'] = str(block._source_count)
-            block._source_count += 1
-        if dir == 'sink' and not n.find('key'):
-            n['key'] = str(block._sink_count)
-            block._sink_count += 1
-        #build the port
+        if n['type'] == 'msg':
+            n['key'] = 'msg'
+        if not n.find('key'):
+            n['key'] = str(next(block.port_counters[dir == 'source']))
+        # build the port
         _Port.__init__(
             self,
             block=block,



reply via email to

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