inspector_window.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2012, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of Willow Garage, Inc. nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 #
00033 # Author: Isaac Saito, Ze'ev Klapow, Austin Hendrix
00034 
00035 from python_qt_binding.QtCore import Signal, Slot
00036 from python_qt_binding.QtWidgets import QPushButton, QTextEdit, QVBoxLayout, QWidget
00037 import rospy
00038 
00039 from .status_snapshot import StatusSnapshot, level_to_text
00040 from .timeline_pane import TimelinePane
00041 import rqt_robot_monitor.util_robot_monitor as util
00042 
00043 from diagnostic_msgs.msg import DiagnosticArray
00044 
00045 
00046 class InspectorWindow(QWidget):
00047     closed = Signal(str)
00048 
00049     def __init__(self, parent, name, status, timeline):
00050         """
00051         :type status: DiagnosticStatus
00052         :param close_callback: When the instance of this class
00053                                (InspectorWindow) terminates, this callback gets
00054                                called.
00055         """
00056         #TODO(Isaac) UI construction that currently is done in this method,
00057         #            needs to be done in .ui file.
00058 
00059         super(InspectorWindow, self).__init__()
00060         self.setWindowTitle(name)
00061         self._name = name
00062 
00063         self.layout_vertical = QVBoxLayout(self)
00064 
00065         self.disp = StatusSnapshot(parent=self)
00066 
00067         self.layout_vertical.addWidget(self.disp, 1)
00068 
00069         if timeline is not None:
00070             self.timeline_pane = TimelinePane(self)
00071             self.timeline_pane.set_timeline(timeline, name)
00072             self.layout_vertical.addWidget(self.timeline_pane, 0)
00073 
00074             self.snapshot = QPushButton("Snapshot")
00075             self.snapshot.clicked.connect(self._take_snapshot)
00076             self.layout_vertical.addWidget(self.snapshot)
00077 
00078         self.snaps = []
00079 
00080         self.setLayout(self.layout_vertical)
00081         # TODO better to be configurable where to appear.
00082         self.resize(400, 600)
00083         self.show()
00084         self.message_updated(status)
00085 
00086     def closeEvent(self, event):
00087         """ called when this window is closed
00088 
00089         Calls close on all snapshots, and emits the closed signal
00090         """
00091         # TODO: are snapshots kept around even after they're closed?
00092         #       this appears to work even if the user closes some snapshots,
00093         #       and they're still left in the internal array
00094         for snap in self.snaps:
00095             snap.close()
00096         self.closed.emit(self._name)
00097 
00098     @Slot(DiagnosticArray)
00099     def message_updated(self, msg):
00100         status = util.get_status_by_name(msg, self._name)
00101         scroll_value = self.disp.verticalScrollBar().value()
00102 
00103         rospy.logdebug('InspectorWin message_updated')
00104 
00105         self.status = status
00106         self.disp.write_status.emit(status)
00107 
00108         if self.disp.verticalScrollBar().maximum() < scroll_value:
00109             scroll_value = self.disp.verticalScrollBar().maximum()
00110         self.disp.verticalScrollBar().setValue(scroll_value)
00111 
00112     def _take_snapshot(self):
00113         snap = StatusSnapshot(status=self.status)
00114         self.snaps.append(snap)


rqt_robot_monitor
Author(s): Austin Hendrix, Isaac Saito, Ze'ev Klapow, Kevin Watts, Josh Faust
autogenerated on Tue Sep 26 2017 02:44:21