inspector_window.py
Go to the documentation of this file.
1 # Software License Agreement (BSD License)
2 #
3 # Copyright (c) 2012, Willow Garage, Inc.
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 Willow Garage, Inc. 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 OWNER 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 # Author: Isaac Saito, Ze'ev Klapow, Austin Hendrix
34 
35 from python_qt_binding.QtCore import Qt, Signal, Slot
36 from python_qt_binding.QtWidgets import QPushButton, QTextEdit, QVBoxLayout, QWidget
37 import rospy
38 
39 from rqt_robot_monitor.status_snapshot import StatusSnapshot, level_to_text
40 from rqt_robot_monitor.timeline_pane import TimelinePane
42 
43 from diagnostic_msgs.msg import DiagnosticArray
44 
45 
46 class InspectorWindow(QWidget):
47  closed = Signal(str)
48  _message_updated = Signal(dict)
49  _queue_updated = Signal()
50 
51  def __init__(self, parent, name, timeline):
52  """
53  :param name: Name of inspecting diagnostic status
54  :param timeline: Timeline object from which a status is fetched
55  """
56  #TODO(Isaac) UI construction that currently is done in this method,
57  # needs to be done in .ui file.
58  super(InspectorWindow, self).__init__(parent=parent)
59  self.setWindowTitle(name)
60  self._name = name
61 
62  self.layout_vertical = QVBoxLayout(self)
63 
64  self.disp = StatusSnapshot(parent=self)
65 
66  self.layout_vertical.addWidget(self.disp, 1)
67 
70 
71  self.timeline = timeline
72  self.timeline.message_updated.connect(
73  self.message_updated, Qt.DirectConnection)
74  self.timeline.queue_updated.connect(
75  self.queue_updated, Qt.DirectConnection)
76  self._message_updated.connect(
77  self._signal_message_updated, Qt.QueuedConnection)
78  self._queue_updated.connect(
79  self._signal_queue_updated, Qt.QueuedConnection)
80 
81  self.timeline_pane = TimelinePane(self, self.timeline.paused)
82  self.timeline_pane.pause_changed.connect(self.timeline.set_paused)
83  self.timeline_pane.position_changed.connect(self.timeline.set_position)
84  self.timeline.pause_changed.connect(self.timeline_pane.set_paused)
85  self.timeline.position_changed.connect(self.timeline_pane.set_position)
86  self.layout_vertical.addWidget(self.timeline_pane, 0)
87 
88  self.snapshot = QPushButton("Snapshot")
89  self.snapshot.clicked.connect(self._take_snapshot)
90  self.layout_vertical.addWidget(self.snapshot)
91 
92  self.snaps = []
93 
94  self.setLayout(self.layout_vertical)
95  # TODO better to be configurable where to appear.
96  self.resize(400, 600)
97 
98  def closeEvent(self, event):
99  """ called when this window is closed
100 
101  Calls close on all snapshots, and emits the closed signal
102  """
103  # TODO: are snapshots kept around even after they're closed?
104  # this appears to work even if the user closes some snapshots,
105  # and they're still left in the internal array
106  for snap in self.snaps:
107  snap.close()
108  self.closed.emit(self._name)
109 
110  @Slot()
111  def queue_updated(self):
112  '''
113  This method just calls _signal_queue_updated in 'best effort' manner.
114  This method should be called by signal with DirectConnection.
115  '''
117  return
118  self._queue_updated_processing = True
119  self._queue_updated.emit()
120 
121  @Slot()
123  # update timeline pane
124  # collect worst status levels for each history
125  status = self.timeline.get_all_status_by_name(self._name)
126  if status is not None:
127  self.timeline_pane.set_levels([s.level for s in status])
128  self.timeline_pane.set_position(self.timeline.position)
129  self.timeline_pane.redraw.emit()
130  self._queue_updated_processing = False
131 
132  @Slot(dict)
133  def message_updated(self, status):
134  '''
135  This method just calls _signal_message_updated in 'best effort' manner.
136  This method should be called by signal with DirectConnection.
137  '''
139  return
140  self._message_updated_processing = True
141  self._message_updated.emit(status)
142 
143  @Slot(dict)
144  def _signal_message_updated(self, status):
145  rospy.logdebug('InspectorWin message_updated')
146 
147  try:
148  status = status[self._name]
149  except:
150  return
151 
152  scroll_value = self.disp.verticalScrollBar().value()
153 
154  self.status = status
155  self.disp.write_status.emit(status)
156 
157  if self.disp.verticalScrollBar().maximum() < scroll_value:
158  scroll_value = self.disp.verticalScrollBar().maximum()
159  self.disp.verticalScrollBar().setValue(scroll_value)
160  self._message_updated_processing = False
161 
162  def _take_snapshot(self):
163  snap = StatusSnapshot(status=self.status)
164  self.snaps.append(snap)
def __init__(self, parent, name, timeline)


rqt_robot_monitor
Author(s): Austin Hendrix, Isaac Saito, Ze'ev Klapow, Kevin Watts, Josh Faust
autogenerated on Thu Jun 4 2020 03:46:53