From 51aed01e4b83ac58c2684346a3945d1d56f6a8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Wed, 14 Feb 2024 10:01:14 +0100 Subject: [PATCH] Allow to autocomplete namespaced topics (#299) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Alejandro Hernández Cordero --- .../src/rqt_py_common/topic_completer.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/rqt_py_common/src/rqt_py_common/topic_completer.py b/rqt_py_common/src/rqt_py_common/topic_completer.py index a6996145..29853861 100644 --- a/rqt_py_common/src/rqt_py_common/topic_completer.py +++ b/rqt_py_common/src/rqt_py_common/topic_completer.py @@ -46,6 +46,24 @@ def __init__(self, parent=None): def splitPath(self, path): # to handle array subscriptions, e.g. /topic/field[1]/subfield[2] # we need to separate array subscriptions by an additional / + + topic_name = path + + if self.topic_list: + # Remove backslash at the end of the topic name + if (topic_name[-1] == '/'): + topic_name = topic_name[:-1] + + for topic, _ in self.topic_list: + if topic in topic_name: + subfield_topic = path.replace(topic, '') + # Remove backslash at the end of the topic name + result = [topic[1:]] + result2 = super(TopicCompleter, self).splitPath( + subfield_topic.replace('[', '/[')) + result = result + result2 + return result + return super(TopicCompleter, self).splitPath(path.replace('[', '/[')) def update_topics(self, node): @@ -55,9 +73,9 @@ def update_topics(self, node): # If no node is passed in then we need to start rclpy and create a node # topic_helpers provides a convenience function for doing this - topic_list = node.get_topic_names_and_types() + self.topic_list = node.get_topic_names_and_types() - for topic_path, topic_types in topic_list: + for topic_path, topic_types in self.topic_list: for topic_type in topic_types: topic_name = topic_path.strip('/') message_class = get_message_class(topic_type)