diff options
author | Nicholas McCarthy <namccart@gmail.com> | 2013-07-07 18:08:20 -0400 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2013-07-08 07:19:33 -0700 |
commit | cd99526b5d1c8b1130ac1ba87e21f96c621b1bdc (patch) | |
tree | 12836648bf75868b17b04a2c3ead9c1b6fa2d4c5 /grc/python/Block.py | |
parent | 2dc1b6f2ed0cabd2bccbcc58487e93be4295df84 (diff) |
grc: add bus ports
Bus ports allow ganging together of block input or output ports into
a single display item for connection to other bus ports.
Diffstat (limited to 'grc/python/Block.py')
-rw-r--r-- | grc/python/Block.py | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index 806de46724..d365c43319 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -31,6 +31,8 @@ class Block(_Block, _GUIBlock): ##for make sink to keep track of indexes _sink_count = 0 + + def __init__(self, flow_graph, n): """ Make a new block from nested data. @@ -50,6 +52,8 @@ class Block(_Block, _GUIBlock): self._checks = n.findall('check') self._callbacks = n.findall('callback') self._throttle = n.find('throttle') or '' + self._bus_structure_source = n.find('bus_structure_source') or '' + self._bus_structure_sink = n.find('bus_structure_sink') or '' #build the block _Block.__init__( self, @@ -58,6 +62,21 @@ class Block(_Block, _GUIBlock): ) _GUIBlock.__init__(self) + def get_bus_structure(self, direction): + if direction == 'source': + bus_structure = self._bus_structure_source; + else: + bus_structure = self._bus_structure_sink; + + bus_structure = self.resolve_dependencies(bus_structure); + + if not bus_structure: return '' + try: + clean_bus_structure = self.get_parent().evaluate(bus_structure) + return clean_bus_structure + + except: return '' + def throttle(self): return bool(self._throttle) def validate(self): @@ -84,10 +103,11 @@ class Block(_Block, _GUIBlock): def rectify(ports): #restore integer contiguity after insertion #rectify the port names with the index + self.back_ofthe_bus(ports); for i, port in enumerate(ports): port._key = str(i) port._name = port._n['name'] - if len(ports) > 1: port._name += str(i) + if len(ports) > 1 and not port._type == 'bus': port._name += str(i) def insert_port(get_ports, get_port, key): prev_port = get_port(str(int(key)-1)) @@ -121,14 +141,19 @@ class Block(_Block, _GUIBlock): #remove excess ports and connections if nports < num_ports: for key in reversed(map(str, range(index_first+nports, index_first+num_ports))): - remove_port(get_ports, get_port, key) + remove_port(get_ports, get_port, key); + + continue #add more ports if nports > num_ports: for key in map(str, range(index_first+num_ports, index_first+nports)): insert_port(get_ports, get_port, key) + + continue - + + def port_controller_modify(self, direction): """ Change the port controller. |