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 splitPath(self, path):
00049
00050
00051 return super(TopicCompleter,self).splitPath(path.replace('[','/['))
00052
00053 def update_topics(self):
00054 self.model().clear()
00055 topic_list = rospy.get_published_topics()
00056 for topic_path, topic_type in topic_list:
00057 topic_name = topic_path.strip('/')
00058 message_class = roslib.message.get_message_class(topic_type)
00059 if message_class is None:
00060 qWarning('TopicCompleter.update_topics(): could not get message class for topic type "%s" on topic "%s"' % (topic_type, topic_path))
00061 continue
00062 message_instance = message_class()
00063 self.model().add_message(message_instance, topic_name, topic_type, topic_path)
00064
00065
00066 if __name__ == '__main__':
00067 import sys
00068 from python_qt_binding.QtGui import QApplication, QComboBox, QLineEdit, QMainWindow, QTreeView, QVBoxLayout, QWidget
00069 app = QApplication(sys.argv)
00070 mw = QMainWindow()
00071 widget = QWidget(mw)
00072 layout = QVBoxLayout(widget)
00073
00074 edit = QLineEdit()
00075 edit_completer = TopicCompleter(edit)
00076
00077 edit.setCompleter(edit_completer)
00078
00079 combo = QComboBox()
00080 combo.setEditable(True)
00081 combo_completer = TopicCompleter(combo)
00082
00083 combo.lineEdit().setCompleter(combo_completer)
00084
00085 model_tree = QTreeView()
00086 model_tree.setModel(combo_completer.model())
00087 model_tree.expandAll()
00088 for column in range(combo_completer.model().columnCount()):
00089 model_tree.resizeColumnToContents(column)
00090
00091 completion_tree = QTreeView()
00092 completion_tree.setModel(combo_completer.completionModel())
00093 completion_tree.expandAll()
00094 for column in range(combo_completer.completionModel().columnCount()):
00095 completion_tree.resizeColumnToContents(column)
00096
00097 layout.addWidget(model_tree)
00098 layout.addWidget(completion_tree)
00099 layout.addWidget(edit)
00100 layout.addWidget(combo)
00101 layout.setStretchFactor(model_tree, 1)
00102 widget.setLayout(layout)
00103 mw.setCentralWidget(widget)
00104
00105 mw.move(300, 0)
00106 mw.resize(800, 900)
00107 mw.show()
00108 app.exec_()