Ejemplo n.º 1
0
 def _SelectExpandedPath(self, item, path):
     node = self.GetPyData(item)
     if node.path == path:
         self.SelectItem(node.item)
     elif node.type == 'd':
         for child_item in iter_tree_children(self, item):
             self._SelectExpandedPath(child_item, path)
Ejemplo n.º 2
0
 def _ExpandPaths(self, item, paths):
     expanded = [path[0] for path in paths if path]
     sub_paths = [path[1:] for path in paths if len(path) > 1]
     yield self.ExpandNode(self.GetPyData(item))
     for child_item in iter_tree_children(self, item):
         node = self.GetPyData(child_item)
         name = os.path.basename(node.path) or node.path.strip(os.path.sep)
         if name in expanded:
             yield self._ExpandPaths(child_item, sub_paths)
Ejemplo n.º 3
0
def dirtree_delete(tree, parent_item, text):
    for item in iter_tree_children(tree, parent_item):
        if text == tree.GetItemText(item):
            sel_item = tree.GetNextSibling(item)
            if not sel_item.IsOk():
                sel_item = tree.GetPrevSibling(item)
            if sel_item.IsOk():
                tree.SelectItem(sel_item)
            tree.Delete(item)
            break
Ejemplo n.º 4
0
 def _FindExpandedPaths(self, item, path, expanded):
     if self.IsExpanded(item):
         node = self.GetPyData(item)
         if node.type == 'd':
             subpath = os.path.join(path, os.path.basename(node.path)) if path else node.path
             len_expanded = len(expanded)
             for child_item in iter_tree_children(self, item):
                 self._FindExpandedPaths(child_item, subpath, expanded)
             if len(expanded) == len_expanded:
                 expanded.append(subpath)
     return expanded
Ejemplo n.º 5
0
def dirtree_insert(tree, parent_item, text, image):
    i = 0
    text_lower = text.lower()
    for i, item in enumerate(iter_tree_children(tree, parent_item)):
        item_text = tree.GetItemText(item)
        if item_text == text:
            return item
        if image != IM_FILE and tree.GetItemImage(item) == IM_FILE:
            return tree.InsertItemBefore(parent_item, i, text, image)
        if item_text.lower() > text_lower:
            if not (image == IM_FILE and tree.GetItemImage(item) != IM_FILE):
                return tree.InsertItemBefore(parent_item, i, text, image)
    return tree.AppendItem(parent_item, text, image)
Ejemplo n.º 6
0
def dirtree_insert_node(tree, parent_item, node, image):
    # Optimise common case when expanding directory for the first time
    item = tree.GetLastChild(parent_item)
    if item.IsOk() and tree.GetPyData(item) < node:
        item = tree.AppendItem(parent_item, node.label, image)
        tree.SetItemNode(item, node)
        return item, node

    # Search for the position to insert
    for index, existing_item in enumerate(iter_tree_children(tree, parent_item)):
        existing_node = tree.GetPyData(existing_item)
        if node == existing_node:
            return existing_item, existing_node
        elif node < existing_node:
            item = tree.InsertItemBefore(parent_item, index, node.label, image)
            tree.SetItemNode(item, node)
            return item, node

    item = tree.AppendItem(parent_item, node.label, image)
    tree.SetItemNode(item, node)
    return item, node
Ejemplo n.º 7
0
 def FindExpandedPaths(self):
     expanded = []
     for item in iter_tree_children(self, self.GetRootItem()):
         self._FindExpandedPaths(item, "", expanded)
     return expanded