Skip to content

Commit eb030a3

Browse files
committed
fix: tauri save state and key binding
1 parent 399655f commit eb030a3

File tree

5 files changed

+56
-28
lines changed

5 files changed

+56
-28
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies = [
2929
"netCDF4>=1.6.5",
3030
"trame-dataclass>=1.2",
3131
"trame-components",
32+
"trame-tauri>=0.6.2",
3233
]
3334

3435
[project.optional-dependencies]
@@ -37,7 +38,6 @@ tauri = [
3738
]
3839
vue2 = [
3940
"trame-grid-layout>=1.0.3",
40-
"trame-tauri>=0.6.2",
4141
]
4242

4343

src/e3sm_quickview/app2.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from trame.app import TrameApp, asynchronous, file_upload
99
from trame.ui.vuetify3 import VAppLayout
10-
from trame.widgets import vuetify3 as v3, client, html, dataclass, trame as tw
10+
from trame.widgets import vuetify3 as v3, client, html, dataclass, trame as tw, tauri
1111
from trame.decorators import controller, change, trigger, life_cycle
1212

1313
from e3sm_quickview import module as qv_module
@@ -37,6 +37,7 @@ def __init__(self, server=None):
3737
{
3838
"trame__title": "QuickView",
3939
"trame__favicon": ASSETS.icon,
40+
"is_tauri": False,
4041
"animation_play": False,
4142
# All available variables
4243
"variables_listing": [],
@@ -116,6 +117,7 @@ def _build_ui(self, **_):
116117
Size2=(self.view_manager.apply_size, "[2]"),
117118
Size3=(self.view_manager.apply_size, "[3]"),
118119
Size4=(self.view_manager.apply_size, "[4]"),
120+
Size5=(self.view_manager.apply_size, "[5]"),
119121
Size6=(self.view_manager.apply_size, "[6]"),
120122
ToolbarLayout=(self.toggle_toolbar, "['adjust-layout']"),
121123
ToolbarCrop=(self.toggle_toolbar, "['adjust-databounds']"),
@@ -135,24 +137,30 @@ def _build_ui(self, **_):
135137
mt.bind(["alt+2", "2"], "Size2")
136138
mt.bind(["alt+3", "3"], "Size3")
137139
mt.bind(["alt+4", "4"], "Size4")
140+
mt.bind(["alt+5", "5"], "Size5")
138141
mt.bind(["alt+6", "6"], "Size6")
139142

140-
mt.bind("i", "ProjectionEquidistant")
141-
mt.bind("o", "ProjectionRobinson")
142-
mt.bind("p", "ProjectionMollweide")
143+
mt.bind("e", "ProjectionEquidistant")
144+
mt.bind("b", "ProjectionRobinson")
145+
mt.bind("m", "ProjectionMollweide")
143146

144-
mt.bind("a", "ToolbarLayout")
145-
mt.bind("s", "ToolbarCrop")
146-
mt.bind("d", "ToolbarSelect")
147-
mt.bind("f", "ToolbarAnimation")
147+
mt.bind("l", "ToolbarLayout")
148+
mt.bind("c", "ToolbarCrop")
149+
mt.bind("s", "ToolbarSelect")
150+
mt.bind("a", "ToolbarAnimation")
148151
mt.bind("g", "ToggleGroups")
149152

150-
mt.bind("?", "ToggleVariableSelection")
153+
mt.bind("v", "ToggleVariableSelection")
151154

152155
mt.bind("space", "ToggleViewLock", stop_propagation=True)
153156

154157
mt.bind("esc", "RemoveAllToolbars")
155158

159+
# Native Dialogs
160+
client.ClientTriggers(mounted="is_tauri = !!window.__TAURI__")
161+
with tauri.Dialog() as dialog:
162+
self.ctrl.save = dialog.save
163+
156164
with v3.VLayout():
157165
drawers.Tools(
158166
reset_camera=self.view_manager.reset_camera,
@@ -209,6 +217,7 @@ def selected_variable_names(self):
209217
# -------------------------------------------------------------------------
210218

211219
@trigger("download_state")
220+
@controller.set("download_state")
212221
def download_state(self):
213222
active_variables = self.selected_variables
214223
state_content = {}

src/e3sm_quickview/components/doc.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __init__(self):
3838
""",
3939
)
4040
with self, v3.Template(v_slot_append=True):
41-
v3.VHotkey(keys="?", variant="contained", inline=True)
41+
v3.VHotkey(keys="v", variant="contained", inline=True)
4242

4343

4444
class ToolResetCamera(Tool):
@@ -69,9 +69,9 @@ def __init__(self):
6969
description="Select projection to use for the visualizations. (Cylindrical Equidistant, Robinson, Mollweide)",
7070
)
7171
with self, v3.Template(v_slot_append=True):
72-
v3.VHotkey(keys="i", variant="contained", inline=True)
73-
v3.VHotkey(keys="o", variant="contained", inline=True)
74-
v3.VHotkey(keys="p", variant="contained", inline=True)
72+
v3.VHotkey(keys="e", variant="contained", inline=True)
73+
v3.VHotkey(keys="b", variant="contained", inline=True)
74+
v3.VHotkey(keys="m", variant="contained", inline=True)
7575

7676

7777
class ToolLayoutManagement(Tool):
@@ -82,7 +82,7 @@ def __init__(self):
8282
description="Toggle layout toolbar for adjusting aspect-ratio, width and grouping options.",
8383
)
8484
with self, v3.Template(v_slot_append=True):
85-
v3.VHotkey(keys="a", variant="contained", inline=True)
85+
v3.VHotkey(keys="l", variant="contained", inline=True)
8686

8787

8888
class ToolCropping(Tool):
@@ -93,7 +93,7 @@ def __init__(self):
9393
description="Toggle cropping toolbar for adjusting spacial bounds.",
9494
)
9595
with self, v3.Template(v_slot_append=True):
96-
v3.VHotkey(keys="s", variant="contained", inline=True)
96+
v3.VHotkey(keys="c", variant="contained", inline=True)
9797

9898

9999
class ToolDataSelection(Tool):
@@ -104,7 +104,7 @@ def __init__(self):
104104
description="Toggle data selection toolbar for selecting a given layer, midpoint or time.",
105105
)
106106
with self, v3.Template(v_slot_append=True):
107-
v3.VHotkey(keys="d", variant="contained", inline=True)
107+
v3.VHotkey(keys="s", variant="contained", inline=True)
108108

109109

110110
class ToolAnimation(Tool):
@@ -115,7 +115,7 @@ def __init__(self):
115115
description="Toggle animation toolbar.",
116116
)
117117
with self, v3.Template(v_slot_append=True):
118-
v3.VHotkey(keys="f", variant="contained", inline=True)
118+
v3.VHotkey(keys="a", variant="contained", inline=True)
119119

120120

121121
# -----------------------------------------------------------------------------
@@ -225,19 +225,19 @@ def __init__(self):
225225
with v3.VRow(classes="ma-0 pb-4"):
226226
v3.VLabel("Toggle Layout management toolbar")
227227
v3.VSpacer(classes="mt-2")
228-
v3.VHotkey(keys="a", variant="contained", inline=True)
228+
v3.VHotkey(keys="l", variant="contained", inline=True)
229229
with v3.VRow(classes="ma-0 pb-4"):
230230
v3.VLabel("Toggle Lat/Long cropping toolbar")
231231
v3.VSpacer()
232-
v3.VHotkey(keys="s", variant="contained", inline=True)
232+
v3.VHotkey(keys="c", variant="contained", inline=True)
233233
with v3.VRow(classes="ma-0 pb-4"):
234234
v3.VLabel("Toggle Slice selection toolbar")
235235
v3.VSpacer()
236-
v3.VHotkey(keys="d", variant="contained", inline=True)
236+
v3.VHotkey(keys="s", variant="contained", inline=True)
237237
with v3.VRow(classes="ma-0 pb-4"):
238238
v3.VLabel("Toggle Animation controls toolbar")
239239
v3.VSpacer()
240-
v3.VHotkey(keys="f", variant="contained", inline=True)
240+
v3.VHotkey(keys="a", variant="contained", inline=True)
241241

242242
v3.VDivider(classes="mb-4")
243243

@@ -249,7 +249,7 @@ def __init__(self):
249249
with v3.VRow(classes="ma-0 pb-4"):
250250
v3.VLabel("Toggle variable selection drawer")
251251
v3.VSpacer()
252-
v3.VHotkey(keys="?", variant="contained", inline=True)
252+
v3.VHotkey(keys="v", variant="contained", inline=True)
253253

254254
v3.VDivider(classes="mb-4")
255255

@@ -265,13 +265,13 @@ def __init__(self):
265265
with v3.VList(density="compact", classes="pa-0 ma-0"):
266266
with v3.VListItem(subtitle="Cylindrical Equidistant"):
267267
with v3.Template(v_slot_append="True"):
268-
v3.VHotkey(keys="i", variant="contained", inline=True)
268+
v3.VHotkey(keys="e", variant="contained", inline=True)
269269
with v3.VListItem(subtitle="Robinson"):
270270
with v3.Template(v_slot_append="True"):
271-
v3.VHotkey(keys="o", variant="contained", inline=True)
271+
v3.VHotkey(keys="b", variant="contained", inline=True)
272272
with v3.VListItem(subtitle="Mollweide"):
273273
with v3.Template(v_slot_append="True"):
274-
v3.VHotkey(keys="p", variant="contained", inline=True)
274+
v3.VHotkey(keys="m", variant="contained", inline=True)
275275

276276
v3.VDivider(classes="my-4")
277277

@@ -291,6 +291,9 @@ def __init__(self):
291291
with v3.VListItem(subtitle="4 columns"):
292292
with v3.Template(v_slot_append="True"):
293293
v3.VHotkey(keys="4", variant="contained", inline=True)
294+
with v3.VListItem(subtitle="5 columns"):
295+
with v3.Template(v_slot_append="True"):
296+
v3.VHotkey(keys="5", variant="contained", inline=True)
294297
with v3.VListItem(subtitle="6 columns"):
295298
with v3.Template(v_slot_append="True"):
296299
v3.VHotkey(keys="6", variant="contained", inline=True)

src/e3sm_quickview/components/tools.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
from pathlib import Path
12
from trame.widgets import vuetify3 as v3
3+
from trame.app import asynchronous
24

35
from e3sm_quickview import __version__ as quickview_version
46
from e3sm_quickview.assets import ASSETS
@@ -218,6 +220,7 @@ def __init__(self, compact="compact_drawer", title="State Import/Export"):
218220
text=title,
219221
disabled=(f"!{compact}",),
220222
)
223+
self._pending_task = None
221224
with self:
222225
with v3.Template(v_slot_activator="{ props }"):
223226
with v3.VListItem(
@@ -234,7 +237,7 @@ def __init__(self, compact="compact_drawer", title="State Import/Export"):
234237
v3.VListItem(
235238
title="Download state file",
236239
prepend_icon="mdi-file-download-outline",
237-
click="show_export_dialog=true",
240+
click=self.download_state,
238241
disabled=("!variables_loaded",),
239242
)
240243
v3.VListItem(
@@ -251,3 +254,16 @@ def __init__(self, compact="compact_drawer", title="State Import/Export"):
251254
prepend_icon=False,
252255
style="position: absolute;left:-1000px;width:1px;",
253256
)
257+
258+
def download_state(self):
259+
if not self.state.is_tauri:
260+
self.state.show_export_dialog = True
261+
return
262+
263+
self._pending_task = asynchronous.create_task(self._tauri_save())
264+
265+
async def _tauri_save(self):
266+
export_path = await self.ctrl.save("Export State")
267+
txt_content = self.ctrl.download_state()
268+
Path(export_path).write_text(txt_content)
269+
self._pending_task = None

src/e3sm_quickview/view_manager2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, server, source, variable_name, variable_type):
7979
self.view.UseColorPaletteForBackground = 0
8080
self.view.BackgroundColorMode = "Gradient"
8181
self.view.CameraParallelProjection = 1
82-
self.view.Size = 0 # make the interactive widget non responsive
82+
self.view.Size = 0 # make the interactive widget non responsive
8383
self.representation = simple.Show(
8484
proxy=source.views["atmosphere_data"],
8585
view=self.view,

0 commit comments

Comments
 (0)