File: 12_reserved_state.py

package info (click to toggle)
python-trame 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (77 lines) | stat: -rw-r--r-- 2,284 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from trame.app import get_server
from trame.assets.local import LocalFileManager
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import html, vuetify

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

server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller

favicons = LocalFileManager(__file__)
favicons.url("open", "./data/fileopen.png")
favicons.url("filter", "./data/filter.png")
favicons.url("kitware", "./data/kw.png")
favicons.url("paraview_mac", "./data/pv_icon.png")
favicons.url("paraview", "./data/pv.png")

_idx = 0
OPTIONS = [*favicons.assets]


def random_update():
    global _idx
    _idx = (_idx + 1) % len(OPTIONS)
    name = OPTIONS[_idx]
    state.favicon = name
    state.trame__title = name


@state.change("favicon")
def update_favicon(favicon, **kwargs):
    state.trame__favicon = favicons[favicon]


# -----------------------------------------------------------------------------
# UI setup
# -----------------------------------------------------------------------------

layout = SinglePageLayout(server)

with layout:
    layout.title.set_text("Title favicon")

    # Toolbar
    with layout.toolbar as toolbar:
        vuetify.VSpacer()
        vuetify.VSelect(
            label="favicon",
            v_model=("favicon", None),
            items=(
                "favicon_items",
                [{"text": value, "value": value} for value in favicons.assets.keys()],
            ),
            style="max-width: 200px;",
            dense=True,
            hide_details=True,
            classes="mx-4",
        )
        with html.Div(style="width: 200px;", classes="mx-4"):
            vuetify.VTextField(
                label="Title",
                v_model="trame__title",
                dense=True,
                hide_details=True,
            )
        with vuetify.VBtn(icon=True, click=random_update):
            vuetify.VIcon("mdi-refresh")


# -----------------------------------------------------------------------------
# start server
# -----------------------------------------------------------------------------

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