Skip to content

Commit 0e7add8

Browse files
kecnrypllim
andauthored
plugin method to open in tray (#1559)
* plugin method to open self in tray * convenience method on the plugin object to open the sidebar and open the plugin enty (if not already opened). This essentially moves existing object in the tool (to open plot options or export) to the plugins, to be more easily accessible from the API * Apply suggestions from code review Co-authored-by: P. L. Lim <[email protected]> Co-authored-by: P. L. Lim <[email protected]>
1 parent 7c10260 commit 0e7add8

File tree

13 files changed

+49
-66
lines changed

13 files changed

+49
-66
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ New Features
1313
- New ``jdaviz.core.region_translators.regions2roi()`` function to convert certain
1414
``regions`` shapes into ``glue`` ROIs. [#1463]
1515

16+
- New plugin-level ``open_in_tray`` method to programmatically show the plugin. [#1559]
17+
1618
Cubeviz
1719
^^^^^^^
1820

jdaviz/configs/cubeviz/plugins/slice/slice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
from jdaviz.core.events import AddDataMessage, SliceToolStateMessage, SliceSelectSliceMessage
1010
from jdaviz.core.registries import tray_registry
11-
from jdaviz.core.template_mixin import TemplateMixin
11+
from jdaviz.core.template_mixin import PluginTemplateMixin
1212

1313
__all__ = ['Slice']
1414

1515

1616
@tray_registry('cubeviz-slice', label="Slice")
17-
class Slice(TemplateMixin):
17+
class Slice(PluginTemplateMixin):
1818
template_file = __file__, "slice.vue"
1919
slider = Any(0).tag(sync=True)
2020
wavelength = Any(-1).tag(sync=True)

jdaviz/configs/default/plugins/export_plot/export_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from jdaviz.core.registries import tray_registry
2-
from jdaviz.core.template_mixin import TemplateMixin, ViewerSelectMixin
2+
from jdaviz.core.template_mixin import PluginTemplateMixin, ViewerSelectMixin
33

44
__all__ = ['ExportViewer']
55

66

77
@tray_registry('g-export-plot', label="Export Plot")
8-
class ExportViewer(TemplateMixin, ViewerSelectMixin):
8+
class ExportViewer(PluginTemplateMixin, ViewerSelectMixin):
99
template_file = __file__, "export_plot.vue"
1010

1111
def __init__(self, *args, **kwargs):

jdaviz/configs/default/plugins/gaussian_smooth/gaussian_smooth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from jdaviz.core.custom_traitlets import FloatHandleEmpty
1010
from jdaviz.core.events import SnackbarMessage
1111
from jdaviz.core.registries import tray_registry
12-
from jdaviz.core.template_mixin import TemplateMixin, DatasetSelectMixin, AddResultsMixin
12+
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin
1313

1414
__all__ = ['GaussianSmooth']
1515

@@ -19,7 +19,7 @@
1919

2020

2121
@tray_registry('g-gaussian-smooth', label="Gaussian Smooth")
22-
class GaussianSmooth(TemplateMixin, DatasetSelectMixin, AddResultsMixin):
22+
class GaussianSmooth(PluginTemplateMixin, DatasetSelectMixin, AddResultsMixin):
2323
template_file = __file__, "gaussian_smooth.vue"
2424
stddev = FloatHandleEmpty(1).tag(sync=True)
2525
selected_data_is_1d = Bool(True).tag(sync=True)

jdaviz/configs/default/plugins/metadata_viewer/metadata_viewer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from traitlets import Bool, List, observe
22

33
from jdaviz.core.registries import tray_registry
4-
from jdaviz.core.template_mixin import TemplateMixin, DatasetSelectMixin
4+
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin
55
from jdaviz.utils import PRIHDR_KEY, COMMENTCARD_KEY
66

77
__all__ = ['MetadataViewer']
88

99

1010
@tray_registry('g-metadata-viewer', label="Metadata Viewer")
11-
class MetadataViewer(TemplateMixin, DatasetSelectMixin):
11+
class MetadataViewer(PluginTemplateMixin, DatasetSelectMixin):
1212
template_file = __file__, "metadata_viewer.vue"
1313
has_metadata = Bool(False).tag(sync=True)
1414
has_primary = Bool(False).tag(sync=True)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
from glue_jupyter.common.toolbar_vuetify import read_icon
99

1010
from jdaviz.core.registries import tray_registry
11-
from jdaviz.core.template_mixin import (TemplateMixin, ViewerSelect, LayerSelect,
11+
from jdaviz.core.template_mixin import (PluginTemplateMixin, ViewerSelect, LayerSelect,
1212
PlotOptionsSyncState)
1313
from jdaviz.core.tools import ICON_DIR
1414

1515
__all__ = ['PlotOptions']
1616

1717

1818
@tray_registry('g-plot-options', label="Plot Options")
19-
class PlotOptions(TemplateMixin):
19+
class PlotOptions(PluginTemplateMixin):
2020
template_file = __file__, "plot_options.vue"
2121

2222
# multiselect is shared between viewer and layer

jdaviz/configs/default/plugins/subset_plugin/subset_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from jdaviz.core.events import SnackbarMessage
1010
from jdaviz.core.registries import tray_registry
11-
from jdaviz.core.template_mixin import TemplateMixin, SubsetSelect
11+
from jdaviz.core.template_mixin import PluginTemplateMixin, SubsetSelect
1212

1313
__all__ = ['SubsetPlugin']
1414

@@ -22,7 +22,7 @@
2222

2323

2424
@tray_registry('g-subset-plugin', label="Subset Tools")
25-
class SubsetPlugin(TemplateMixin):
25+
class SubsetPlugin(PluginTemplateMixin):
2626
template_file = __file__, "subset_plugin.vue"
2727
select = List([]).tag(sync=True)
2828
subset_items = List([]).tag(sync=True)

jdaviz/configs/imviz/plugins/aper_phot_simple/aper_phot_simple.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
from jdaviz.core.events import SnackbarMessage
2323
from jdaviz.core.region_translators import regions2aperture
2424
from jdaviz.core.registries import tray_registry
25-
from jdaviz.core.template_mixin import TemplateMixin, DatasetSelectMixin, SubsetSelect
25+
from jdaviz.core.template_mixin import PluginTemplateMixin, DatasetSelectMixin, SubsetSelect
2626
from jdaviz.utils import bqplot_clear_figure, PRIHDR_KEY
2727

2828
__all__ = ['SimpleAperturePhotometry']
2929

3030

3131
@tray_registry('imviz-aper-phot-simple', label="Imviz Simple Aperture Photometry")
32-
class SimpleAperturePhotometry(TemplateMixin, DatasetSelectMixin):
32+
class SimpleAperturePhotometry(PluginTemplateMixin, DatasetSelectMixin):
3333
template_file = __file__, "aper_phot_simple.vue"
3434
subset_items = List([]).tag(sync=True)
3535
subset_selected = Unicode("").tag(sync=True)

jdaviz/configs/mosviz/plugins/slit_overlay/slit_overlay.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from jdaviz.core.registries import tray_registry
2-
from jdaviz.core.template_mixin import TemplateMixin
2+
from jdaviz.core.template_mixin import PluginTemplateMixin
33
from jdaviz.core.events import SnackbarMessage
44

55
from traitlets import Bool
@@ -43,7 +43,7 @@ def jwst_header_to_skyregion(header):
4343

4444

4545
@tray_registry('g-slit-overlay', label="Slit Overlay")
46-
class SlitOverlay(TemplateMixin):
46+
class SlitOverlay(PluginTemplateMixin):
4747
template_file = __file__, "slit_overlay.vue"
4848
visible = Bool(True).tag(sync=True)
4949

jdaviz/configs/specviz/plugins/line_analysis/tests/test_line_analysis.py

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import numpy as np
44
from glue.core.roi import XRangeROI
55
from glue.core.edit_subset_mode import NewMode
6-
from ipywidgets.widgets import widget_serialization
76

87
from jdaviz.configs.specviz.plugins.line_analysis.line_analysis import _coerce_unit
98
from jdaviz.core.events import LineIdentifyMessage
@@ -14,10 +13,8 @@ def test_plugin(specviz_helper, spectrum1d):
1413
label = "Test 1D Spectrum"
1514
specviz_helper.load_spectrum(spectrum1d, data_label=label)
1615

17-
specviz_helper.app.state.drawer = True
18-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
19-
plugin_index = tray_names.index('specviz-line-analysis')
20-
specviz_helper.app.state.tray_items_open = [plugin_index]
16+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
17+
plugin.open_in_tray()
2118

2219
# continuum should be created, plotted, and visible
2320
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -33,8 +30,6 @@ def test_plugin(specviz_helper, spectrum1d):
3330
sv.apply_roi(XRangeROI(6500, 7400))
3431
specviz_helper.app.state.drawer = True
3532

36-
ipy_model_id = specviz_helper.app.state.tray_items[plugin_index]['widget']
37-
plugin = widget_serialization['from_json'](ipy_model_id, None)
3833
assert 'Subset 1' in plugin.spectral_subset.labels
3934
plugin.selected_subset = 'Subset 1'
4035
plugin.selected_continuum = 'Surrounding'
@@ -121,10 +116,8 @@ def test_continuum_surrounding_spectral_subset(specviz_helper, spectrum1d):
121116
label = "Test 1D Spectrum"
122117
specviz_helper.load_spectrum(spectrum1d, data_label=label)
123118

124-
specviz_helper.app.state.drawer = True
125-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
126-
plugin_index = tray_names.index('specviz-line-analysis')
127-
specviz_helper.app.state.tray_items_open = [plugin_index]
119+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
120+
plugin.open_in_tray()
128121

129122
# continuum should be created, plotted, and visible
130123
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -150,10 +143,8 @@ def test_continuum_spectral_same_value(specviz_helper, spectrum1d):
150143
label = "Test 1D Spectrum"
151144
specviz_helper.load_spectrum(spectrum1d, data_label=label)
152145

153-
specviz_helper.app.state.drawer = True
154-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
155-
plugin_index = tray_names.index('specviz-line-analysis')
156-
specviz_helper.app.state.tray_items_open = [plugin_index]
146+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
147+
plugin.open_in_tray()
157148

158149
# continuum should be created, plotted, and visible
159150
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -179,10 +170,8 @@ def test_continuum_surrounding_invalid_width(specviz_helper, spectrum1d):
179170
label = "Test 1D Spectrum"
180171
specviz_helper.load_spectrum(spectrum1d, data_label=label)
181172

182-
specviz_helper.app.state.drawer = True
183-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
184-
plugin_index = tray_names.index('specviz-line-analysis')
185-
specviz_helper.app.state.tray_items_open = [plugin_index]
173+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
174+
plugin.open_in_tray()
186175

187176
# continuum should be created, plotted, and visible
188177
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -206,10 +195,8 @@ def test_continuum_subset_spectral_entire(specviz_helper, spectrum1d):
206195
label = "Test 1D Spectrum"
207196
specviz_helper.load_spectrum(spectrum1d, data_label=label)
208197

209-
specviz_helper.app.state.drawer = True
210-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
211-
plugin_index = tray_names.index('specviz-line-analysis')
212-
specviz_helper.app.state.tray_items_open = [plugin_index]
198+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
199+
plugin.open_in_tray()
213200

214201
# continuum should be created, plotted, and visible
215202
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -235,10 +222,8 @@ def test_continuum_subset_spectral_subset2(specviz_helper, spectrum1d):
235222
label = "Test 1D Spectrum"
236223
specviz_helper.load_spectrum(spectrum1d, data_label=label)
237224

238-
specviz_helper.app.state.drawer = True
239-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
240-
plugin_index = tray_names.index('specviz-line-analysis')
241-
specviz_helper.app.state.tray_items_open = [plugin_index]
225+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
226+
plugin.open_in_tray()
242227

243228
# continuum should be created, plotted, and visible
244229
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -270,10 +255,8 @@ def test_continuum_surrounding_no_right(specviz_helper, spectrum1d):
270255
label = "Test 1D Spectrum"
271256
specviz_helper.load_spectrum(spectrum1d, data_label=label)
272257

273-
specviz_helper.app.state.drawer = True
274-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
275-
plugin_index = tray_names.index('specviz-line-analysis')
276-
specviz_helper.app.state.tray_items_open = [plugin_index]
258+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
259+
plugin.open_in_tray()
277260

278261
# continuum should be created, plotted, and visible
279262
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -300,10 +283,8 @@ def test_continuum_surrounding_no_left(specviz_helper, spectrum1d):
300283
label = "Test 1D Spectrum"
301284
specviz_helper.load_spectrum(spectrum1d, data_label=label)
302285

303-
specviz_helper.app.state.drawer = True
304-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
305-
plugin_index = tray_names.index('specviz-line-analysis')
306-
specviz_helper.app.state.tray_items_open = [plugin_index]
286+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
287+
plugin.open_in_tray()
307288

308289
# continuum should be created, plotted, and visible
309290
sv = specviz_helper.app.get_viewer('spectrum-viewer')
@@ -330,10 +311,8 @@ def test_subset_changed(specviz_helper, spectrum1d):
330311
label = "Test 1D Spectrum"
331312
specviz_helper.load_spectrum(spectrum1d, data_label=label)
332313

333-
specviz_helper.app.state.drawer = True
334-
tray_names = [ti['name'] for ti in specviz_helper.app.state.tray_items]
335-
plugin_index = tray_names.index('specviz-line-analysis')
336-
specviz_helper.app.state.tray_items_open = [plugin_index]
314+
plugin = specviz_helper.app.get_tray_item_from_name('specviz-line-analysis')
315+
plugin.open_in_tray()
337316

338317
# continuum should be created, plotted, and visible
339318
sv = specviz_helper.app.get_viewer('spectrum-viewer')

0 commit comments

Comments
 (0)