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 from __future__ import division
00034 import os
00035
00036 from python_qt_binding import loadUi
00037 from python_qt_binding.QtCore import Signal, Slot
00038 from python_qt_binding.QtGui import QIcon
00039 from python_qt_binding.QtWidgets import QWidget
00040
00041 import roslib
00042 import rosmsg
00043 import rospkg
00044 import rospy
00045
00046 from qt_gui_py_common.worker_thread import WorkerThread
00047 from rqt_py_common.extended_combo_box import ExtendedComboBox
00048 from .publisher_tree_widget import PublisherTreeWidget
00049
00050
00051
00052 class PublisherWidget(QWidget):
00053 add_publisher = Signal(str, str, float, bool)
00054 change_publisher = Signal(int, str, str, str, object)
00055 publish_once = Signal(int)
00056 remove_publisher = Signal(int)
00057 clean_up_publishers = Signal()
00058
00059 def __init__(self, parent=None):
00060 super(PublisherWidget, self).__init__(parent)
00061 self._topic_dict = {}
00062 self._update_thread = WorkerThread(self._update_thread_run, self._update_finished)
00063
00064 self._rospack = rospkg.RosPack()
00065 ui_file = os.path.join(self._rospack.get_path('rqt_publisher'), 'resource', 'Publisher.ui')
00066 loadUi(ui_file, self, {'ExtendedComboBox': ExtendedComboBox, 'PublisherTreeWidget': PublisherTreeWidget})
00067 self.refresh_button.setIcon(QIcon.fromTheme('view-refresh'))
00068 self.refresh_button.clicked.connect(self.refresh_combo_boxes)
00069 self.add_publisher_button.setIcon(QIcon.fromTheme('list-add'))
00070 self.remove_publisher_button.setIcon(QIcon.fromTheme('list-remove'))
00071 self.clear_button.setIcon(QIcon.fromTheme('edit-clear'))
00072
00073 self.refresh_combo_boxes()
00074
00075 self.publisher_tree_widget.model().item_value_changed.connect(self.change_publisher)
00076 self.publisher_tree_widget.remove_publisher.connect(self.remove_publisher)
00077 self.publisher_tree_widget.publish_once.connect(self.publish_once)
00078 self.remove_publisher_button.clicked.connect(self.publisher_tree_widget.remove_selected_publishers)
00079 self.clear_button.clicked.connect(self.clean_up_publishers)
00080
00081 def shutdown_plugin(self):
00082 self._update_thread.kill()
00083
00084 @Slot()
00085 def refresh_combo_boxes(self):
00086 self._update_thread.kill()
00087 self.type_combo_box.setEnabled(False)
00088 self.topic_combo_box.setEnabled(False)
00089 self.type_combo_box.setEditText('updating...')
00090 self.topic_combo_box.setEditText('updating...')
00091 self._update_thread.start()
00092
00093
00094 def _update_thread_run(self):
00095
00096 message_type_names = []
00097 try:
00098
00099 packages = sorted([pkg_tuple[0] for pkg_tuple in rosmsg.iterate_packages(self._rospack, rosmsg.MODE_MSG)])
00100 except:
00101
00102 packages = sorted(rosmsg.list_packages())
00103 for package in packages:
00104 for base_type_str in rosmsg.list_msgs(package, rospack=self._rospack):
00105 message_class = roslib.message.get_message_class(base_type_str)
00106 if message_class is not None:
00107 message_type_names.append(base_type_str)
00108
00109 self.type_combo_box.setItems.emit(sorted(message_type_names))
00110
00111
00112 _, _, topic_types = rospy.get_master().getTopicTypes()
00113 self._topic_dict = dict(topic_types)
00114 self.topic_combo_box.setItems.emit(sorted(self._topic_dict.keys()))
00115
00116 @Slot()
00117 def _update_finished(self):
00118 self.type_combo_box.setEnabled(True)
00119 self.topic_combo_box.setEnabled(True)
00120
00121 @Slot(str)
00122 def on_topic_combo_box_currentIndexChanged(self, topic_name):
00123 if topic_name in self._topic_dict:
00124 self.type_combo_box.setEditText(self._topic_dict[topic_name])
00125
00126 @Slot()
00127 def on_add_publisher_button_clicked(self):
00128 topic_name = str(self.topic_combo_box.currentText())
00129 type_name = str(self.type_combo_box.currentText())
00130 rate = float(self.frequency_combo_box.currentText())
00131 enabled = False
00132 self.add_publisher.emit(topic_name, type_name, rate, enabled)