33 Defines a raw view: a TopicMessageView that displays the message contents in a tree.
39 from python_qt_binding.QtCore
import Qt
40 from python_qt_binding.QtWidgets
import QApplication, QAbstractItemView, QSizePolicy, QTreeWidget, QTreeWidgetItem, QWidget
41 from .topic_message_view
import TopicMessageView
50 return codecs.utf_8_decode(str(x).encode(),
'ignore')[0]
56 Plugin to view a message in a treeview window
57 The message is loaded into a custum treewidget
62 :param timeline: timeline data object, ''BagTimeline''
63 :param parent: widget that will be added to the ros_gui context, ''QWidget''
65 super(RawView, self).
__init__(timeline, parent, topic)
73 _, msg, t = msg_details
80 TopicMessageView.message_cleared(self)
87 super(MessageTree, self).
__init__(parent)
88 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
89 self.setHeaderHidden(
False)
90 self.setHeaderLabel(
'')
91 self.setSelectionMode(QAbstractItemView.ExtendedSelection)
103 Clears the tree view and displays the new message
104 :param msg: message object to display in the treeview, ''msg''
110 if item.isExpanded():
116 self.setHeaderLabel(msg._type)
129 item.setExpanded(
True)
131 item.setExpanded(
False)
137 if event.modifiers() & Qt.ControlModifier:
139 if key == ord(
'C')
or key == ord(
'c'):
143 elif key == ord(
'A')
or key == ord(
'a'):
150 def get_distance(item, ancestor, distance=0):
151 parent = item.parent()
155 return get_distance(parent, ancestor, distance + 1)
158 if i
in self.selectedItems():
159 text += (
'\t' * (get_distance(i,
None))) + i.text(0) +
'\n'
161 clipboard = QApplication.clipboard()
162 clipboard.setText(text)
165 return item.data(0, Qt.UserRole)[0].replace(
' ',
'')
170 root = self.invisibleRootItem()
178 for i
in range(root.childCount()):
179 child = root.child(i)
186 if hasattr(obj,
'__slots__'):
187 subobjs = [(slot, getattr(obj, slot))
for slot
in obj.__slots__]
188 elif type(obj)
in [list, tuple]:
193 w = int(math.ceil(math.log10(len_obj)))
194 subobjs = [(
'[%*d]' % (w, i), subobj)
for (i, subobj)
in enumerate(obj)]
198 if type(obj)
in [int, long, float]:
199 if type(obj) == float:
200 obj_repr =
'%.6f' % obj
204 if obj_repr[0] ==
'-':
205 label +=
': %s' % obj_repr
207 label +=
': %s' % obj_repr
209 elif type(obj)
in [str, bool, int, long, float, complex, rospy.Time]:
214 if len(obj_repr) >= 50:
215 obj_repr = obj_repr[:50] +
'...'
217 label +=
': ' + obj_repr
218 item = QTreeWidgetItem([label])
221 elif path.find(
'.') == -1
and path.find(
'[') == -1:
222 self.addTopLevelItem(item)
224 parent.addChild(item)
225 item.setData(0, Qt.UserRole, (path, obj_type))
227 for subobj_name, subobj
in subobjs:
232 subpath = subobj_name
233 elif subobj_name.startswith(
'['):
234 subpath =
'%s%s' % (path, subobj_name)
236 subpath =
'%s.%s' % (path, subobj_name)
238 if hasattr(subobj,
'_type'):
239 subobj_type = subobj._type
241 subobj_type = type(subobj).__name__