32 from python_qt_binding.QtGui
import QStandardItem, QStandardItemModel
33 from .data_items
import ReadonlyItem
41 QStandardItemModel.__init__(self, parent)
43 def add_message(self, message_instance, message_name='', message_type='', message_path=''):
44 if message_instance
is None:
47 self, message_instance, message_name, message_type, message_path)
50 items = [self.itemFromIndex(index)
for index
in index_list]
53 while item.parent()
is not None:
55 if item.row()
not in uniqueItems:
56 uniqueItems[item.row()] = item
57 return uniqueItems.values()
60 return (QStandardItem(slot_name), QStandardItem(slot_type_name), QStandardItem(slot_path))
65 item._path = slot_path
66 item._user_data = kwargs.get(
'user_data',
None)
70 if hasattr(slot,
'__slots__')
and hasattr(slot,
'_slot_types'):
71 for child_slot_name, child_slot_type
in zip(slot.__slots__, slot._slot_types):
72 child_slot_path = slot_path +
'/' + child_slot_name
73 child_slot = getattr(slot, child_slot_name)
75 row[0], child_slot, child_slot_name, child_slot_type, child_slot_path, **kwargs)
77 elif type(slot)
in (list, tuple)
and (len(slot) > 0):
78 child_slot_type = slot_type_name[:slot_type_name.find(
'[')]
79 for index, child_slot
in enumerate(slot):
80 child_slot_name =
'[%d]' % index
81 child_slot_path = slot_path + child_slot_name
83 row[0], child_slot, child_slot_name, child_slot_type, child_slot_path, **kwargs)
88 if parent
is self
and kwargs.get(
'top_level_row_number',
None)
is not None:
89 parent.insertRow(kwargs[
'top_level_row_number'], row)
93 return (row, is_leaf_node)
96 NOTE: I (Isaac Saito) suspect that this function might have same/similar
97 functionality with _recursive_create_items.
99 @summary: Evaluate current node and the previous node on the same depth.
100 If the name of both nodes at the same depth is the same,
101 current name is added to the previous node.
102 If not, the current name gets added to the parent node.
103 At the end, this function calls itself recursively going down
105 @param stditem_parent: QStandardItem.
106 @param names_on_branch: List of strings each of which
107 represents the name of the node.
108 Ex. If you have a hierarchy that looks like:
110 /top_node/sub_node/subsub_node
112 then this list would look like:
114 [ top_node, sub_node, subsub_node ]
119 name_curr = names_on_branch.pop(0)
122 row_index_parent = stditem_parent.rowCount() - 1
127 if not stditem_parent.child(row_index_parent) ==
None:
128 stditem_prev = stditem_parent.child(row_index_parent)
129 name_prev = stditem_prev.text()
132 if not name_prev == name_curr:
133 stditem_parent.appendRow(stditem_curr)
134 stditem = stditem_curr
136 stditem = stditem_prev
138 rospy.logdebug(
'add_tree_node 1 name_curr=%s ' +
139 '\n\t\t\t\t\tname_prev=%s row_index_parent=%d', name_curr, name_prev, row_index_parent)
140 if (0 < len(names_on_branch)):
141 MessageTreeModel._build_tree_recursive(stditem, names_on_branch)