Karana.KUtils.MultibodyTUI.view#

Attributes#

Classes#

HasId

Structural type to require an id getter method

View

Container for exploring subsets of items of a given type

Module Contents#

class Karana.KUtils.MultibodyTUI.view.HasId[source]#

Bases: Protocol

Structural type to require an id getter method

id() int[source]#
Karana.KUtils.MultibodyTUI.view.Value#
class Karana.KUtils.MultibodyTUI.view.View(name: str, init_values: collections.abc.Iterable[Value])[source]#

Bases: Generic[Value]

Container for exploring subsets of items of a given type

At any time, the view has a current list of items (the ‘selection’). And, if the selection is nonempty, a single specific item from the selection (the ‘current item’).

Key features:

  • Change to a different selection, maintaining the current item if it is a member of the new selection.

  • Mark the current item as a ‘favorite’ and list all favorites.

  • Take any number of steps forward or backward in the selection.

copy() Self[source]#

Create a copy of this view

Returns:

A copy of this view

Return type:

Self

property current: Value | None#

The current item or None if the selection is empty

property selection: list[Value]#

The selection

property index: int#

The index of the current item in the selection list

property name: str#

The name of the view

select(values: collections.abc.Iterable[Value], current: Value | None = None)[source]#

Change to a new selection

Parameters:
  • values (Iterable[Value]) – The new selection

  • current (Value | None = None) – The prefered current item in the new selection, using the current item from the prior selection if None.

is_favorite(value: Value) bool[source]#

Whether the given item is a favorite

Parameters:

value (Value) – The item to check

Returns:

Whether the given item is a favorite

Return type:

bool

property on_favorite: bool#

Whether the current item is a favorite

property favorites: list[Value]#

The list of all favorite items

toggle_favorite(value: Value | None = None)[source]#

Toggle the favorite status of an item

Parameters:

value (Value | None = None) – The item to toggle, or the current item if None

next(step: int = 1)[source]#

Increment the current item index

When the step size is greater than one, this has ‘sticky’ behavior around the endpoints of the selection, stopping early at both the end and beginning of the selection. This is more complex than the more obvious solution of using modulo, but will hopefully result in more intuitive behavior to the user.

Parameters:

step (int = 1) – The amount to increment the current item index

prev(step: int = 1)[source]#

Decrement the current item index

When the step size is greater than one, this has ‘sticky’ behavior around the endpoints of the selection, stopping early at both the beginning and end of the selection. This is more complex than the more obvious solution of using modulo, but will hopefully result in more intuitive behavior to the user.

Parameters:

step (int = 1) – The amount to decrement the current item index

__bool__() bool[source]#

Whether the view’s selection is nonempty

__eq__(other: View) bool[source]#

Whether the views have identical state

__len__() int[source]#

Number of items in the view’s selection