Skip to content

Commit

Permalink
Improve overwrite warning behavior in export (#3094)
Browse files Browse the repository at this point in the history
* Use normalize_filename and overwrite_warn for plugin plots

* Clear overwrite warning overlay after confirming

* Changelog

* Codestyle
  • Loading branch information
rosteen authored Jul 18, 2024
1 parent f35af23 commit df59fd7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ Bug Fixes

- Previous zoom tool is optimized to only issue one zoom update to the viewer. [#2949]

- Fixes overwrite behavior for plugin plots, and properly closes overwrite warning overlay after confirmation. [#3094]

Cubeviz
^^^^^^^

Expand Down
16 changes: 8 additions & 8 deletions jdaviz/configs/default/plugins/export/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,7 @@ def export(self, filename=None, show_dialog=None, overwrite=False,
elif len(self.plugin_plot.selected):
plot = self.plugin_plot.selected_obj._obj
filetype = self.plugin_plot_format.selected

if len(filename):
if not filename.endswith(filetype):
filename += f".{filetype}"
filename = Path(filename).expanduser()
else:
filename = None
filename = self._normalize_filename(filename, filetype, overwrite=overwrite)

if not plot._plugin.is_active:
# force an update to the plot. This requires the plot to have set
Expand All @@ -474,11 +468,16 @@ def export(self, filename=None, show_dialog=None, overwrite=False,
# in case one was never created in the parent plugin
self.plugin_plot_selected_widget = f'IPY_MODEL_{plot.model_id}'

if self.overwrite_warn and not overwrite:
if raise_error_for_overwrite:
raise FileExistsError(f"{filename} exists but overwrite={overwrite}")
return

self.save_figure(plot, filename, filetype, show_dialog=show_dialog)

elif len(self.plugin_table.selected):
filetype = self.plugin_table_format.selected
filename = self._normalize_filename(filename, filetype)
filename = self._normalize_filename(filename, filetype, overwrite=overwrite)
if self.overwrite_warn and not overwrite:
if raise_error_for_overwrite:
raise FileExistsError(f"{filename} exists but overwrite=False")
Expand Down Expand Up @@ -539,6 +538,7 @@ def vue_overwrite_from_ui(self, *args, **kwargs):
if filename is not None:
self.hub.broadcast(SnackbarMessage(
f"Exported to {filename} (overwrite)", sender=self, color="success"))
self.overwrite_warn = False

def save_figure(self, viewer, filename=None, filetype="png", show_dialog=False):
if filetype == "png":
Expand Down

0 comments on commit df59fd7

Please sign in to comment.