File: reserved_state.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 (47 lines) | stat: -rw-r--r-- 1,243 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
import time

from trame.app import get_server
from trame.ui.html import DivLayout
from trame.widgets import html

# -----------------------------------------------------------------------------
# Trame app
# -----------------------------------------------------------------------------

server = get_server()
count = 1


def make_server_busy():
    time.sleep(1)


def update_title():
    global count
    server.state.trame__title = f"T({count})"
    count += 1


def update_favicon():
    global count
    server.state.trame__favicon = f"https://picsum.photos/id/{count}/32/32"
    count += 10


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

with DivLayout(server) as layout:
    html.Div("trame__busy: {{ trame__busy }}")
    html.Button("Make server busy", click=make_server_busy)
    html.Button("Update title", click=update_title)
    html.Button("Update favicon", click=update_favicon)


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

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