diff options
author | Josh Blum | 2009-08-15 00:29:11 -0700 |
---|---|---|
committer | Josh Blum | 2009-08-15 00:29:11 -0700 |
commit | 8e1a2c4ac1a43fd989c06856dae27b0c2559c6b3 (patch) | |
tree | a43586c97ca94cf2d9d491daf7e6d421567ac9b1 | |
parent | de213686dfa9608bcf59e2c14a4e326049e9779e (diff) | |
download | gnuradio-8e1a2c4ac1a43fd989c06856dae27b0c2559c6b3.tar.gz gnuradio-8e1a2c4ac1a43fd989c06856dae27b0c2559c6b3.tar.bz2 gnuradio-8e1a2c4ac1a43fd989c06856dae27b0c2559c6b3.zip |
added validation check for msg type ports, added copy method for ports to cleanup nports code
-rw-r--r-- | grc/python/Block.py | 22 | ||||
-rw-r--r-- | grc/python/Port.py | 19 |
2 files changed, 23 insertions, 18 deletions
diff --git a/grc/python/Block.py b/grc/python/Block.py index e2c812d5a..47fe13a3c 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -66,14 +66,12 @@ class Block(_Block): except AssertionError: self.add_error_message('Check "%s" failed.'%check) except: self.add_error_message('Check "%s" did not evaluate.'%check) #adjust nports - for get_ports, get_port, Port in ( - (self.get_sources, self.get_source, self.get_parent().get_parent().Source), - (self.get_sinks, self.get_sink, self.get_parent().get_parent().Sink), + for get_ports, get_port in ( + (self.get_sources, self.get_source), + (self.get_sinks, self.get_sink), ): - #TODO #FIXME we want to filter out msg ports and run the regular code below this line - if any([port.get_type() == 'msg' for port in get_ports()]): continue - #how many ports? - num_ports = len(get_ports()) + #how many streaming (non-message) ports? + num_ports = len(filter(lambda p: p.get_type() != 'msg', get_ports())) #do nothing for 0 ports if not num_ports: continue #get the nports setting @@ -97,11 +95,11 @@ class Block(_Block): #add more ports if nports > num_ports: for key in map(str, range(num_ports, nports)): - n = port0._n - n['key'] = key - port = Port(self, n) - #FIXME should use insert w/index not append - get_ports().append(port) + prev_port = get_port(str(int(key)-1)) + get_ports().insert( + get_ports().index(prev_port)+1, + prev_port.copy(new_key=key), + ) continue def port_controller_modify(self, direction): diff --git a/grc/python/Port.py b/grc/python/Port.py index 0b6d20bbe..daf8f9ca3 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -38,7 +38,7 @@ class Port(_Port): n=n, ) self._nports = n.find('nports') or '' - self._vlen = n.find('vlen') or '1' + self._vlen = n.find('vlen') or '' self._optional = bool(n.find('optional')) def validate(self): @@ -47,6 +47,11 @@ class Port(_Port): except AssertionError: self.add_error_message('Port is not connected.') try: assert self.is_source() or len(self.get_enabled_connections()) <= 1 except AssertionError: self.add_error_message('Port has too many connections.') + if self.get_type() == 'msg': + try: assert not self.get_nports() + except AssertionError: self.add_error_message('A port of type "msg" cannot have "nports" set.') + try: assert self.get_vlen() == 1 + except AssertionError: self.add_error_message('A port of type "msg" must have a "vlen" of 1.') def get_vlen(self): """ @@ -101,12 +106,17 @@ class Port(_Port): }[self.get_type()] except: return _Port.get_color(self) + def copy(self, new_key=None): + n = self._n.copy() + if new_key: n['key'] = new_key + return self.__class__(self.get_parent(), n) + class Source(Port): def __init__(self, block, n): self._n = n #save n if n['type'] == 'msg': n['key'] = 'msg' - else: + if not n.find('key'): n['key'] = str(block._source_count) block._source_count = block._source_count + 1 Port.__init__(self, block, n) @@ -116,10 +126,7 @@ class Sink(Port): def __init__(self, block, n): self._n = n #save n if n['type'] == 'msg': n['key'] = 'msg' - else: + if not n.find('key'): n['key'] = str(block._sink_count) block._sink_count = block._sink_count + 1 Port.__init__(self, block, n) - -#TODO check that nports and vlen is undefined when type is message -#TODO only allow up to one port of type msg |