A factory class for creating TUI menus.
This class provides static methods for creating different types of menus.
create_main_menu
staticmethod
A method that creates the main menu.
Returns:
Source code in dev_tool/tui/menu/factory.py
| @staticmethod
def create_main_menu() -> Menu:
"""
A method that creates the main menu.
:return: The main menu.
"""
tabs: dict[str, list[tuple[int, MenuItem]]] = {}
for specification in REGISTRY.values():
label = specification['label']
title = specification['category']
command = specification['bound']
group = specification['group']
order = specification['order']
if title not in tabs:
tabs[title] = []
item: MenuItem | None = None
match group:
case ActionGroup.COMMAND:
action = CommandAction(command=command)
item = MenuItem(label=label, action=action)
case ActionGroup.SUBMENU:
action = SubmenuAction(submenu=command)
item = MenuItem(label=label, action=action)
if item is not None:
tabs[title].append((order, item))
sorted_tabs: dict[str, list[Menu | MenuItem]] = {}
for title, items in tabs.items():
items.sort(key=lambda x: x[0])
sorted_tabs[title] = [item for _, item in items]
menu_items: list[Menu | MenuItem] = [
Menu(title=title, items=items)
for title, items in sorted_tabs.items()
]
return Menu(title='Main Menu', items=menu_items)
|