Skip to content

navigation

dev_tool.tui.components.navigation

NavigationHandler

A handler class for navigation logic.

The constructor for the NavigationHandler class.

Parameters:

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

    :param state: The state manager instance.
    :param notification: The notification display instance.
    """

    self.notification = notification
    self.state = state

notification = notification instance-attribute

state = state instance-attribute

get_selected_item

A method that gets the currently selected menu item.

Returns:

Source code in dev_tool/tui/components/navigation.py
def get_selected_item(self) -> MenuItem:
    """
    A method that gets the currently selected menu item.

    :return: The selected menu item.
    """

    if self.state.is_root_with_tabs():
        selected = self.state.menu.items[self.state.index]
        menu = selected.as_menu()

        if menu:
            item = menu.items[self.state.row].as_menu_item()

            if item:
                return item

            message = 'Expected MenuItem in menu'
            raise ValueError(message)

        message = 'Expected Menu in tab position'
        raise ValueError(message)

    item = self.state.menu.items[self.state.row].as_menu_item()

    if item:
        return item

    message = 'Expected MenuItem'
    raise ValueError(message)

handle_navigation

A method that handles navigation key presses.

Parameters:

  • key (str) –

    The key name.

Returns:

  • bool

    True if the UI needs redraw, False otherwise.

Source code in dev_tool/tui/components/navigation.py
def handle_navigation(self, key: str) -> bool:
    """
    A method that handles navigation key presses.

    :param key: The key name.
    :return: True if the UI needs redraw, False otherwise.
    """

    if self._handle_notification_dismissal(key):
        return True

    if self._handle_submenu(key):
        return True

    self._handle_navigation_keys(key)
    return True