36 from python_qt_binding.QtCore
import qWarning
38 from .message_tree_model
import MessageTreeModel
39 from .tree_model_completer
import TreeModelCompleter
45 super(TopicCompleter, self).
__init__(parent)
51 return super(TopicCompleter, self).
splitPath(path.replace(
'[',
'/['))
55 topic_list = rospy.get_published_topics()
56 for topic_path, topic_type
in topic_list:
57 topic_name = topic_path.strip(
'/')
58 message_class = roslib.message.get_message_class(topic_type)
59 if message_class
is None:
60 qWarning(
'TopicCompleter.update_topics(): '
61 'could not get message class for topic type "%s" on topic "%s"' %
62 (topic_type, topic_path))
64 message_instance = message_class()
65 self.model().add_message(message_instance, topic_name, topic_type, topic_path)
68 if __name__ ==
'__main__':
70 from python_qt_binding.QtGui
import QApplication, QComboBox, QLineEdit, QMainWindow, QTreeView, QVBoxLayout, QWidget
71 app = QApplication(sys.argv)
74 layout = QVBoxLayout(widget)
79 edit.setCompleter(edit_completer)
82 combo.setEditable(
True)
85 combo.lineEdit().setCompleter(combo_completer)
87 model_tree = QTreeView()
88 model_tree.setModel(combo_completer.model())
89 model_tree.expandAll()
90 for column
in range(combo_completer.model().columnCount()):
91 model_tree.resizeColumnToContents(column)
93 completion_tree = QTreeView()
94 completion_tree.setModel(combo_completer.completionModel())
95 completion_tree.expandAll()
96 for column
in range(combo_completer.completionModel().columnCount()):
97 completion_tree.resizeColumnToContents(column)
99 layout.addWidget(model_tree)
100 layout.addWidget(completion_tree)
101 layout.addWidget(edit)
102 layout.addWidget(combo)
103 layout.setStretchFactor(model_tree, 1)
104 widget.setLayout(layout)
105 mw.setCentralWidget(widget)