List Walker Classes

ListWalker

class urwid.ListWalker
get_focus()

This default implementation relies on a focus attribute and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

get_next(position)

This default implementation relies on a next_position() method and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

get_prev(position)

This default implementation relies on a prev_position() method and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

List-like List Walkers

class urwid.SimpleFocusListWalker(contents: Iterable[_T], wrap_around: bool = False)

contents – list to copy into this object

wrap_around – if true, jumps to beginning/end of list on move

This class inherits MonitoredList which means it can be treated as a list.

Changes made to this object (when it is treated as a list) are detected automatically and will cause ListBox objects using this list walker to be updated.

Also, items added or removed before the widget in focus with normal list methods will cause the focus to be updated intelligently.

next_position(position: int) int

Return position after start_from.

positions(reverse: bool = False) Iterable[int]

Optional method for returning an iterable of positions.

prev_position(position: int) int

Return position before start_from.

set_focus(position: int) None

Set focus position.

set_modified_callback(callback: Any) NoReturn

This function inherited from MonitoredList is not implemented in SimpleFocusListWalker.

Use connect_signal(list_walker, “modified”, …) instead.

class urwid.SimpleListWalker(contents: Iterable[_T], wrap_around: bool = False)

contents – list to copy into this object

wrap_around – if true, jumps to beginning/end of list on move

This class inherits MonitoredList which means it can be treated as a list.

Changes made to this object (when it is treated as a list) are detected automatically and will cause ListBox objects using this list walker to be updated.

property contents: Self

Return self.

Provides compatibility with old SimpleListWalker class.

next_position(position: int) int

Return position after start_from.

positions(reverse: bool = False) Iterable[int]

Optional method for returning an iterable of positions.

prev_position(position: int) int

Return position before start_from.

set_focus(position: int) None

Set focus position.

set_modified_callback(callback: Callable[[], Any]) NoReturn

This function inherited from MonitoredList is not implemented in SimpleListWalker.

Use connect_signal(list_walker, “modified”, …) instead.

TreeWalker and Nodes

class urwid.TreeWalker(start_from)

ListWalker-compatible class for displaying TreeWidgets

positions are TreeNodes.

start_from: TreeNode with the initial focus.

get_focus()

This default implementation relies on a focus attribute and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

get_next(start_from) tuple[TreeWidget, TreeNode] | tuple[None, None]

This default implementation relies on a next_position() method and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

get_prev(start_from) tuple[TreeWidget, TreeNode] | tuple[None, None]

This default implementation relies on a prev_position() method and a __getitem__() method defined in a subclass.

Override and don’t call this method if these are not defined.

class urwid.TreeNode(value: Any, parent: ParentNode | None = None, key: Hashable | None = None, depth: int | None = None)

Store tree contents and cache TreeWidget objects. A TreeNode consists of the following elements: * key: accessor token for parent nodes * value: subclass-specific data * parent: a TreeNode which contains a pointer back to this object * widget: The widget used to render the object

get_widget(reload: bool = False) TreeWidget

Return the widget for this node.

load_parent()

Provide TreeNode with a parent for the current node. This function is only required if the tree was instantiated from a child node (virtual function)

class urwid.ParentNode(value: Any, parent: ParentNode | None = None, key: Hashable = None, depth: int | None = None)

Maintain sort order for TreeNodes.

get_child_keys(reload: bool = False) Sequence[Hashable]

Return a possibly ordered list of child keys

get_child_node(key, reload: bool = False) TreeNode

Return the child node for a given key. Create if necessary.

get_child_widget(key) TreeWidget

Return the widget for a given key. Create if necessary.

get_first_child() TreeNode

Return the first TreeNode in the directory.

get_last_child() TreeNode

Return the last TreeNode in the directory.

has_children() bool

Does this node have any children?

load_child_keys() Sequence[Hashable]

Provide ParentNode with an ordered list of child keys (virtual function)

load_child_node(key: Hashable) TreeNode

Load the child node for a given key (virtual function)

next_child(key: Hashable) TreeNode | None

Return the next child node in index order from the given key.

prev_child(key: Hashable) TreeNode | None

Return the previous child node in index order from the given key.

set_child_node(key: Hashable, node: TreeNode) None

Set the child node for a given key.

Useful for bottom-up, lazy population of a tree.