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
|
from trame.app import get_server
from trame.ui.vuetify import SinglePageLayout
from trame.widgets import client
# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------
server = get_server(client_type="vue2")
state, ctrl = server.state, server.controller
STYLES = [
"div { background: white; }",
"div { background: red; }",
"div { background: blue; }",
"div { background: green; }",
"div { background: gray; }",
]
STYLE_IDX = 0
def change_style():
global STYLE_IDX
STYLE_IDX += 1
if len(STYLES) == STYLE_IDX:
STYLE_IDX = 0
ctrl.update_style(STYLES[STYLE_IDX])
# -----------------------------------------------------------------------------
# UI setup
# -----------------------------------------------------------------------------
with SinglePageLayout(server) as layout:
layout.icon.click = change_style
layout.title.set_text("Toggle HTML Background")
layout.toolbar.dense = True
style = client.Style("div { background: orange }")
ctrl.update_style = style.update
# -----------------------------------------------------------------------------
# start server
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start()
|