message.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 from rosgraph_msgs.msg import Log
00034 
00035 from python_qt_binding.QtCore import QCoreApplication, QDateTime, QObject
00036 
00037 
00038 class Message(QObject):
00039 
00040     DEBUG = 1
00041     INFO = 2
00042     WARN = 4
00043     ERROR = 8
00044     FATAL = 16
00045 
00046     SEVERITY_LABELS = {
00047         DEBUG: QCoreApplication.translate('Message', 'Debug'),
00048         INFO: QCoreApplication.translate('Message', 'Info'),
00049         WARN: QCoreApplication.translate('Message', 'Warn'),
00050         ERROR: QCoreApplication.translate('Message', 'Error'),
00051         FATAL: QCoreApplication.translate('Message', 'Fatal'),
00052     }
00053 
00054     _next_id = 1
00055 
00056     def __init__(self):
00057         super(Message, self).__init__()
00058         self.id = Message._next_id
00059         Message._next_id += 1
00060 
00061         self.message = None
00062         self.severity = None
00063         self.node = None
00064         self.__stamp = (None, None)
00065         self.topics = []
00066         self.location = None
00067 
00068         self._stamp_compare = None
00069         self._stamp_qdatetime = None
00070 
00071         self._stamp_format = None
00072         self._stamp_string = None
00073 
00074         self.highlighted = True
00075 
00076     def _get_stamp(self):
00077         return self.__stamp
00078 
00079     def _set_stamp(self, stamp):
00080         """
00081         Update the string representation of the timestamp.
00082         :param stamp: a tuple containing seconds and nano seconds
00083         """
00084         assert len(stamp) == 2
00085         self.__stamp = stamp
00086         if None not in self.__stamp:
00087             # shortest string representation to compare stamps
00088             # floats do not provide enough precision
00089             self._stamp_compare = '%08x%08x' % (self.__stamp[0], self.__stamp[1])
00090         else:
00091             self._stamp_compare = None
00092         self._stamp_qdatetime = self._get_stamp_as_qdatetime(self.__stamp)
00093         if self._stamp_format:
00094             s = self._stamp_qdatetime.toString(self._stamp_format)
00095             if 'ZZZ' in s:
00096                 s = s.replace('ZZZ', str(self.__stamp[1]).zfill(9))
00097             self._stamp_string = s
00098 
00099     stamp = property(_get_stamp, _set_stamp)
00100 
00101     def get_stamp_for_compare(self):
00102         return self._stamp_compare
00103 
00104     def get_stamp_as_qdatetime(self):
00105         return self._stamp_qdatetime
00106 
00107     def _get_stamp_as_qdatetime(self, stamp):
00108         if None in self.__stamp:
00109             return None
00110         dt = QDateTime()
00111         dt.setTime_t(stamp[0])
00112         dt.addMSecs(int(float(stamp[1]) / 10**6))
00113         return dt
00114 
00115     def get_stamp_string(self):
00116         return self._stamp_string
00117 
00118     def set_stamp_format(self, format):
00119         self._stamp_format = format
00120         if None not in self.__stamp:
00121             self.stamp = self.__stamp
00122 
00123     def pretty_print(self):
00124         text = self.tr('Node: ') + self.node + '\n'
00125         text += self.tr('Time: ') + self.get_stamp_string() + '\n'
00126         text += self.tr('Severity: ') + Message.SEVERITY_LABELS[self.severity] + '\n'
00127         text += self.tr('Published Topics: ') + ', '.join(self.topics) + '\n'
00128         text += '\n' + self.message + '\n'
00129         text += '\n' + 'Location:'
00130         text += '\n' + self.location + '\n\n'
00131         text += '-' * 100 + '\n\n'
00132 
00133         return text


rqt_console
Author(s): Aaron Blasdel
autogenerated on Wed May 3 2017 02:48:27