Skip to content

Commit

Permalink
Merge pull request #1691 from pllim/linelist-no-data-no-activate
Browse files Browse the repository at this point in the history
Disable Line Lists when there is no data
  • Loading branch information
pllim authored Oct 5, 2022
2 parents 4c2a3dc + 38ca560 commit 3df8b3b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ Mosviz
Specviz
^^^^^^^

- Line Lists plugin now disabled if no data is loaded instead of letting user
load a list list and crash. [#1691]

Specviz2d
^^^^^^^^^

Expand Down
10 changes: 10 additions & 0 deletions jdaviz/configs/default/plugins/line_lists/line_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ def __init__(self, *args, **kwargs):
self._viewer.state.add_callback("x_max",
lambda x_max: self._on_spectrum_viewer_limits_changed())

self._disable_if_no_data()

def _disable_if_no_data(self):
if len(self.app.data_collection) == 0:
self.disabled_msg = 'Line Lists unavailable when no data is loaded'
else:
self.disabled_msg = ''

def _on_viewer_data_changed(self, msg=None):
"""
Callback method for when data is added or removed from a viewer, or
Expand All @@ -131,6 +139,8 @@ def _on_viewer_data_changed(self, msg=None):
msg : `glue.core.Message`
The glue message passed to this callback method.
"""
self._disable_if_no_data()

self._viewer_id = self.app._viewer_item_by_reference(
'spectrum-viewer').get('id')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ def test_line_lists(specviz_helper):


def test_redshift(specviz_helper, spectrum1d):
# Also test that plugin is disabled before data is loaded.
plg = specviz_helper.plugins['Line Lists']
assert plg._obj.disabled_msg

label = "Test 1D Spectrum"
specviz_helper.load_spectrum(spectrum1d, data_label=label)

assert not plg._obj.disabled_msg

lt = QTable()
lt['linename'] = ['O III', 'Halpha']
lt['rest'] = [5007, 6563]*u.AA
Expand Down

0 comments on commit 3df8b3b

Please sign in to comment.