Skip to content

Commit

Permalink
Allow to autocomplete namespaced topics (#299)
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored Feb 14, 2024
1 parent edaf31a commit 51aed01
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions rqt_py_common/src/rqt_py_common/topic_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down

0 comments on commit 51aed01

Please sign in to comment.