33 Defines a raw view: a TopicMessageView that displays the message contents in a tree.
39 from python_qt_binding.QtCore
import Qt
41 from python_qt_binding.QtGui
import QApplication, QAbstractItemView, QSizePolicy, QTreeWidget, QTreeWidgetItem
43 from python_qt_binding.QtWidgets
import QApplication, QAbstractItemView, QSizePolicy, QTreeWidget, QTreeWidgetItem
44 from .topic_message_view
import TopicMessageView
50 Plugin to view a message in a treeview window
51 The message is loaded into a custum treewidget
55 :param timeline: timeline data object, ''BagTimeline''
56 :param parent: widget that will be added to the ros_gui context, ''QWidget''
58 super(RawView, self).
__init__(timeline, parent, topic)
64 _, msg, t = msg_details
71 TopicMessageView.message_cleared(self)
77 super(MessageTree, self).
__init__(parent)
78 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
79 self.setHeaderHidden(
True)
80 self.setSelectionMode(QAbstractItemView.ExtendedSelection)
92 Clears the tree view and displays the new message
93 :param msg: message object to display in the treeview, ''msg''
115 item.setExpanded(
True)
117 item.setExpanded(
False)
123 key, ctrl = event.key(), event.modifiers() & Qt.ControlModifier
125 if key == ord(
'C')
or key == ord(
'c'):
129 elif key == ord(
'A')
or key == ord(
'a'):
135 if not i.isSelected():
141 def get_distance(item, ancestor, distance=0):
142 parent = item.parent()
146 return get_distance(parent, ancestor, distance + 1)
149 if i
in self.selectedItems():
150 text += (
'\t' * (get_distance(i,
None))) + i.text(0) +
'\n'
152 clipboard = QApplication.clipboard()
153 clipboard.setText(text)
156 return item.data(0, Qt.UserRole)[0].replace(
' ',
'')
161 root = self.invisibleRootItem()
169 for i
in range(root.childCount()):
170 child = root.child(i)
177 if hasattr(obj,
'__slots__'):
178 subobjs = [(slot, getattr(obj, slot))
for slot
in obj.__slots__]
179 elif type(obj)
in [list, tuple]:
184 w = int(math.ceil(math.log10(len_obj)))
185 subobjs = [(
'[%*d]' % (w, i), subobj)
for (i, subobj)
in enumerate(obj)]
189 if type(obj)
in [int, long, float]:
190 if type(obj) == float:
191 obj_repr =
'%.6f' % obj
195 if obj_repr[0] ==
'-':
196 label +=
': %s' % obj_repr
198 label +=
': %s' % obj_repr
200 elif type(obj)
in [str, bool, int, long, float, complex, rospy.Time]:
202 obj_repr = codecs.utf_8_decode(str(obj),
'ignore')[0]
205 if len(obj_repr) >= 50:
206 obj_repr = obj_repr[:50] +
'...'
208 label +=
': ' + obj_repr
209 item = QTreeWidgetItem([label])
212 elif path.find(
'.') == -1
and path.find(
'[') == -1:
213 self.addTopLevelItem(item)
215 parent.addChild(item)
216 item.setData(0, Qt.UserRole, (path, obj_type))
218 for subobj_name, subobj
in subobjs:
223 subpath = subobj_name
224 elif subobj_name.startswith(
'['):
225 subpath =
'%s%s' % (path, subobj_name)
227 subpath =
'%s.%s' % (path, subobj_name)
229 if hasattr(subobj,
'_type'):
230 subobj_type = subobj._type
232 subobj_type = type(subobj).__name__