From c3447e873bb33ffa2ca6b6f8e9e16e3c86223a1c Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:44:00 -0400 Subject: [PATCH] Backport PR #3094: Improve overwrite warning behavior in export --- CHANGES.rst | 2 ++ jdaviz/configs/default/plugins/export/export.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index fcf3cca46b..81c3313155 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ^^^^^^^ diff --git a/jdaviz/configs/default/plugins/export/export.py b/jdaviz/configs/default/plugins/export/export.py index f6dd48eb38..f8611eb680 100644 --- a/jdaviz/configs/default/plugins/export/export.py +++ b/jdaviz/configs/default/plugins/export/export.py @@ -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 @@ -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") @@ -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):