| Home | Trees | Indices | Help |
|---|
|
|
1 # Software License Agreement (BSD License) 2 # 3 # Copyright (c) 2012, Fraunhofer FKIE/US, Alexander Tiderko 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 Fraunhofer 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 from datetime import datetime 33 from python_qt_binding import loadUi 34 from python_qt_binding.QtCore import Signal 35 try: 36 from python_qt_binding.QtGui import QDockWidget 37 except: 38 from python_qt_binding.QtWidgets import QDockWidget 39 import os 40 41 from .rosout_listener import RosoutListener 42 4345 ''' 46 The collect the the warning log messages from rosout and print it in a text 47 browser. 48 ''' 49 50 added_signal = Signal(int, int, int, int) 51 ''' 52 added_signal will be emitted on adding a new log entry. The parameter contains 53 the current count of messages (INFO, WARN, ERROR, FATAL) 54 ''' 55 56 cleared_signal = Signal() 5716759 ''' 60 Creates the window, connects the signals and init the class. 61 ''' 62 QDockWidget.__init__(self, parent) 63 self._log_info_count = 0 64 self._log_warn_count = 0 65 self._log_err_count = 0 66 self._log_fatal_count = 0 67 # load the UI file 68 log_dock_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'LogDockWidget.ui') 69 loadUi(log_dock_file, self) 70 self.hide() 71 # connect to the button signals 72 self.clearCloseButton.clicked.connect(self._on_log_clear_close_clicked) 73 self.closeButton.clicked.connect(self.hide) 74 # initialize the listener to the rosout topic 75 self._rosout_listener = RosoutListener() 76 self._rosout_listener.roswarn_signal.connect(self._on_roslog_warn) 77 self._rosout_listener.roserr_signal.connect(self._on_roslog_err) 78 self._rosout_listener.rosfatal_signal.connect(self._on_roslog_fatal) 79 self._rosout_listener.registerByROS()8082 ''' 83 Returns the count all current viewed log messages. 84 ''' 85 return self._log_info_count + self._log_warn_count + self._log_err_count + self._log_fatal_count8688 ''' 89 Removes all log messages and emit the `cleared_signal`. 90 ''' 91 self._log_info_count = 0 92 self._log_warn_count = 0 93 self._log_err_count = 0 94 self._log_fatal_count = 0 95 self.textBrowser.clear() 96 self.infoLabel.setText('') 97 self.cleared_signal.emit()98100 ''' 101 Unregister the listener thread from the `/rosout` topic. This method must be 102 called at the exit! 103 ''' 104 self._rosout_listener.stop()105107 self._log_info_count += 1 108 text = ('<pre style="padding:10px;"><dt><font color="#000000">' 109 '<b>[INFO]</b> %s (%s:%s:%s):' 110 '<br>%s</font></dt></pre>' % (self._formated_ts(msg.header.stamp), 111 msg.file, msg.function, msg.line, 112 msg.msg)) 113 self.textBrowser.append(text) 114 self._update_info_label()115117 self._log_warn_count += 1 118 text = ('<pre style="padding:10px;"><dt><font color="#FE9A2E">' 119 '<b>[WARN]</b> %s (%s:%s:%s):' 120 '<br>%s</font></dt></pre>' % (self._formated_ts(msg.header.stamp), 121 msg.file, msg.function, msg.line, 122 msg.msg)) 123 self.textBrowser.append(text) 124 self._update_info_label()125127 self._log_err_count += 1 128 text = ('<pre style="padding:10px;"><dt><font color="#DF0101">' 129 '<b>[ERROR]</b> %s (%s:%s:%s):' 130 '<br>%s</font></dt></pre>' % (self._formated_ts(msg.header.stamp), 131 msg.file, msg.function, msg.line, 132 msg.msg)) 133 self.textBrowser.append(text) 134 self._update_info_label()135137 self._log_fatal_count += 1 138 text = ('<pre style="padding:10px;"><dt><font color="#610B0B">' 139 '<b>[FATAL]</b> %s (%s:%s:%s):' 140 '<br>%s</font></dt></pre>' % (self._formated_ts(msg.header.stamp), 141 msg.file, msg.function, msg.line, 142 msg.msg)) 143 self.textBrowser.append(text) 144 self._update_info_label()145 149151 info_text = '' 152 if self._log_info_count > 0: 153 info_text = '%s INFO: %d ' % (info_text, self._log_info_count) 154 if self._log_warn_count > 0: 155 info_text = '%s WARN: %d ' % (info_text, self._log_warn_count) 156 if self._log_err_count > 0: 157 info_text = '%s ERROR: %d ' % (info_text, self._log_err_count) 158 if self._log_fatal_count > 0: 159 info_text = '%s FATAL: %d' % (info_text, self._log_fatal_count) 160 self.infoLabel.setText(info_text) 161 self.added_signal.emit(self._log_info_count, self._log_warn_count, 162 self._log_err_count, self._log_fatal_count)163
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Thu Apr 27 02:41:59 2017 | http://epydoc.sourceforge.net |