misc Package¶
misc Package¶
This module contains several useful functions and classes that dont fit in any other modules.
progress_display Module¶
Displays the progress during the computing.
tinytree Module¶
-
class
ABXpy.misc.tinytree.Tree(children=None)[source]¶ Bases:
objectA simple implementation of an ordered tree
-
addChildrenFromList(children)[source]¶ Add children to this node.
:children A nested list specifying a tree of children
-
attrsToRoot(attr)[source]¶ 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.
:attr A string attribute name
-
dump(outf=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]¶ Dump a formatted representation of this tree to the specified file descriptor.
:outf Output file descriptor.
-
findAttr(attr, default=None)[source]¶ Traverses the path to the root of the tree, looking for the specified attribute. If it is found, return it, else return default.
:attr A string attribute name :default Arbitrary default return value
-
findBackwards(*func, **kwargs)[source]¶ Search backwards in a preOrder traversal of the whole tree (not this node’s subnodes). Return None if object not found.
:func A list of selector functions, that accept a node, and return a boolean.
:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.
-
findChild(*func, **kwargs)[source]¶ 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.
:func A list of selector functions, that accept a node, and return a boolean.
:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.
-
findForwards(*func, **kwargs)[source]¶ Search forwards in a preOrder traversal of the whole tree (not this node’s subnodes). Return None if object not found.
:func A list of selector functions, that accept a node, and return a boolean.
:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.
-
findParent(*func, **kwargs)[source]¶ Find the first node matching func in a traversal to the root of the tree. Return None if no matching object is found.
:func A list of selector functions, that accept a node, and return a boolean.
:kwargs A dictionary of attribute selectors. Checks that matching attributes exist, and that their values are equal to the specified values.
-
getDepth()[source]¶ Return the depth of this node, i.e. the number of nodes on the path to the root.
-
inject(node)[source]¶ Inserts a node between the current node and its children. Returns the specified parent node.
:node A Tree object
-
isDescendantOf(node)[source]¶ Returns true if this node lies on the path to the root from the specified node.
:node A Tree object
-
isSiblingOf(node)[source]¶ Returns true if this node is a sibling of the specified node.
:node A Tree object
-
pathFromRoot()[source]¶ Generator yielding all nodes on the path to this node from the root of the tree, including this node itself.
-
pathToRoot()[source]¶ Generator yielding all objects on the path from this node to the root of the tree, including this node itself.
-
remove()[source]¶ Remove this node from its parent. Returns the index this node had in the parent child list.
-
reparent(node)[source]¶ Inserts a node between the current node and its parent. Returns the specified parent node.
:node A Tree object
-