forked from Kitware/QuickView
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
316 lines (281 loc) · 11.1 KB
/
tools.py
File metadata and controls
316 lines (281 loc) · 11.1 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
from pathlib import Path
from trame.app import asynchronous
from trame.decorators import trigger
from trame.widgets import vuetify3 as v3
from e3sm_quickview import __version__ as quickview_version
from e3sm_quickview.assets import ASSETS
# -----------------------------------------------------------------------------
# Logo / Help
# -----------------------------------------------------------------------------
class AppLogo(v3.VTooltip):
def __init__(self, compact="compact_drawer"):
super().__init__(
text=f"QuickView {quickview_version}",
disabled=(f"!{compact}",),
)
with self:
with v3.Template(v_slot_activator="{ props }"):
with v3.VListItem(
v_bind="props",
title=(f"{compact} ? null : 'QuickView {quickview_version}'",),
classes="text-h6",
click=f"{compact} = !{compact}",
):
with v3.Template(raw_attrs=["#prepend"]):
v3.VAvatar(
image=ASSETS.icon,
size=24,
classes="me-4",
)
v3.VProgressCircular(
color="primary",
indeterminate=True,
v_show="trame__busy",
v_if=compact,
style="position: absolute !important;left: 50%;top: 50%; transform: translate(-50%, -50%);",
)
v3.VProgressLinear(
v_else=True,
color="primary",
indeterminate=True,
v_show="trame__busy",
absolute=True,
style="top:90%;width:100%;",
)
# -----------------------------------------------------------------------------
# Clickable tools
# -----------------------------------------------------------------------------
class ActionButton(v3.VTooltip):
def __init__(self, compact, title, icon, click, keybinding=None):
super().__init__(text=title, disabled=(f"!{compact}",))
with self:
with v3.Template(v_slot_activator="{ props }"):
with v3.VListItem(
v_bind="props",
prepend_icon=icon,
title=(f"{compact} ? null : '{title}'",),
click=click,
):
if keybinding:
with v3.Template(v_slot_append=True):
v3.VHotkey(
keys=keybinding,
variant="contained",
inline=True,
classes="mt-n2 border-md border-grey-darken-1 border-opacity-100 rounded-lg",
)
class ResetCamera(ActionButton):
def __init__(self, compact="compact_drawer", click=None):
super().__init__(
compact=compact,
title="Auto zoom",
icon="mdi-fit-to-page-outline",
click=click,
keybinding="z",
)
class ToggleHelp(ActionButton):
def __init__(self, compact="compact_drawer"):
super().__init__(
compact=compact,
title="Toggle Help",
icon="mdi-lifebuoy",
click=f"{compact} = !{compact}",
)
# -----------------------------------------------------------------------------
# Toggle toolbar tools
# -----------------------------------------------------------------------------
class ToggleButton(v3.VTooltip):
def __init__(self, compact, title, icon, value, disabled=None, keybinding=None):
super().__init__(text=title, disabled=(f"!{compact}",))
add_on = {}
if disabled:
add_on["disabled"] = (disabled,)
with self:
with v3.Template(v_slot_activator="{ props }"):
with v3.VListItem(
v_bind="props",
prepend_icon=icon,
value=value,
title=(f"{compact} ? null : '{title}'",),
active_class="border-primary border-md border-primary border-opacity-100",
**add_on,
):
if keybinding:
with v3.Template(v_slot_append=True):
v3.VHotkey(
keys=keybinding,
variant="contained",
inline=True,
classes="mt-n2 border-md border-grey-darken-1 border-opacity-100 rounded-lg",
)
class LayoutManagement(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="Viewport layout",
icon="mdi-view-module",
value="adjust-layout",
keybinding="p",
)
class OpenFile(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="File loading",
icon="mdi-file-upload-outline",
value="load-data",
)
class FieldSelection(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="Variable selection",
icon="mdi-list-status",
value="select-fields",
disabled="variables_listing.length === 0",
keybinding="v",
)
class Cropping(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="Lat/Lon cropping",
icon="mdi-web",
value="adjust-databounds",
keybinding="l",
)
class DataSelection(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="Slice selection",
icon="mdi-tune-variant",
value="select-slice-time",
keybinding="s",
)
class Animation(ToggleButton):
def __init__(self):
super().__init__(
compact="compact_drawer",
title="Animation controls",
icon="mdi-video",
value="animation-controls",
keybinding="a",
)
# -----------------------------------------------------------------------------
# Menu tools
# -----------------------------------------------------------------------------
class MapProjection(v3.VTooltip):
def __init__(self, compact="compact_drawer", title="Map Projection"):
super().__init__(
text=title,
disabled=(f"!{compact}",),
)
with self:
with v3.Template(v_slot_activator="{ props }"):
with v3.VListItem(
v_bind="props",
prepend_icon="mdi-earth",
title=(f"{compact} ? null : '{title}'",),
):
with v3.VMenu(
activator="parent",
location="end",
offset=10,
):
with v3.VList(
mandatory=True,
v_model_selected=(
"projection",
["Mollweide"],
),
density="compact",
# items=("projections", self.options),
):
for entry in self.options:
with (
v3.VListItem(
title=entry.get("title"),
value=entry.get("value"),
),
v3.Template(v_slot_append=True),
):
v3.VHotkey(
keys=entry.get("key"),
variant="contained",
inline=True,
classes="ml-4 mn-2",
)
@property
def options(self):
return [
{
"title": "Cylindrical Equidistant",
"value": "Cyl. Equidistant",
"key": "c",
},
{
"title": "Robinson",
"value": "Robinson",
"key": "r",
},
{
"title": "Mollweide",
"value": "Mollweide",
"key": "m",
},
]
class StateImportExport(v3.VTooltip):
def __init__(self, compact="compact_drawer", title="State Import/Export"):
super().__init__(
text=title,
disabled=(f"!{compact}",),
)
self._pending_task = None
with self:
with v3.Template(v_slot_activator="{ props }"):
with v3.VListItem(
v_bind="props",
prepend_icon="mdi-folder-arrow-left-right-outline",
title=(f"{compact} ? null : '{title}'",),
):
with v3.VMenu(
activator="parent",
location="end",
offset=10,
):
with v3.VList(density="compact"):
v3.VListItem(
title=(
"is_tauri ? 'Save state file' : 'Download state file'",
),
prepend_icon="mdi-file-download-outline",
click=self.download_state,
disabled=("!variables_loaded",),
)
v3.VListItem(
title=(
"is_tauri ? 'Load state file' : 'Upload state file'",
),
prepend_icon="mdi-file-upload-outline",
click="utils.get('document').querySelector('#fileUpload').click()",
)
v3.VFileInput(
id="fileUpload",
v_show=False,
v_model=("upload_state_file", None),
density="compact",
prepend_icon=False,
style="position: absolute;left:-1000px;width:1px;",
)
@trigger("download_state")
def download_state(self):
if not self.state.is_tauri:
self.state.show_export_dialog = True
return
self._pending_task = asynchronous.create_task(self._tauri_save())
async def _tauri_save(self):
export_path = await self.ctrl.save("Export State")
txt_content = self.ctrl.download_state()
Path(export_path).write_text(txt_content)
self._pending_task = None