From f72981ea9969ec803af4e657a705ba416cafbc51 Mon Sep 17 00:00:00 2001 From: Ricky O'Steen <39831871+rosteen@users.noreply.github.com> Date: Wed, 1 Nov 2023 11:47:12 -0400 Subject: [PATCH] Backport PR #2541: Don't try to update viewer state if it was deleted --- CHANGES.rst | 3 +++ .../default/plugins/plot_options/plot_options.py | 3 ++- jdaviz/configs/imviz/tests/test_viewers.py | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index e52bcfaf6b..9f6dd8fae7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -12,6 +12,9 @@ Cubeviz Imviz ^^^^^ +- Plot options layer selection no longer gets stuck in some cases when deleting + the currently selected viewer. [#2541] + Mosviz ^^^^^^ diff --git a/jdaviz/configs/default/plugins/plot_options/plot_options.py b/jdaviz/configs/default/plugins/plot_options/plot_options.py index 4d52227929..d9642f250f 100644 --- a/jdaviz/configs/default/plugins/plot_options/plot_options.py +++ b/jdaviz/configs/default/plugins/plot_options/plot_options.py @@ -564,7 +564,8 @@ def _update_stretch_histogram(self, msg={}): viewer_label_old = msg.get('old') if isinstance(viewer_label_old, list): viewer_label_old = viewer_label_old[0] - if len(viewer_label_old): + # If the previously selected viewer was deleted, we don't need to do this. + if viewer_label_old in self.app._viewer_store: vs_old = self.app.get_viewer(viewer_label_old).state for attr in ('x_min', 'x_max', 'y_min', 'y_max'): vs_old.remove_callback(attr, self._update_stretch_histogram) diff --git a/jdaviz/configs/imviz/tests/test_viewers.py b/jdaviz/configs/imviz/tests/test_viewers.py index 46a92533f3..852bd6e585 100644 --- a/jdaviz/configs/imviz/tests/test_viewers.py +++ b/jdaviz/configs/imviz/tests/test_viewers.py @@ -6,6 +6,7 @@ from jdaviz.core.config import get_configuration from jdaviz.configs.imviz.helper import Imviz from jdaviz.configs.imviz.plugins.viewers import ImvizImageView +from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_NoWCS @pytest.mark.parametrize( @@ -94,3 +95,17 @@ def test_mastviz_config(): assert im.app.get_viewer_ids() == ['mastviz-0'] assert im.app.data_collection[0].shape == (2, 2) + + +class TestDeleteData(BaseImviz_WCS_NoWCS): + + def test_plot_options_after_destroy(self): + self.imviz.create_image_viewer(viewer_name="imviz-1") + self.imviz.app.add_data_to_viewer('imviz-1', 'no_wcs[SCI,1]') + + po = self.imviz.plugins['Plot Options'] + po.open_in_tray() + po.viewer = "imviz-1" + po.stretch_function = "Square Root" + self.imviz.destroy_viewer("imviz-1") + assert len(po.layer.choices) == 2