Containers¶
TreeBox is essentially a urwid.ListBox that displays a given Tree.
Per default no decoration is used and the widgets of the tree are simply displayed line by line in
depth first order. TreeBox’s constructor accepts a focus parameter to specify the initially
focussed position. Internally, it uses a TreeListWalker to linearize the tree to a list.
TreeListWalker serve as adapter between Tree and urwid.ListWalker APIs:
They implement the ListWalker API using the data from a given Tree in depth-first order.
As such, one can directly pass on a TreeListWalker to an urwid.ListBox if one doesn’t want
to use tree-based focus movement or key bindings for collapsing subtrees.
API¶
- class urwidtrees.widgets.TreeBox(tree, focus=None)[source]¶
A widget that displays a given
Tree. This is essentially aListBoxwith the ability to move the focus based on directions in the Tree and to collapse/expand subtrees if possible.Keys are passed to the underlying ListBox first. Of those it leaves, TreeBox interprets left/right to move the focus to the parent/first child, [/] to move it to the previous/next sibling, -/+ to collapse/expand the focussed node and C/E to collapse/expand all. A movement key that does not move the focus, and a collapse key on a tree that cannot collapse, are returned as unhandled, so that enclosing widgets can use them.
- collapse_all()[source]¶
Collapse all positions; works only if the underlying tree allows it. The focus moves to the top-level node it was under.
- collapse_focussed()[source]¶
Collapse currently focussed position; works only if the underlying tree allows it.
- class urwidtrees.widgets.TreeListWalker(tree, focus=None)[source]¶
ListWalker to walk through a class:Tree.
This translates a
Treeinto aurwid.ListWalkerthat is digestible byurwid.ListBox. It usesTree.[next|prev]_positionto determine the next/previous position in depth first order.