-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathapp.py
135 lines (113 loc) · 4.23 KB
/
app.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from pathlib import Path
from trame.app import get_server
from trame.ui.vuetify3 import SinglePageLayout
from trame.widgets import vuetify3 as vuetify, simput, html
from trame_simput import get_simput_manager
# -----------------------------------------------------------------------------
# Trame setup
# -----------------------------------------------------------------------------
server = get_server()
state, ctrl = server.state, server.controller
# -----------------------------------------------------------------------------
# Simput initialization
# -----------------------------------------------------------------------------
DEF_DIR = Path(__file__).with_name("definitions")
simput_manager = get_simput_manager()
simput_manager.load_model(yaml_file=DEF_DIR / "model.yaml")
# -----------------------------------------------------------------------------
# Application state
# -----------------------------------------------------------------------------
pxm = simput_manager.proxymanager
CHOICES = []
for obj_type in pxm.types():
item = pxm.create(obj_type)
CHOICES.append({"text": obj_type, "value": item.id})
# -----------------------------------------------------------------------------
@state.change("use_xml_ui")
def update_ui(use_xml_ui, **kwargs):
if use_xml_ui:
simput_manager.load_ui(xml_file=DEF_DIR / "ui.xml")
else:
simput_manager.clear_ui()
simput_manager.load_model(
yaml_file=DEF_DIR / "model.yaml"
) # Needed to generate UI
# -----------------------------------------------------------------------------
# Simput container initialization
# -----------------------------------------------------------------------------
simput_widget = simput.Simput(simput_manager, prefix="simput", trame_server=server)
ctrl.simput_apply = simput_widget.apply
ctrl.simput_reset = simput_widget.reset
# -----------------------------------------------------------------------------
# UI
# -----------------------------------------------------------------------------
with SinglePageLayout(server) as layout:
simput_widget.register_layout(layout)
with layout.toolbar as toolbar:
layout.title.set_text("SimPut Widgets")
toolbar.dense = True
vuetify.VSpacer()
vuetify.VSwitch(
label="UI",
v_model=("use_xml_ui", False),
classes="mx-2",
dense=True,
hide_details=True,
)
vuetify.VCheckbox(
v_model=("showChangeSet", False),
on_icon="mdi-bug",
off_icon="mdi-shield-bug-outline",
classes="mx-1",
hide_details=True,
dense=True,
)
vuetify.VSwitch(
label="Apply",
v_model=("simputAutoApply", False),
classes="mx-2",
dense=True,
hide_details=True,
)
with vuetify.VBtn(
classes="mx-2",
small=True,
outlined=True,
icon=True,
disabled=("!simputChangeSet",),
click=ctrl.simput_apply,
):
with vuetify.VBadge(
content=("simputChangeSet", ""),
offset_x=8,
offset_y=8,
value=("simputChangeSet", ""),
):
vuetify.VIcon("mdi-database-import")
with vuetify.VBtn(
classes="mx-2",
small=True,
outlined=True,
icon=True,
disabled=("!simputChangeSet",),
click=ctrl.simput_reset,
):
vuetify.VIcon("mdi-undo-variant")
vuetify.VSelect(
v_model=("active", CHOICES[0].get("value")),
items=("choices", CHOICES),
dense=True,
hide_details=True,
style="max-width: 120px;",
)
with layout.content:
with vuetify.VContainer(fluid=True, v_if="active"):
html.Pre("{{ simputChangeSetContent }}", v_if="showChangeSet")
simput.SimputItem(
item_id="active",
)
# -----------------------------------------------------------------------------
# Start server
# -----------------------------------------------------------------------------
if __name__ == "__main__":
server.start()