diff options
-rw-r--r-- | grc/base/FlowGraph.py | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py index 519d399aa8..2281e24dbe 100644 --- a/grc/base/FlowGraph.py +++ b/grc/base/FlowGraph.py @@ -296,9 +296,10 @@ class FlowGraph(Element): #get the blocks source_block = self.get_block(source_block_id) sink_block = self.get_block(sink_block_id) - # update numeric message ports keys - source_key = self.update_message_port_key(source_key, source_block.get_sources()) - sink_key = self.update_message_port_key(sink_key, sink_block.get_sinks()) + # fix old, numeric message ports keys + source_key, sink_key = self.update_old_message_port_keys( + source_key, sink_key, source_block, sink_block + ) #verify the ports if source_key not in source_block.get_source_keys(): # dummy blocks learn their ports here @@ -325,7 +326,8 @@ class FlowGraph(Element): self.rewrite() #global rewrite - def update_message_port_key(self, key, ports): + @staticmethod + def update_old_message_port_keys(source_key, sink_key, source_block, sink_block): """Backward compatibility for message port keys Message ports use their names as key (like in the 'connect' method). @@ -334,18 +336,18 @@ class FlowGraph(Element): respective port. The correct message port is deduced from the integer value of the key (assuming the order has not changed). - :param key: the port key to be updated - :param ports: list of candidate ports - :returns: the updated key or the original one + The connection ends are updated only if both ends translate into a + message port. """ - if key.isdigit(): # don't bother current message port keys - try: - port = ports[int(key)] # get port (assuming liner indexed keys) - if port.get_type() == "message": - return port.get_key() # for message ports get updated key - except IndexError: - pass - return key # do nothing + try: + # get ports using the "old way" (assuming liner indexed keys) + source_port = source_block.get_sources()[int(source_key)] + sink_port = sink_block.get_sinks()[int(sink_key)] + if source_port.get_type() == "message" and sink_port.get_type() == "message": + source_key, sink_key = source_port.get_key(), sink_port.get_key() + except (ValueError, IndexError): + pass + return source_key, sink_key # do nothing def _initialize_dummy_block(block, block_n): @@ -370,4 +372,4 @@ def _dummy_block_add_port(block, key, dir): if port.is_source(): block.get_sources().append(port) else: - block.get_sinks().append(port)
\ No newline at end of file + block.get_sinks().append(port) |