generated from dopt-python/py311
50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
from typing import Any
|
|
|
|
from nicegui import ui
|
|
|
|
nested_menu = {
|
|
"Notiz": None,
|
|
"Beratungsgespräch": None,
|
|
"Neu": {"Unternehmen": None, "Individualperson": None},
|
|
}
|
|
|
|
|
|
def build_menu(
|
|
title: str,
|
|
structure: dict[str, Any],
|
|
):
|
|
def _recursive(structure: dict[str, Any]):
|
|
with ui.menu():
|
|
for label, children in structure.items():
|
|
if children:
|
|
with ui.menu_item(label, auto_close=False).props("icon=arrow_right"):
|
|
with ui.menu().props('anchor="top end" self="top start"'):
|
|
build_menu(children) # Rekursion für Untermenüs
|
|
else:
|
|
ui.menu_item(label, on_click=lambda: ui.notify(f"{label} geklickt"))
|
|
|
|
with ui.button(title, icon="add"):
|
|
_recursive(structure)
|
|
|
|
# ui.menu_item("Direkte Aktion", on_click=lambda: ui.notify("Aktion 1"))
|
|
|
|
# ui.separator()
|
|
|
|
# # Der Trick: @click.stop verhindert, dass das Hauptmenü den Klick bemerkt
|
|
# with ui.menu_item("Untermenü öffnen...", auto_close=False).props("icon=arrow_right"):
|
|
# with ui.item_section().props("side"):
|
|
# ui.icon("keyboard_arrow_right")
|
|
# with ui.menu().props('anchor="top end" self="top start"'):
|
|
# ui.menu_item("Unterpunkt A", on_click=lambda: ui.notify("A"))
|
|
# ui.menu_item("Unterpunkt B", on_click=lambda: ui.notify("B"))
|
|
|
|
|
|
# def build_menu(data):
|
|
# for label, children in data.items():
|
|
# if children:
|
|
# with ui.menu_item(label):
|
|
# with ui.menu().props('anchor="top end" self="top start"'):
|
|
# build_menu(children) # Rekursion für Untermenüs
|
|
# else:
|
|
# ui.menu_item(label, on_click=lambda l=label: ui.notify(f"{l} geklickt"))
|