Skip to content

state

dev_tool.tui.components.state

State dataclass

A data class representing the menu state.

This class tracks the current menu, selected index, row, and offset.

menu instance-attribute

index instance-attribute

row instance-attribute

offset instance-attribute

tab = 0 class-attribute instance-attribute

StateManager

A class for managing TUI state and navigation stack.

The constructor for the StateManager class.

Source code in dev_tool/tui/components/state.py
def __init__(self) -> None:
    """The constructor for the StateManager class."""

    menu = MenuFactory.create_main_menu()

    self.stack = [
        State(
            menu=menu,
            index=0,
            row=0,
            offset=0,
            tab=0
        )
    ]

stack = [State(menu=menu, index=0, row=0, offset=0, tab=0)] instance-attribute

current property

A property that gets the current state.

Returns:

  • State

    The current state.

index property writable

A property that gets the current selected index.

Returns:

  • int

    The current index.

menu property

A property that gets the current menu.

Returns:

  • Menu

    The current menu.

offset property writable

A property that gets the current scroll offset.

Returns:

  • int

    The current offset.

root property

A property that gets the root menu.

Returns:

  • Menu

    The root menu.

row property writable

A property that gets the current row.

Returns:

  • int

    The current row.

tab property writable

A property that gets the current tab index.

Returns:

  • int

    The current tab index.

go_back

A method that navigates back to the previous menu.

Source code in dev_tool/tui/components/state.py
def go_back(self) -> None:
    """A method that navigates back to the previous menu."""

    if len(self.stack) > 1:
        self.stack.pop()

is_root_with_tabs

A method that checks if currently at root level with tabs.

Returns:

  • bool

    True if at root with tabs, False otherwise.

Source code in dev_tool/tui/components/state.py
def is_root_with_tabs(self) -> bool:
    """
    A method that checks if currently at root level with tabs.

    :return: True if at root with tabs, False otherwise.
    """

    return len(self.stack) == 1 and self.is_tabs()

is_tabs

A method that checks if the current menu has tabs.

Returns:

  • bool

    True if the menu has tabs, False otherwise.

Source code in dev_tool/tui/components/state.py
def is_tabs(self) -> bool:
    """
    A method that checks if the current menu has tabs.

    :return: True if the menu has tabs, False otherwise.
    """

    if not self.root.items:
        return False

    return self.root.items[0].as_menu() is not None

push_menu

A method that pushes a new menu onto the stack.

Parameters:

  • menu (Menu) –

    The new menu.

Source code in dev_tool/tui/components/state.py
def push_menu(self, menu: Menu) -> None:
    """
    A method that pushes a new menu onto the stack.

    :param menu: The new menu.
    """

    if menu is self.menu:
        return

    current = self.index if self.is_root_with_tabs() else self.tab

    state = State(
        menu=menu,
        index=0,
        row=0,
        offset=0,
        tab=current
    )

    self.stack.append(state)