message.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 from rosgraph_msgs.msg import Log
34 
35 from python_qt_binding.QtCore import QCoreApplication, QDateTime, QObject
36 
37 
38 class Message(QObject):
39 
40  DEBUG = 1
41  INFO = 2
42  WARN = 4
43  ERROR = 8
44  FATAL = 16
45 
46  SEVERITY_LABELS = {
47  DEBUG: QCoreApplication.translate('Message', 'Debug'),
48  INFO: QCoreApplication.translate('Message', 'Info'),
49  WARN: QCoreApplication.translate('Message', 'Warn'),
50  ERROR: QCoreApplication.translate('Message', 'Error'),
51  FATAL: QCoreApplication.translate('Message', 'Fatal'),
52  }
53 
54  _next_id = 1
55 
56  def __init__(self):
57  super(Message, self).__init__()
58  self.id = Message._next_id
59  Message._next_id += 1
60 
61  self.message = None
62  self.severity = None
63  self.node = None
64  self.__stamp = (None, None)
65  self.topics = []
66  self.location = None
67 
68  self._stamp_compare = None
69  self._stamp_qdatetime = None
70 
71  self._stamp_format = None
72  self._stamp_string = None
73 
74  self.highlighted = True
75 
76  def _get_stamp(self):
77  return self.__stamp
78 
79  def _set_stamp(self, stamp):
80  """
81  Update the string representation of the timestamp.
82  :param stamp: a tuple containing seconds and nano seconds
83  """
84  assert len(stamp) == 2
85  self.__stamp = stamp
86  if None not in self.__stamp:
87  # shortest string representation to compare stamps
88  # floats do not provide enough precision
89  self._stamp_compare = '%08x%08x' % (self.__stamp[0], self.__stamp[1])
90  else:
91  self._stamp_compare = None
93  if self._stamp_format:
94  s = self._stamp_qdatetime.toString(self._stamp_format)
95  if 'ZZZ' in s:
96  s = s.replace('ZZZ', str(self.__stamp[1]).zfill(9))
97  self._stamp_string = s
98 
99  stamp = property(_get_stamp, _set_stamp)
100 
102  return self._stamp_compare
103 
105  return self._stamp_qdatetime
106 
107  def _get_stamp_as_qdatetime(self, stamp):
108  if None in self.__stamp:
109  return None
110  dt = QDateTime()
111  dt.setTime_t(stamp[0])
112  dt.addMSecs(int(float(stamp[1]) / 10**6))
113  return dt
114 
115  def get_stamp_string(self):
116  return self._stamp_string
117 
118  def set_stamp_format(self, format):
119  self._stamp_format = format
120  if None not in self.__stamp:
121  self.stamp = self.__stamp
122 
123  def pretty_print(self):
124  text = self.tr('Node: ') + self.node + '\n'
125  text += self.tr('Time: ') + self.get_stamp_string() + '\n'
126  text += self.tr('Severity: ') + Message.SEVERITY_LABELS[self.severity] + '\n'
127  text += self.tr('Published Topics: ') + ', '.join(self.topics) + '\n'
128  text += '\n' + self.message + '\n'
129  text += '\n' + 'Location:'
130  text += '\n' + self.location + '\n\n'
131  text += '-' * 100 + '\n\n'
132 
133  return text
def _get_stamp_as_qdatetime(self, stamp)
Definition: message.py:107
def get_stamp_as_qdatetime(self)
Definition: message.py:104
def set_stamp_format(self, format)
Definition: message.py:118
def get_stamp_for_compare(self)
Definition: message.py:101
def _set_stamp(self, stamp)
Definition: message.py:79


rqt_console
Author(s): Aaron Blasdel
autogenerated on Fri Mar 17 2023 02:44:51