35 from python_qt_binding
import loadUi
36 from python_qt_binding.QtCore
import Qt
37 from python_qt_binding.QtGui
import QIcon
38 from python_qt_binding.QtWidgets
import (QAction, QMenu, QMessageBox,
46 from .messages_tree_view
import MessagesTreeView
47 from rqt_py_common
import rosaction
54 This class is intended to be able to handle msg, srv & action (actionlib). 55 The name of the class is kept to use message, by following the habit of 56 rosmsg (a script that can handle both msg & srv). 59 def __init__(self, mode=rosmsg.MODE_MSG,
61 ui_filename=
'messages.ui'):
63 :param ui_filename: This Qt-based .ui file must have elements that are 64 referred from this class. Otherwise unexpected 65 errors are likely to happen. Best way to avoid that 66 situation when you want to give your own .ui file 67 is to implement all Qt components in 68 rqt_msg/resource/message.ui file. 71 super(MessagesWidget, self).
__init__()
73 ui_file = os.path.join(self._rospack.get_path(pkg_name),
'resource', ui_filename)
74 loadUi(ui_file, self, {
'MessagesTreeView': MessagesTreeView})
75 self.setObjectName(ui_filename)
78 self._add_button.setIcon(QIcon.fromTheme(
'list-add'))
82 self._package_combo.currentIndexChanged[str].connect(self.
_refresh_msgs)
88 if (self.
_mode == rosmsg.MODE_MSG)
or self.
_mode == rosmsg.MODE_SRV:
89 packages = sorted([pkg_tuple[0]
for pkg_tuple
in 91 elif self.
_mode == rosaction.MODE_ACTION:
92 packages = sorted([pkg_tuple[0]
93 for pkg_tuple
in rosaction.iterate_packages(
97 self._package_combo.clear()
99 self._package_combo.setCurrentIndex(0)
102 if package
is None or len(package) == 0:
105 if (self.
_mode == rosmsg.MODE_MSG
or 106 self.
_mode == rosaction.MODE_ACTION):
107 msg_list = rosmsg.list_msgs(package)
108 elif self.
_mode == rosmsg.MODE_SRV:
109 msg_list = rosmsg.list_srvs(package)
112 '_refresh_msgs package={} msg_list={}'.format(package, msg_list))
114 if (self.
_mode == rosmsg.MODE_MSG
or 115 self.
_mode == rosaction.MODE_ACTION):
116 msg_class = roslib.message.get_message_class(msg)
117 elif self.
_mode == rosmsg.MODE_SRV:
118 msg_class = roslib.message.get_service_class(msg)
120 rospy.logdebug(
'_refresh_msgs msg_class={}'.format(msg_class))
122 if msg_class
is not None:
123 self._msgs.append(msg)
125 self.
_msgs = [x.split(
'/')[1]
for x
in self.
_msgs]
127 self._msgs_combo.clear()
128 self._msgs_combo.addItems(self.
_msgs)
131 if self._msgs_combo.count() == 0:
133 msg = (self._package_combo.currentText() +
134 '/' + self._msgs_combo.currentText())
136 rospy.logdebug(
'_add_message msg={}'.format(msg))
138 if (self.
_mode == rosmsg.MODE_MSG
or 139 self.
_mode == rosaction.MODE_ACTION):
140 msg_class = roslib.message.get_message_class(msg)()
141 if self.
_mode == rosmsg.MODE_MSG:
142 text_tree_root =
'Msg Root' 143 elif self.
_mode == rosaction.MODE_ACTION:
144 text_tree_root =
'Action Root' 145 self._messages_tree.model().add_message(msg_class,
146 self.tr(text_tree_root), msg, msg)
148 elif self.
_mode == rosmsg.MODE_SRV:
149 msg_class = roslib.message.get_service_class(msg)()
150 self._messages_tree.model().add_message(msg_class._request_class,
151 self.tr(
'Service Request'),
153 self._messages_tree.model().add_message(msg_class._response_class,
154 self.tr(
'Service Response'),
156 self._messages_tree._recursive_set_editable(
157 self._messages_tree.model().invisibleRootItem(),
False)
160 old_pressEvent=QTreeView.mousePressEvent):
161 if (event.buttons() & Qt.RightButton
and 162 event.modifiers() == Qt.NoModifier):
165 return old_pressEvent(self._messages_tree, event)
176 selected = self._messages_tree.selectedIndexes()
177 if len(selected) == 0:
181 text_action = QAction(self.tr(
'View Text'), menu)
182 menu.addAction(text_action)
183 raw_action = QAction(self.tr(
'View Raw'), menu)
184 menu.addAction(raw_action)
185 remove_action = QAction(self.tr(
'Remove message'), menu)
186 menu.addAction(remove_action)
188 action = menu.exec_(event.globalPos())
190 if action == raw_action
or action == text_action:
191 rospy.logdebug(
'_rightclick_menu selected={}'.format(selected))
192 selected_type = selected[1].data()
194 if selected_type[-2:] ==
'[]':
195 selected_type = selected_type[:-2]
198 if (self.
_mode == rosmsg.MODE_MSG
or 199 self.
_mode == rosaction.MODE_ACTION):
200 browsetext = rosmsg.get_msg_text(selected_type,
201 action == raw_action)
202 elif self.
_mode == rosmsg.MODE_SRV:
203 browsetext = rosmsg.get_srv_text(selected_type,
204 action == raw_action)
208 except rosmsg.ROSMsgException
as e:
209 QMessageBox.warning(self, self.tr(
'Warning'),
210 self.tr(
'The selected item component ' +
211 'does not have text to view.'))
212 if browsetext
is not None:
217 if action == remove_action:
218 self._messages_tree.model().removeRow(selected[0].row())