|
1 | | -from trame.app import get_server |
| 1 | +from trame.app import TrameApp |
2 | 2 | from trame.ui.vuetify3 import SinglePageLayout |
3 | | -from trame.widgets import vuetify3 as vuetify |
| 3 | +from trame.widgets import vuetify3 as v3 |
4 | 4 |
|
5 | | -# ----------------------------------------------------------------------------- |
6 | | -# Trame setup |
7 | | -# ----------------------------------------------------------------------------- |
8 | 5 |
|
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) |
11 | 9 |
|
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"] |
13 | 13 |
|
| 14 | + self._build_ui() |
14 | 15 |
|
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") |
17 | 23 |
|
| 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 | + ) |
18 | 32 |
|
19 | | -# ----------------------------------------------------------------------------- |
20 | | -# GUI |
21 | | -# ----------------------------------------------------------------------------- |
22 | 33 |
|
23 | | -state.trame__title = "Menu example" |
| 34 | + def print_item(self, item): |
| 35 | + print("Clicked on", item) |
24 | 36 |
|
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 | | - ) |
42 | 37 |
|
43 | 38 | if __name__ == "__main__": |
44 | | - server.start() |
| 39 | + app = Demo() |
| 40 | + app.server.start() |
0 commit comments