diff options
Diffstat (limited to 'grc')
-rw-r--r-- | grc/base/Block.py | 41 | ||||
-rw-r--r-- | grc/gui/Block.py | 8 | ||||
-rw-r--r-- | grc/python/Block.py | 20 | ||||
-rw-r--r-- | grc/python/Port.py | 6 |
4 files changed, 37 insertions, 38 deletions
diff --git a/grc/base/Block.py b/grc/base/Block.py index 867a14f57..d5e104785 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -46,6 +46,9 @@ class TemplateArg(UserDict): def __call__(self): return self._param.get_evaluated() +def _get_keys(lst): return [elem.get_key() for elem in lst] +def _get_elem(lst, key): return lst[_get_keys(lst).index(key)] + class Block(Element): def __init__(self, flow_graph, n): @@ -66,17 +69,17 @@ class Block(Element): self._category = n.find('category') or '' self._block_wrapper_path = n.find('block_wrapper_path') #create the param objects - self._params = odict() + self._params = list() #add the id param - self._params['id'] = self.get_parent().get_parent().Param( + self.get_params().append(self.get_parent().get_parent().Param( self, odict({ 'name': 'ID', 'key': 'id', 'type': 'id', }) - ) - self._params['_enabled'] = self.get_parent().get_parent().Param( + )) + self.get_params().append(self.get_parent().get_parent().Param( self, odict({ 'name': 'Enabled', @@ -85,32 +88,32 @@ class Block(Element): 'value': 'True', 'hide': 'all', }) - ) + )) for param in map(lambda n: self.get_parent().get_parent().Param(self, n), params): key = param.get_key() #test against repeated keys try: assert key not in self.get_param_keys() except AssertionError: raise Exception, 'Key "%s" already exists in params'%key #store the param - self._params[key] = param + self.get_params().append(param) #create the source objects - self._sources = odict() + self._sources = list() for source in map(lambda n: self.get_parent().get_parent().Source(self, n), sources): key = source.get_key() #test against repeated keys try: assert key not in self.get_source_keys() except AssertionError: raise Exception, 'Key "%s" already exists in sources'%key #store the port - self._sources[key] = source + self.get_sources().append(source) #create the sink objects - self._sinks = odict() + self._sinks = list() for sink in map(lambda n: self.get_parent().get_parent().Sink(self, n), sinks): key = sink.get_key() #test against repeated keys try: assert key not in self.get_sink_keys() except AssertionError: raise Exception, 'Key "%s" already exists in sinks'%key #store the port - self._sinks[key] = sink + self.get_sinks().append(sink) #begin the testing self.test() @@ -164,23 +167,23 @@ class Block(Element): ############################################## # Access Params ############################################## - def get_param_keys(self): return self._params.keys() - def get_param(self, key): return self._params[key] - def get_params(self): return self._params.values() + def get_param_keys(self): return _get_keys(self._params) + def get_param(self, key): return _get_elem(self._params, key) + def get_params(self): return self._params ############################################## # Access Sinks ############################################## - def get_sink_keys(self): return self._sinks.keys() - def get_sink(self, key): return self._sinks[key] - def get_sinks(self): return self._sinks.values() + def get_sink_keys(self): return _get_keys(self._sinks) + def get_sink(self, key): return _get_elem(self._sinks, key) + def get_sinks(self): return self._sinks ############################################## # Access Sources ############################################## - def get_source_keys(self): return self._sources.keys() - def get_source(self, key): return self._sources[key] - def get_sources(self): return self._sources.values() + def get_source_keys(self): return _get_keys(self._sources) + def get_source(self, key): return _get_elem(self._sources, key) + def get_sources(self): return self._sources def get_connections(self): return sum([port.get_connections() for port in self.get_ports()], []) diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 0496f0a28..4add3aa19 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -43,7 +43,7 @@ class Block(Element): Add graphics related params to the block. """ #add the position param - self._params['_coordinate'] = self.get_parent().get_parent().Param( + self.get_params().append(self.get_parent().get_parent().Param( self, odict({ 'name': 'GUI Coordinate', @@ -52,8 +52,8 @@ class Block(Element): 'value': '(0, 0)', 'hide': 'all', }) - ) - self._params['_rotation'] = self.get_parent().get_parent().Param( + )) + self.get_params().append(self.get_parent().get_parent().Param( self, odict({ 'name': 'GUI Rotation', @@ -62,7 +62,7 @@ class Block(Element): 'value': '0', 'hide': 'all', }) - ) + )) Element.__init__(self) def get_coordinate(self): diff --git a/grc/python/Block.py b/grc/python/Block.py index 6693f6f86..e2c812d5a 100644 --- a/grc/python/Block.py +++ b/grc/python/Block.py @@ -66,18 +66,18 @@ 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 ports, Port in ( - (self._sources, self.get_parent().get_parent().Source), - (self._sinks, self.get_parent().get_parent().Sink), + 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), ): #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 ports.values()]): continue + if any([port.get_type() == 'msg' for port in get_ports()]): continue #how many ports? - num_ports = len(ports) + num_ports = len(get_ports()) #do nothing for 0 ports if not num_ports: continue #get the nports setting - port0 = ports[str(0)] + port0 = get_port(str(0)) nports = port0.get_nports() #do nothing for no nports if not nports: continue @@ -87,11 +87,12 @@ class Block(_Block): if nports < num_ports: #remove the connections for key in map(str, range(nports, num_ports)): - port = ports[key] + port = get_port(key) for connection in port.get_connections(): self.get_parent().remove_element(connection) #remove the ports - for key in map(str, range(nports, num_ports)): ports.pop(key) + for key in map(str, range(nports, num_ports)): + get_ports().remove(get_port(key)) continue #add more ports if nports > num_ports: @@ -99,7 +100,8 @@ class Block(_Block): n = port0._n n['key'] = key port = Port(self, n) - ports[key] = port + #FIXME should use insert w/index not append + get_ports().append(port) continue def port_controller_modify(self, direction): diff --git a/grc/python/Port.py b/grc/python/Port.py index 14adc0618..0b6d20bbe 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -111,9 +111,6 @@ class Source(Port): block._source_count = block._source_count + 1 Port.__init__(self, block, n) - def __del__(self): - self.get_parent()._source_count = self.get_parent()._source_count - 1 - class Sink(Port): def __init__(self, block, n): @@ -124,8 +121,5 @@ class Sink(Port): block._sink_count = block._sink_count + 1 Port.__init__(self, block, n) - def __del__(self): - self.get_parent()._sink_count = self.get_parent()._sink_count - 1 - #TODO check that nports and vlen is undefined when type is message #TODO only allow up to one port of type msg |