File: 01_menu_v3.py

package info (click to toggle)
python-trame 3.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,399 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as vuetify

# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------

server = get_server()
state, ctrl = server.state, server.controller

state.menu_items = ["one", "two", "three"]


def print_item(item):
    print("Clicked on", item)


# -----------------------------------------------------------------------------
# GUI
# -----------------------------------------------------------------------------

state.trame__title = "Menu example"

with SinglePageLayout(server) as layout:
    with layout.toolbar:
        vuetify.VSpacer()
        with vuetify.VMenu():
            with vuetify.Template(v_slot_activator="{ on, attrs }"):
                with vuetify.VBtn(icon=True, v_bind="attrs", v_on="on"):
                    vuetify.VIcon("mdi-dots-vertical")
            with vuetify.VList():
                with vuetify.VListItem(
                    v_for="(item, i) in menu_items",
                    key="i",
                    value=["item"],
                ):
                    vuetify.VBtn(
                        "{{ item }}",
                        click=(print_item, "[item]"),
                    )

if __name__ == "__main__":
    server.start()