def insert(self, child, parent, index, select=True): "inserts child to the list of parent's children at index; a SlotNode at index is overwritten" assert isinstance(child, Node) # pos is index if parent is None: # XXX check whether this is called at all parent = self._GetItemData(self.GetRootItem()) assert isinstance(parent, Node) # parent is a Node, i.e. Dummy or Button are not in parent.children if parent.children is None or index >= len(parent.children): self.add(child, parent, select=select) return if isinstance(parent.children[index], SlotNode): if not isinstance(child, SlotNode): self.remove(parent.children[index]) Tree.insert(self, child, parent, index) image = child.get_image() child.item = compat.wx_Tree_InsertItemBefore(self, parent.item, index, self._build_label(child), image) self._SetItemData(child.item, child) if self.auto_expand: self.Expand(parent.item) if select: self.select_item(child) if not isinstance(child.widget, edit_sizers.SizerSlot): self.app.check_codegen(child.widget)
def change_node_pos(self, node, new_pos): if new_pos >= self.GetChildrenCount(node.parent.item, False): return index = node.parent.children.index(node) Tree.change_node_pos(self, node, new_pos, index) old_item = node.item image = self.GetItemImage(node.item) self.Freeze() if index >= new_pos: node.item = compat.wx_Tree_InsertItemBefore( self, node.parent.item, new_pos, self._build_label(node), image ) else: node.item = compat.wx_Tree_InsertItemBefore( self, node.parent.item, new_pos+1, self._build_label(node), image ) self._SetItemData(node.item, node) if node.children: for c in node.children: self._append_rec(node, c) self.Expand(node.item) self.Delete(old_item) self.Thaw()
def add2(self, child, parent, index, item=None): "insert an item for child into the list of parent's items; optionally re-use old item" image = self.images.get( child._get_tree_image(), -1) label = child._get_tree_label() if item is None: if index is None: item = child.item = self.AppendItem(parent.item, label, image) else: item = child.item = compat.wx_Tree_InsertItemBefore(self, parent.item, index, label, image) else: # re-use child.item = item self.refresh(child) self._SetItemData(item, child) if self.auto_expand: self.Expand(parent.item) if DEBUG: print("added item", utilities.hx(item), child, child.item) return item