Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 import roslib
00034 import rospy
00035
00036 from python_qt_binding.QtCore import qWarning
00037
00038 from .message_tree_model import MessageTreeModel
00039 from .tree_model_completer import TreeModelCompleter
00040
00041
00042 class TopicCompleter(TreeModelCompleter):
00043
00044 def __init__(self, parent=None):
00045 super(TopicCompleter, self).__init__(parent)
00046 self.setModel(MessageTreeModel())
00047
00048 def update_topics(self):
00049 self.model().clear()
00050 topic_list = rospy.get_published_topics()
00051 for topic_path, topic_type in topic_list:
00052 topic_name = topic_path.strip('/')
00053 message_class = roslib.message.get_message_class(topic_type)
00054 if message_class is None:
00055 qWarning('TopicCompleter.update_topics(): could not get message class for topic type "%s" on topic "%s"' % (topic_type, topic_path))
00056 continue
00057 message_instance = message_class()
00058 self.model().add_message(message_instance, topic_name, topic_type, topic_path)
00059
00060
00061 if __name__ == '__main__':
00062 import sys
00063 from python_qt_binding.QtGui import QApplication, QComboBox, QLineEdit, QMainWindow, QTreeView, QVBoxLayout, QWidget
00064 app = QApplication(sys.argv)
00065 mw = QMainWindow()
00066 widget = QWidget(mw)
00067 layout = QVBoxLayout(widget)
00068
00069 edit = QLineEdit()
00070 edit_completer = TopicCompleter(edit)
00071
00072 edit.setCompleter(edit_completer)
00073
00074 combo = QComboBox()
00075 combo.setEditable(True)
00076 combo_completer = TopicCompleter(combo)
00077
00078 combo.lineEdit().setCompleter(combo_completer)
00079
00080 model_tree = QTreeView()
00081 model_tree.setModel(combo_completer.model())
00082 model_tree.expandAll()
00083 for column in range(combo_completer.model().columnCount()):
00084 model_tree.resizeColumnToContents(column)
00085
00086 completion_tree = QTreeView()
00087 completion_tree.setModel(combo_completer.completionModel())
00088 completion_tree.expandAll()
00089 for column in range(combo_completer.completionModel().columnCount()):
00090 completion_tree.resizeColumnToContents(column)
00091
00092 layout.addWidget(model_tree)
00093 layout.addWidget(completion_tree)
00094 layout.addWidget(edit)
00095 layout.addWidget(combo)
00096 layout.setStretchFactor(model_tree, 1)
00097 widget.setLayout(layout)
00098 mw.setCentralWidget(widget)
00099
00100 mw.move(300, 0)
00101 mw.resize(800, 900)
00102 mw.show()
00103 app.exec_()