Skip to content

Commit 309b76b

Browse files
authoredNov 1, 2023
Don't try to update viewer state if it was deleted (#2541)
* Don't try to update viewer state if it was deleted * Add changelog * Consolidate redundant logic * Add test Add test Fix codestyle codestyle * Test that actually fails on main? * This fails in notebook on main at least
1 parent bdce2af commit 309b76b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed
 

‎CHANGES.rst

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ Cubeviz
104104
Imviz
105105
^^^^^
106106

107+
- Plot options layer selection no longer gets stuck in some cases when deleting
108+
the currently selected viewer. [#2541]
109+
107110
Mosviz
108111
^^^^^^
109112

‎jdaviz/configs/default/plugins/plot_options/plot_options.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,8 @@ def _update_stretch_histogram(self, msg={}):
659659
viewer_label_old = msg.get('old')
660660
if isinstance(viewer_label_old, list):
661661
viewer_label_old = viewer_label_old[0]
662-
if len(viewer_label_old):
662+
# If the previously selected viewer was deleted, we don't need to do this.
663+
if viewer_label_old in self.app._viewer_store:
663664
vs_old = self.app.get_viewer(viewer_label_old).state
664665
for attr in ('x_min', 'x_max', 'y_min', 'y_max'):
665666
vs_old.remove_callback(attr, self._update_stretch_histogram)

‎jdaviz/configs/imviz/tests/test_viewers.py

+15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from jdaviz.core.config import get_configuration
77
from jdaviz.configs.imviz.helper import Imviz
88
from jdaviz.configs.imviz.plugins.viewers import ImvizImageView
9+
from jdaviz.configs.imviz.tests.utils import BaseImviz_WCS_NoWCS
910

1011

1112
@pytest.mark.parametrize(
@@ -94,3 +95,17 @@ def test_mastviz_config():
9495

9596
assert im.app.get_viewer_ids() == ['mastviz-0']
9697
assert im.app.data_collection[0].shape == (2, 2)
98+
99+
100+
class TestDeleteData(BaseImviz_WCS_NoWCS):
101+
102+
def test_plot_options_after_destroy(self):
103+
self.imviz.create_image_viewer(viewer_name="imviz-1")
104+
self.imviz.app.add_data_to_viewer('imviz-1', 'no_wcs[SCI,1]')
105+
106+
po = self.imviz.plugins['Plot Options']
107+
po.open_in_tray()
108+
po.viewer = "imviz-1"
109+
po.stretch_function = "Square Root"
110+
self.imviz.destroy_viewer("imviz-1")
111+
assert len(po.layer.choices) == 2

0 commit comments

Comments
 (0)