generated from dopt-python/py311
track prototypes
This commit is contained in:
49
prototypes/recursive_menu.py
Normal file
49
prototypes/recursive_menu.py
Normal file
@@ -0,0 +1,49 @@
|
||||
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"))
|
||||
Reference in New Issue
Block a user