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
47 Plugin to view a message in a treeview window 48 The message is loaded into a custum treewidget 53 :param timeline: timeline data object, ''BagTimeline'' 54 :param parent: widget that will be added to the ros_gui context, ''QWidget'' 56 super(RawView, self).
__init__(timeline, parent, topic)
64 _, msg, t = msg_details
68 self.message_tree.set_message(msg)
71 TopicMessageView.message_cleared(self)
72 self.message_tree.set_message(
None)
78 super(MessageTree, self).
__init__(parent)
79 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
80 self.setHeaderHidden(
True)
81 self.setSelectionMode(QAbstractItemView.ExtendedSelection)
93 Clears the tree view and displays the new message 94 :param msg: message object to display in the treeview, ''msg'' 100 if item.isExpanded():
101 self._expanded_paths.add(path)
103 self._expanded_paths.remove(path)
117 item.setExpanded(
True)
119 item.setExpanded(
False)
125 key, ctrl = event.key(), event.modifiers() & Qt.ControlModifier
127 if key == ord(
'C')
or key == ord(
'c'):
131 elif key == ord(
'A')
or key == ord(
'a'):
137 if not i.isSelected():
143 def get_distance(item, ancestor, distance=0):
144 parent = item.parent()
148 return get_distance(parent, ancestor, distance + 1)
151 if i
in self.selectedItems():
152 text += (
'\t' * (get_distance(i,
None))) + i.text(0) +
'\n' 154 clipboard = QApplication.clipboard()
155 clipboard.setText(text)
158 return item.data(0, Qt.UserRole)[0].replace(
' ',
'')
163 root = self.invisibleRootItem()
171 for i
in range(root.childCount()):
172 child = root.child(i)
179 if hasattr(obj,
'__slots__'):
180 subobjs = [(slot, getattr(obj, slot))
for slot
in obj.__slots__]
181 elif type(obj)
in [list, tuple]:
186 w = int(math.ceil(math.log10(len_obj)))
187 subobjs = [(
'[%*d]' % (w, i), subobj)
for (i, subobj)
in enumerate(obj)]
191 if type(obj)
in [int, long, float]:
192 if type(obj) == float:
193 obj_repr =
'%.6f' % obj
197 if obj_repr[0] ==
'-':
198 label +=
': %s' % obj_repr
200 label +=
': %s' % obj_repr
202 elif type(obj)
in [str, bool, int, long, float, complex, rospy.Time]:
204 obj_repr = codecs.utf_8_decode(str(obj),
'ignore')[0]
207 if len(obj_repr) >= 50:
208 obj_repr = obj_repr[:50] +
'...' 210 label +=
': ' + obj_repr
211 item = QTreeWidgetItem([label])
214 elif path.find(
'.') == -1
and path.find(
'[') == -1:
215 self.addTopLevelItem(item)
217 parent.addChild(item)
218 item.setData(0, Qt.UserRole, (path, obj_type))
220 for subobj_name, subobj
in subobjs:
225 subpath = subobj_name
226 elif subobj_name.startswith(
'['):
227 subpath =
'%s%s' % (path, subobj_name)
229 subpath =
'%s.%s' % (path, subobj_name)
231 if hasattr(subobj,
'_type'):
232 subobj_type = subobj._type
234 subobj_type = type(subobj).__name__
def message_cleared(self)
def __init__(self, parent)
def set_message(self, msg)
def traverse(self, root, function)
def get_item_path(self, item)
def _add_msg_object(self, parent, path, name, obj, obj_type)
def on_key_press(self, event)
def _copy_text_to_clipboard(self)
def __init__(self, timeline, parent, topic)
def message_viewed(self, bag, msg_details)