bootstack.TreeNode#
- class bootstack.TreeNode(label='', *, icon=None, open_icon=None, closed_icon=None, expanded=False, loader=None, data=None, **extra)#
Bases:
objectA single node in a
Tree.Nodes are identity-based handles: hold the object returned by
Tree.add()and pass it back toexpand(),select(),remove(), and friends. Two nodes are never equal unless they are the same object.Display attributes (
label,icon,open_icon,closed_icon, …) are a non-destructive view over the node. Any keyword not recognized as a display parameter is folded intodata, so a handler always gets the user’s domain data back.- children: list[TreeNode]#
The child nodes, in order. Empty for a leaf, and empty for a lazy node until its
loaderhas run on first expand.
- data: dict[str, Any]#
Open-ended data bag for your own attributes. Holds any keyword passed to
add()that is not a recognized display parameter, and — for a data-source-backed tree — the node’s source record.
- loader: Callable[[TreeNode], Any] | None#
Callable invoked on first expand to fetch children lazily, or
Nonefor an eagerly-populated node. Receives the node; returns an iterable of child specs.
- add(label='', **kwargs)#
Add a child node under this node and return it.
- ancestors()#
Yield this node’s parent, grandparent, … up to the root.
- collapse()#
Collapse this node to hide its children.
- descendants()#
Yield every node beneath this one, depth-first.
- expand()#
Expand this node to reveal its children.
- reload_children()#
Refresh a lazy node’s children (drop and re-fetch via its loader).
- remove()#
Remove this node (and its descendants) from the tree.