Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00088
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