36 from cStringIO
import StringIO
38 from io
import StringIO
43 from diagnostic_msgs.msg
import DiagnosticArray, DiagnosticStatus
44 from python_qt_binding
import loadUi
45 from python_qt_binding.QtGui
import QIcon
46 from python_qt_binding.QtWidgets
import QTreeWidgetItem, QWidget
47 from python_qt_binding.QtCore
import Qt, QTimer, QObject
64 super(RuntimeMonitorWidget, self).
__init__()
66 ui_file = os.path.join(rp.get_path(
'rqt_runtime_monitor'),
'resource',
'runtime_monitor_widget.ui')
68 self.setObjectName(
'RuntimeMonitorWidget')
74 self.
_ok_icon = QIcon.fromTheme(
'dialog-information')
76 self.
_stale_node = QTreeWidgetItem(self.tree_widget.invisibleRootItem(), [
'Stale (0)'])
80 self.
_error_node = QTreeWidgetItem(self.tree_widget.invisibleRootItem(), [
'Errors (0)'])
84 self.
_warning_node = QTreeWidgetItem(self.tree_widget.invisibleRootItem(), [
'Warnings (0)'])
88 self.
_ok_node = QTreeWidgetItem(self.tree_widget.invisibleRootItem(), [
'Ok (0)'])
89 self._ok_node.setIcon(0, self.
_ok_icon)
90 self.tree_widget.addTopLevelItem(self.
_ok_node)
101 self._timer.timeout.connect(self.
_on_timer)
102 self._timer.start(1000)
106 self._msg_timer.start(100)
116 Unregisters subscriber and stops timers 118 self._msg_timer.stop()
121 if rospy.is_shutdown():
125 self._subscriber.unregister()
130 Changes diagnostics topic name. Must be of type diagnostic_msgs/DiagnosticArray 137 self._subscriber.unregister()
143 Removes all values from monitor display, resets buffers 150 for index
in range(self._stale_node.childCount()):
151 self._stale_node.removeChild(self._stale_node.child(index))
152 for index
in range(self._error_node.childCount()):
153 self._error_node.removeChild(self._error_node.child(index))
154 for index
in range(self._warning_node.childCount()):
155 self._warning_node.removeChild(self._warning_node.child(index))
156 for index
in range(self._ok_node.childCount()):
157 self._ok_node.removeChild(self._ok_node.child(index))
163 self._messages.append(message)
172 for message
in messages:
173 for status
in message.status:
177 if item.tree_node.isSelected():
179 if (item.status.level == DiagnosticStatus.ERROR
and status.level != DiagnosticStatus.ERROR):
184 if (status.level == DiagnosticStatus.ERROR):
195 change_parent =
False 196 if (item.status.level != status.level):
199 if (item.status.level == DiagnosticStatus.OK):
200 self._ok_node.removeChild(item.tree_node)
201 elif (item.status.level == DiagnosticStatus.WARN):
202 self._warning_node.removeChild(item.tree_node)
203 elif (item.status.level == -1)
or (item.status.level == DiagnosticStatus.STALE):
204 self._stale_node.removeChild(item.tree_node)
206 self._error_node.removeChild(item.tree_node)
208 if (status.level == DiagnosticStatus.OK):
210 elif (status.level == DiagnosticStatus.WARN):
212 elif (status.level == -1)
or (status.level == DiagnosticStatus.STALE):
217 item.tree_node.setText(0, status.name +
": " + status.message)
218 item.tree_node.setData(0, Qt.UserRole, item)
219 parent_node.addChild(item.tree_node)
222 if (status.level > 1
or status.level == -1):
223 parent_node.setExpanded(
True)
225 parent_node.sortChildren(0, Qt.AscendingOrder)
228 self.tree_widget.setCurrentItem(item.tree_node)
231 item.tree_node.setText(0, status.name +
": " + status.message)
241 if (status.level == DiagnosticStatus.OK):
243 elif (status.level == DiagnosticStatus.WARN):
245 elif (status.level == -1)
or (status.level == DiagnosticStatus.STALE):
250 item =
TreeItem(status, QTreeWidgetItem(parent_node, [status.name +
": " + status.message]))
251 item.tree_node.setData(0, Qt.UserRole, item)
252 parent_node.addChild(item.tree_node)
256 parent_node.sortChildren(0, Qt.AscendingOrder)
259 item.tree_node.setSelected(
True)
261 if (expand_if_error
and (status.level > 1
or status.level == -1)):
262 parent_node.setExpanded(
True)
269 item = node.data(0, Qt.UserRole)
273 scroll_value = self.html_browser.verticalScrollBar().value()
278 s.write(
"<html><body>")
279 s.write(
"<b>Component</b>: %s<br>\n" % (status.name))
280 s.write(
"<b>Message</b>: %s<br>\n" % (status.message))
281 s.write(
"<b>Hardware ID</b>: %s<br><br>\n\n" % (status.hardware_id))
283 s.write(
'<table border="1" cellpadding="2" cellspacing="0">')
284 for value
in status.values:
285 value.value = value.value.replace(
"\n",
"<br>")
286 s.write(
"<tr><td><b>%s</b></td> <td>%s</td></tr>\n" % (value.key, value.value))
288 s.write(
"</table></body></html>")
290 self.html_browser.setHtml(s.getvalue())
291 if self.html_browser.verticalScrollBar().maximum() < scroll_value:
292 scroll_value = self.html_browser.verticalScrollBar().maximum()
293 self.html_browser.verticalScrollBar().setValue(scroll_value)
296 current_item = self.tree_widget.selectedItems()
302 if key == Qt.Key_Delete:
303 nodes = self.tree_widget.selectedItems()
305 item = nodes[0].data(0, Qt.UserRole)
306 if (item.status.level == 0):
307 self._ok_node.removeChild(item.tree_node)
308 elif (item.status.level == 1):
309 self._warning_node.removeChild(item.tree_node)
310 elif (item.status.level == -1)
or (item.status.level == DiagnosticStatus.STALE):
311 self._stale_node.removeChild(item.tree_node)
313 self._error_node.removeChild(item.tree_node)
325 for name, item
in self._name_to_item.items():
326 node = item.tree_node
330 selected = self.tree_widget.selectedItems()
331 if selected != []
and selected[0] == node:
334 new_status = copy.deepcopy(item.status)
335 new_status.level = -1
345 self._stale_node.setText(0,
"Stale (%s)" % (self._stale_node.childCount()))
346 self._error_node.setText(0,
"Errors (%s)" % (self._error_node.childCount()))
347 self._warning_node.setText(0,
"Warnings (%s)" % (self._warning_node.childCount()))
348 self._ok_node.setText(0,
"Ok (%s)" % (self._ok_node.childCount()))