diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-17 17:41:42 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-17 17:41:42 +0200 |
commit | e98dee4f0ec25e3062760f3aeb7642c490e9464a (patch) | |
tree | 8e482beff9b82e80c989b842f8c918b174516972 /grc/python | |
parent | b82987acb6b1e4c368384753c43ad4d2a373659f (diff) |
grc: clean-up Block port counters
Diffstat (limited to 'grc/python')
-rw-r--r-- | grc/python/Block.py | 25 | ||||
-rw-r--r-- | 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 548c991318..303aa85ed5 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 765e1d7423..249d7aed71 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, |