def constructFromList(lst)
a nested list of Tree objects
Returns a list consisting of the nodes at the base of each tree. Trees are constructed "bottom-up", so all parent nodes for a particular node are guaranteed to exist when "addChild" is run.
class Tree(object)
A simple implementation of an ordered tree
def __init__(self, children=None)
def addChildrenFromList(self, children)
Add children to this node.
def addChild(self, node)
Add a child to this node.
def register(self, parent)
Called after a node has been added to a parent.
def index(self)
Return the index of this node in the parent child list, based on object identity.
def remove(self)
Remove this node from its parent. Returns the index this node had in the parent child list.
def clear(self)
Clear all the children of this node. Return a list of the removed children.
def replace(self, *nodes)
Replace this node with a sequence of other nodes. This is equivalent to deleting this node from the child list, and then inserting the specified sequence in its place.
def reparent(self, node)
Inserts a node between the current node and its parent. Returns the specified parent node.
def isDescendantOf(self, node)
Returns true if the specified node lies on the path to the root from this node.
def siblings(self)
Generator yielding all siblings of this node, including this node itself.
def pathToRoot(self)
Generator yielding all objects on the path from this node to the root of the tree, including this node itself.
def pathFromRoot(self)
Generator yielding all nodes on the path to this node from the root of the tree, including this node itself.
def getRoot(self)
Return the topmost node in the tree.
def preOrder(self)
Return a list of subnodes in PreOrder.
def postOrder(self)
Return a list of the subnodes in PostOrder.
def findChild(self, *func, **kwargs)
Find the first child matching all specified selectors in a pre-order traversal of this node's subnodes. Return None if no matching object is found.
def findParent(self, *func, **kwargs)
Find the first node matching func in a traversal to the root of the tree. Return None if no matching object is found.
def findForwards(self, *func, **kwargs)
Search forwards in a preOrder traversal of the whole tree (not this node's subnodes). Return None if object not found.
def findBackwards(self, *func, **kwargs)
Search backwards in a preOrder traversal of the whole tree (not this node's subnodes). Return None if object not found.
def getPrevious(self)
Find the previous node in the preOrder traversal of the tree.
def getNext(self)
Find the next node in the preOrder traversal of the tree.
def getDepth(self)
Return the depth of this node, i.e. the number of nodes on the path to the root.
def findAttr(self, attr, default=None)
Traverses the path to the root of the tree, looking for the specified attribute. If it is found, return it, else return default.
def attrsToRoot(self, attr)
Traverses the path from this node to the root of the tree, and yields a value for each attribute. Nodes that do not have the attribute and attribute values that test false are ignored.
def treeProp(name)
Define a property whose value should be looked up on nodes between this node and the root, inclusive. Returns the first matching attribute. Raises ValueError if no matching attribute is found.
def dump(self, outf=sys.stdout)
Dump a formatted representation of this tree to the specified file descriptor.
def count(self)
Number of nodes in this tree, including the root.
Copyright Nullcube 2008