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 a ListBox with the ability to move the focus based on directions in the Tree and to collapse/expand subtrees if possible.

TreeBox interprets left/right as well as page up/`page down to move the focus to parent/first child and next/previous sibling respectively. All other keys are passed to the underlying ListBox.

collapse_all()[source]

Collapse all positions; works only if the underlying tree allows it.

collapse_focussed()[source]

Collapse currently focussed position; works only if the underlying tree allows it.

expand_all()[source]

Expand all positions; works only if the underlying tree allows it.

expand_focussed()[source]

Expand currently focussed position; works only if the underlying tree allows it.

focus_first_child()[source]

move focus to first child of currently focussed one

focus_last_child()[source]

move focus to last child of currently focussed one

focus_next()[source]

move focus to next position (DFO)

focus_next_sibling()[source]

move focus to next sibling of currently focussed one

focus_parent()[source]

move focus to parent node of currently focussed one

focus_prev()[source]

move focus to previous position (DFO)

focus_prev_sibling()[source]

move focus to previous sibling of currently focussed one

class urwidtrees.widgets.TreeListWalker(tree, focus=None)[source]

ListWalker to walk through a class:Tree.

This translates a Tree into a urwid.ListWalker that is digestible by urwid.ListBox. It uses Tree.[next|prev]_position to determine the next/previous position in depth first order.

clear_cache()[source]

removes all cached lines

positions(reverse=False)[source]

returns a generator that walks the tree’s positions