File: dynamic.py

package info (click to toggle)
python-trame 3.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 101,620 kB
  • sloc: python: 13,515; sh: 183; javascript: 93; makefile: 7
file content (49 lines) | stat: -rw-r--r-- 1,042 bytes parent folder | download | duplicates (2)
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
r"""
Installation requirements:
    pip install trame trame-vuetify
"""

import asyncio

from trame.app import asynchronous, get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import vuetify

coundown_init = 10

server = get_server(client_type="vue2")
state = server.state
state.trame__title = "Coundown"


@asynchronous.task
async def start_countdown():
    try:
        state.countdown = int(state.countdown)
    except ValueError:
        state.countdown = coundown_init

    while state.countdown > 0:
        with state:
            await asyncio.sleep(0.5)
            state.countdown -= 1


with SinglePageLayout(server) as layout:
    layout.title.set_text("Countdown")

    with layout.toolbar:
        vuetify.VSpacer()
        vuetify.VBtn(
            "Start countdown",
            click=start_countdown,
        )

    with layout.content:
        vuetify.VTextField(
            v_model=("countdown", coundown_init),
            classes="ma-8",
        )

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