# 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(spec=None, wraps=None, name=None, spec_set=None, parent=None, _spec_state=None, _new_name='', _new_parent=None, _spec_as_instance=False, _eat_self=None, unsafe=False, **kwargs)

  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()

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

  collapse_focussed()

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

  expand_all()

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

  expand_focussed()

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

  focus_first_child()

    move focus to first child of currently focussed one

  focus_last_child()

    move focus to last child of currently focussed one

  focus_next()

    move focus to next position (DFO)

  focus_next_sibling()

    move focus to next sibling of currently focussed one

  focus_parent()

    move focus to parent node of currently focussed one

  focus_prev()

    move focus to previous position (DFO)

  focus_prev_sibling()

    move focus to previous sibling of currently focussed one

class urwidtrees.widgets.TreeListWalker(spec=None, wraps=None, name=None, spec_set=None, parent=None, _spec_state=None, _new_name='', _new_parent=None, _spec_as_instance=False, _eat_self=None, unsafe=False, **kwargs)

  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()

    removes all cached lines

  positions(reverse=False)

    returns a generator that walks the tree’s positions