Skip to content

Commit eb22a28

Browse files
authored
docs(vuetify): 01_menu_v3.py
1 parent 5016288 commit eb22a28

1 file changed

Lines changed: 28 additions & 32 deletions

File tree

examples/02_vuetify/01_menu_v3.py

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
1-
from trame.app import get_server
1+
from trame.app import TrameApp
22
from trame.ui.vuetify3 import SinglePageLayout
3-
from trame.widgets import vuetify3 as vuetify
3+
from trame.widgets import vuetify3 as v3
44

5-
# -----------------------------------------------------------------------------
6-
# Trame setup
7-
# -----------------------------------------------------------------------------
85

9-
server = get_server()
10-
state, ctrl = server.state, server.controller
6+
class Demo(TrameApp):
7+
def __init__(self, server=None):
8+
super().__init__(server)
119

12-
state.menu_items = ["one", "two", "three"]
10+
# Set state values
11+
self.state.trame__title = "Menu example"
12+
self.state.menu_items = ["one", "two", "three"]
1313

14+
self._build_ui()
1415

15-
def print_item(item):
16-
print("Clicked on", item)
16+
def _build_ui(self):
17+
with SinglePageLayout(self.server) as self.ui:
18+
with self.ui.toolbar:
19+
v3.VSpacer()
20+
with v3.VMenu():
21+
with v3.Template(v_slot_activator="{ props }"):
22+
v3.VBtn(icon="mdi-dots-vertical", v_bind="props")
1723

24+
with v3.VList():
25+
v3.VListItem(
26+
v_for="(item, i) in menu_items",
27+
key="i",
28+
value=("item",),
29+
click=(self.print_item, "[item]"),
30+
title=("item",),
31+
)
1832

19-
# -----------------------------------------------------------------------------
20-
# GUI
21-
# -----------------------------------------------------------------------------
2233

23-
state.trame__title = "Menu example"
34+
def print_item(self, item):
35+
print("Clicked on", item)
2436

25-
with SinglePageLayout(server) as layout:
26-
with layout.toolbar:
27-
vuetify.VSpacer()
28-
with vuetify.VMenu():
29-
with vuetify.Template(v_slot_activator="{ on, attrs }"):
30-
with vuetify.VBtn(icon=True, v_bind="attrs", v_on="on"):
31-
vuetify.VIcon("mdi-dots-vertical")
32-
with vuetify.VList():
33-
with vuetify.VListItem(
34-
v_for="(item, i) in menu_items",
35-
key="i",
36-
value=["item"],
37-
):
38-
vuetify.VBtn(
39-
"{{ item }}",
40-
click=(print_item, "[item]"),
41-
)
4237

4338
if __name__ == "__main__":
44-
server.start()
39+
app = Demo()
40+
app.server.start()

0 commit comments

Comments
 (0)