Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Backport PR #3094 on branch v3.10.x (Improve overwrite warning behavior in export) #3100

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 @@ -434,13 +434,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 @@ -451,11 +445,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 @@ -516,6 +515,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):

Expand Down
Loading