publisher_widget.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright (c) 2011, Dorian Scholz, TU Darmstadt
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 #
10 # * Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # * Redistributions in binary form must reproduce the above
13 # copyright notice, this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided
15 # with the distribution.
16 # * Neither the name of the TU Darmstadt nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 # COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
32 
33 from __future__ import division
34 import os
35 
36 from python_qt_binding import loadUi
37 from python_qt_binding.QtCore import Signal, Slot
38 from python_qt_binding.QtGui import QIcon
39 from python_qt_binding.QtWidgets import QWidget
40 
41 import roslib
42 import rosmsg
43 import rospkg
44 import rospy
45 
46 from qt_gui_py_common.worker_thread import WorkerThread
47 from rqt_py_common.extended_combo_box import ExtendedComboBox
48 from .publisher_tree_widget import PublisherTreeWidget
49 
50 
51 # main class inherits from the ui window class
52 class PublisherWidget(QWidget):
53  add_publisher = Signal(str, str, float, bool)
54  change_publisher = Signal(int, str, str, str, object)
55  publish_once = Signal(int)
56  remove_publisher = Signal(int)
57  clean_up_publishers = Signal()
58 
59  def __init__(self, parent=None):
60  super(PublisherWidget, self).__init__(parent)
61  self._topic_dict = {}
63 
64  self._rospack = rospkg.RosPack()
65  ui_file = os.path.join(self._rospack.get_path('rqt_publisher'), 'resource', 'Publisher.ui')
66  loadUi(ui_file, self,
67  {'ExtendedComboBox': ExtendedComboBox, 'PublisherTreeWidget': PublisherTreeWidget})
68  self.refresh_button.setIcon(QIcon.fromTheme('view-refresh'))
69  self.refresh_button.clicked.connect(self.refresh_combo_boxes)
70  self.add_publisher_button.setIcon(QIcon.fromTheme('list-add'))
71  self.remove_publisher_button.setIcon(QIcon.fromTheme('list-remove'))
72  self.clear_button.setIcon(QIcon.fromTheme('edit-clear'))
73 
74  self.refresh_combo_boxes()
75 
76  self.publisher_tree_widget.model().item_value_changed.connect(self.change_publisher)
77  self.publisher_tree_widget.remove_publisher.connect(self.remove_publisher)
78  self.publisher_tree_widget.publish_once.connect(self.publish_once)
79  self.remove_publisher_button.clicked.connect(
80  self.publisher_tree_widget.remove_selected_publishers)
81  self.clear_button.clicked.connect(self.clean_up_publishers)
82 
83  def shutdown_plugin(self):
84  self._update_thread.kill()
85 
86  @Slot()
88  self._update_thread.kill()
89  self.type_combo_box.setEnabled(False)
90  self.topic_combo_box.setEnabled(False)
91  self.type_combo_box.setEditText('updating...')
92  self.topic_combo_box.setEditText('updating...')
93  self._update_thread.start()
94 
95  # this runs in a non-gui thread, so don't access widgets here directly
96  def _update_thread_run(self):
97  # update type_combo_box
98  message_type_names = []
99  try:
100  # this only works on fuerte and up
101  packages = sorted(
102  [pkg_tuple[0] for pkg_tuple in
103  rosmsg.iterate_packages(self._rospack, rosmsg.MODE_MSG)])
104  except:
105  # this works up to electric
106  packages = sorted(rosmsg.list_packages())
107  for package in packages:
108  for base_type_str in rosmsg.list_msgs(package, rospack=self._rospack):
109  message_class = roslib.message.get_message_class(base_type_str)
110  if message_class is not None:
111  message_type_names.append(base_type_str)
112 
113  self.type_combo_box.setItems.emit(sorted(message_type_names))
114 
115  # update topic_combo_box
116  _, _, topic_types = rospy.get_master().getTopicTypes()
117  self._topic_dict = dict(topic_types)
118  self.topic_combo_box.setItems.emit(sorted(self._topic_dict.keys()))
119 
120  @Slot()
121  def _update_finished(self):
122  self.type_combo_box.setEnabled(True)
123  self.topic_combo_box.setEnabled(True)
124 
125  @Slot(str)
127  if topic_name in self._topic_dict:
128  self.type_combo_box.setEditText(self._topic_dict[topic_name])
129 
130  @Slot()
132  topic_name = str(self.topic_combo_box.currentText())
133  type_name = str(self.type_combo_box.currentText())
134  rate = float(self.frequency_combo_box.currentText())
135  enabled = False
136  self.add_publisher.emit(topic_name, type_name, rate, enabled)
rqt_publisher.publisher_widget.PublisherWidget.on_add_publisher_button_clicked
def on_add_publisher_button_clicked(self)
Definition: publisher_widget.py:131
qt_gui_py_common::worker_thread::WorkerThread
rqt_publisher.publisher_widget.PublisherWidget
Definition: publisher_widget.py:52
rqt_publisher.publisher_widget.PublisherWidget.__init__
def __init__(self, parent=None)
Definition: publisher_widget.py:59
rqt_publisher.publisher_widget.PublisherWidget.on_topic_combo_box_currentIndexChanged
def on_topic_combo_box_currentIndexChanged(self, topic_name)
Definition: publisher_widget.py:126
rqt_publisher.publisher_widget.PublisherWidget._topic_dict
_topic_dict
Definition: publisher_widget.py:61
rqt_publisher.publisher_widget.PublisherWidget._update_thread_run
def _update_thread_run(self)
Definition: publisher_widget.py:96
rqt_publisher.publisher_widget.PublisherWidget._rospack
_rospack
Definition: publisher_widget.py:64
rqt_py_common::extended_combo_box
rqt_publisher.publisher_widget.PublisherWidget.refresh_combo_boxes
def refresh_combo_boxes(self)
Definition: publisher_widget.py:87
rqt_publisher.publisher_widget.PublisherWidget.remove_publisher
remove_publisher
Definition: publisher_widget.py:56
qt_gui_py_common::worker_thread
rqt_publisher.publisher_widget.PublisherWidget.clean_up_publishers
clean_up_publishers
Definition: publisher_widget.py:57
rqt_publisher.publisher_widget.PublisherWidget._update_thread
_update_thread
Definition: publisher_widget.py:62
rqt_publisher.publisher_widget.PublisherWidget.change_publisher
change_publisher
Definition: publisher_widget.py:54
rqt_publisher.publisher_widget.PublisherWidget._update_finished
def _update_finished(self)
Definition: publisher_widget.py:121
rqt_publisher.publisher_widget.PublisherWidget.publish_once
publish_once
Definition: publisher_widget.py:55
rqt_publisher.publisher_widget.PublisherWidget.shutdown_plugin
def shutdown_plugin(self)
Definition: publisher_widget.py:83
rqt_publisher.publisher_widget.PublisherWidget.add_publisher
add_publisher
Definition: publisher_widget.py:53


rqt_publisher
Author(s): Dirk Thomas, Dorian Scholz, Michael Carroll
autogenerated on Thu Oct 5 2023 02:39:55