33 from python_qt_binding.QtCore
import QAbstractTableModel, QModelIndex, Qt, qWarning
34 from python_qt_binding.QtGui
import QBrush, QIcon
36 from .message
import Message
37 from .message_list
import MessageList
43 columns = [
'message',
'severity',
'node',
'stamp',
'topics',
'location']
46 Message.DEBUG: QBrush(Qt.darkCyan),
47 Message.INFO: QBrush(Qt.darkBlue),
48 Message.WARN: QBrush(Qt.darkYellow),
49 Message.ERROR: QBrush(Qt.darkRed),
50 Message.FATAL: QBrush(Qt.red),
54 super(MessageDataModel, self).
__init__()
67 return len(MessageDataModel.columns) + 1
69 def data(self, index, role=None):
72 if index.row() >= 0
and index.row() < len(self.
_messages):
74 if index.column() == 0:
75 if role == Qt.DisplayRole:
77 elif index.column() > 0
and index.column() < len(MessageDataModel.columns) + 1:
78 column = MessageDataModel.columns[index.column() - 1]
79 if role == Qt.DisplayRole
or role == Qt.UserRole:
81 if role != Qt.UserRole:
82 data = msg.get_stamp_string()
84 data = msg.get_stamp_for_compare()
86 data = getattr(msg, column)
88 if role == Qt.DisplayRole
and column ==
'severity':
89 data = Message.SEVERITY_LABELS[data]
91 if column ==
'topics':
92 data =
', '.join(data)
94 if role == Qt.UserRole:
98 data = str(data) +
' %08x' % index.row()
102 if role == Qt.DecorationRole
and column ==
'message':
103 if msg.severity
in [Message.DEBUG, Message.INFO]:
105 elif msg.severity
in [Message.WARN]:
107 elif msg.severity
in [Message.ERROR, Message.FATAL]:
111 if role == Qt.ForegroundRole
and column ==
'severity':
112 assert msg.severity
in MessageDataModel.severity_colors, \
113 'Unknown severity type: %s' % msg.severity
114 return MessageDataModel.severity_colors[msg.severity]
116 if role == Qt.ToolTipRole
and column !=
'severity':
117 if column ==
'stamp':
118 data = msg.get_stamp_string()
119 elif column ==
'topics':
120 data =
', '.join(msg.topics)
122 data = getattr(msg, column)
124 return '<font>' + data +
'<br/><br/>' + \
125 self.tr(
'Right click for menu.') +
'</font>' 129 role = Qt.DisplayRole
130 if orientation == Qt.Horizontal:
131 if role == Qt.DisplayRole:
135 return MessageDataModel.columns[section - 1].capitalize()
136 if role == Qt.ToolTipRole:
138 return self.tr(
'Sort the rows by serial number in descendig order')
141 'Sorting the table by a column other then the serial number slows down the ' 142 'interaction especially when recording high frequency data')
155 self.beginRemoveRows(QModelIndex(), limit, len(self.
_messages) - 1)
167 self.beginInsertRows(QModelIndex(), 0, len(msgs) - 1)
168 self._messages.extend(msgs)
173 :param rowlist: list of row indexes, ''list(int)'' 174 :returns: True if the indexes were removed successfully, ''bool'' 176 if len(rowlist) == 0:
179 self.beginRemoveRows(QModelIndex(), 0, len(self.
_messages))
185 rowlist = list(set(rowlist))
186 rowlist.sort(reverse=
True)
187 dellist = [rowlist[0]]
188 for row
in rowlist[1:]:
189 if dellist[-1] - 1 > row:
191 self.beginRemoveRows(QModelIndex(), dellist[-1], dellist[0])
192 del self.
_messages[dellist[-1]:dellist[0] + 1]
200 self.beginRemoveRows(QModelIndex(), dellist[-1], dellist[0])
201 del self.
_messages[dellist[-1]:dellist[0] + 1]
209 Returns an easily readable block of text for the currently selected rows 210 :param rowlist: list of row indexes, ''list(int)'' 211 :returns: the text from those indexes, ''str'' 214 if len(rowlist) != 0:
216 rowlist = list(set(rowlist))
218 text += self.
_messages[row].pretty_print()
223 :param rowlist: a list of row indexes, ''list'' 224 :returns: a tuple of min and max times in a rowlist in 225 '(unix timestamp).(fraction of second)' format, ''tuple(str,str)'' 230 item = self.
_messages[row].time_as_datestamp()
231 if float(item) > float(max_):
233 if float(item) < float(min_):
240 nodes.add(message.node)
246 severities.add(message.severity)
252 for topic
in message.topics:
257 return Message.SEVERITY_LABELS
261 :param start_time: time to start in timestamp form (including decimal 262 fractions of a second is acceptable, ''unixtimestamp'' 263 :param end_time: time to end in timestamp form (including decimal 264 fractions of a second is acceptable, ''unixtimestamp'' (Optional) 265 :returns: list of messages in the time range ''list[message]'' 269 msg_time = message.stamp[0] + float(message.stamp[1]) / 10**9
270 if msg_time >= float(start_time)
and (end_time
is None or msg_time <= float(end_time)):
def get_selected_text(self, rowlist)
def get_message_between(self, start_time, end_time=None)
def rowCount(self, parent=None)
def data(self, index, role=None)
def get_severity_dict(self)
def get_unique_topics(self)
def remove_rows(self, rowlist)
def _enforce_message_limit(self, limit)
def set_message_limit(self, new_limit)
def headerData(self, section, orientation, role=None)
def get_unique_nodes(self)
def get_time_range(self, rowlist)
def insert_rows(self, msgs)
def get_message_limit(self)
def get_unique_severities(self)
def columnCount(self, parent=None)