From 09025f093db752224e19b64e87de754adf7b8507 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Wed, 2 Aug 2023 14:49:46 -0400 Subject: [PATCH 1/4] move editable select component upstream NOTE: requires changes in jdaviz and update to pin --- lcviz/components/plugin_editable_select.vue | 93 --------------------- lcviz/helper.py | 4 +- lcviz/plugins/ephemeris/ephemeris.py | 8 +- lcviz/plugins/ephemeris/ephemeris.vue | 4 +- lcviz/template_mixin.py | 92 +------------------- 5 files changed, 10 insertions(+), 191 deletions(-) delete mode 100644 lcviz/components/plugin_editable_select.vue diff --git a/lcviz/components/plugin_editable_select.vue b/lcviz/components/plugin_editable_select.vue deleted file mode 100644 index 72d231a3..00000000 --- a/lcviz/components/plugin_editable_select.vue +++ /dev/null @@ -1,93 +0,0 @@ - - - - - diff --git a/lcviz/helper.py b/lcviz/helper.py index 92a629bf..6bc12845 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -11,11 +11,11 @@ __all__ = ['LCviz'] +custom_components = {} _default_time_viewer_reference_name = 'flux-vs-time' -custom_components = {'lcviz-editable-select': 'components/plugin_editable_select.vue', - 'plugin-ephemeris-select': 'components/plugin_ephemeris_select.vue'} +custom_components = {'plugin-ephemeris-select': 'components/plugin_ephemeris_select.vue'} # Register pure vue component. This allows us to do recursive component instantiation only in the # vue component file diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py index 8929366c..65083997 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -7,14 +7,13 @@ from jdaviz.core.custom_traitlets import FloatHandleEmpty from jdaviz.core.events import (NewViewerMessage, ViewerAddedMessage, ViewerRemovedMessage) from jdaviz.core.registries import tray_registry -from jdaviz.core.template_mixin import (PluginTemplateMixin, SelectPluginComponent, - DatasetSelectMixin) +from jdaviz.core.template_mixin import (PluginTemplateMixin, DatasetSelectMixin, + SelectPluginComponent, EditableSelectPluginComponent) from jdaviz.core.user_api import PluginUserApi from lightkurve import periodogram, FoldedLightCurve from lcviz.events import EphemerisComponentChangedMessage, EphemerisChangedMessage -from lcviz.template_mixin import EditableSelectPluginComponent from lcviz.viewers import PhaseScatterView __all__ = ['Ephemeris'] @@ -33,7 +32,7 @@ class Ephemeris(PluginTemplateMixin, DatasetSelectMixin): Only the following attributes and methods are available through the public plugin API. - * ``component`` (:class:`~lcviz.template_mixin.EditableSelectPluginComponent`): + * ``component`` (:class:`~jdaviz.template_mixin.EditableSelectPluginComponent`): Label of the component corresponding to the active ephemeris. * :attr:`t0`: Zeropoint of the ephemeris. @@ -93,6 +92,7 @@ def __init__(self, *args, **kwargs): self._prev_wrap_at = _default_wrap_at self.component = EditableSelectPluginComponent(self, + name='ephemeris', mode='component_mode', edit_value='component_edit_value', items='component_items', diff --git a/lcviz/plugins/ephemeris/ephemeris.vue b/lcviz/plugins/ephemeris/ephemeris.vue index 093ecd74..4fe9418e 100644 --- a/lcviz/plugins/ephemeris/ephemeris.vue +++ b/lcviz/plugins/ephemeris/ephemeris.vue @@ -4,7 +4,7 @@ :link="'https://lcviz.readthedocs.io/en/'+vdocs+'/plugins.html#ephemeris'" :popout_button="popout_button"> - - + diff --git a/lcviz/template_mixin.py b/lcviz/template_mixin.py index 88efe605..23634f1d 100644 --- a/lcviz/template_mixin.py +++ b/lcviz/template_mixin.py @@ -4,13 +4,10 @@ from glue.core import HubListener import jdaviz -from jdaviz.core.events import SnackbarMessage -from jdaviz.core.template_mixin import SelectPluginComponent, DatasetSelect -from jdaviz.core.template_mixin import ViewerSelect +from jdaviz.core.template_mixin import ViewerSelect, SelectPluginComponent from lcviz.events import ViewerRenamedMessage, EphemerisComponentChangedMessage -__all__ = ['EditableSelectPluginComponent', - 'EphemerisSelect', 'EphemerisSelectMixin'] +__all__ = ['EphemerisSelect', 'EphemerisSelectMixin'] # TODO: remove this if/when jdaviz supports renaming viewers natively @@ -24,91 +21,6 @@ def __init__(self, *args, **kwargs): jdaviz.core.template_mixin.ViewerSelect = ViewerSelect -class EditableSelectPluginComponent(SelectPluginComponent): - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - if self.is_multiselect: - self._multiselect_changed() - self.add_observe(kwargs.get('mode'), self._mode_changed) - self.mode = 'select' # select, rename, add - self._on_add = kwargs.get('on_add', lambda *args: None) - self._on_rename = kwargs.get('on_rename', lambda *args: None) - self._on_remove = kwargs.get('on_remove', lambda *args: None) - - def _multiselect_changed(self): - # already subscribed to traitlet by SelectPluginComponent - if self.multiselect: - raise ValueError("EditableSelectPluginComponent does not support multiselect") - - def _selected_changed(self, event): - super()._selected_changed(event) - self.edit_value = self.selected - - def _mode_changed(self, event): - if self.mode == 'rename:accept': - try: - self.rename_choice(self.selected, self.edit_value) - except ValueError: - self.hub.broadcast(SnackbarMessage("Renaming ephemeris failed", - sender=self, color="error")) - else: - self.mode = 'select' - self.edit_value = self.selected - elif self.mode == 'add:accept': - try: - self.add_choice(self.edit_value) - except ValueError: - self.hub.broadcast(SnackbarMessage("Adding ephemeris failed", - sender=self, color="error")) - else: - self.mode = 'select' - self.edit_value = self.selected - elif self.mode == 'remove:accept': - self.remove_choice(self.edit_value) - if len(self.choices): - self.mode = 'select' - else: - self.mode = 'add' - - def _update_items(self): - self.items = [{"label": opt} for opt in self._manual_options] - - def _check_new_choice(self, label): - if not len(label): - raise ValueError("new choice must not be blank") - if label in self.choices: - raise ValueError(f"'{label}' is already a valid choice") - - def add_choice(self, label, set_as_selected=True): - self._check_new_choice(label) - self._manual_options += [label] - self._update_items() - self._on_add(label) - if set_as_selected: - self.selected = label - - def remove_choice(self, label=None): - if label is None: - label = self.selected - if label not in self.choices: - raise ValueError(f"'{label}' not one of available choices ({self.choices})") - self._manual_options.remove(label) - self._update_items() - self._apply_default_selection(skip_if_current_valid=True) - self._on_remove(label) - - def rename_choice(self, old, new): - if old not in self.choices: - raise ValueError(f"'{old}' not one of available choices ({self.choices})") - self._check_new_choice(new) - was_selected = self.selected == old - self._manual_options[self._manual_options.index(old)] = new - self._update_items() - if was_selected: - self.selected = new - self._on_rename(old, new) - - class EphemerisSelect(SelectPluginComponent): """ Plugin select for ephemeris components defined by the Ephemeris plugin. From bfd6c1ff5bcb4c499a73cbb614dc6831fc6849ac Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 8 Aug 2023 11:38:41 -0400 Subject: [PATCH 2/4] update callbacks * upstream now defaults to calling the callback before the selection is updated, with new callback names to trigger AFTER the selection is updated --- lcviz/plugins/ephemeris/ephemeris.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lcviz/plugins/ephemeris/ephemeris.py b/lcviz/plugins/ephemeris/ephemeris.py index 65083997..d33b2f69 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -99,8 +99,9 @@ def __init__(self, *args, **kwargs): selected='component_selected', manual_options=['default'], on_add=self._on_component_add, - on_rename=self._on_component_rename, - on_remove=self._on_component_remove) + on_rename_after_selection=self._on_component_rename, # noqa + on_remove_after_selection=self._on_component_remove) # noqa + # force the original entry in ephemerides with defaults self._change_component() From c7ac38a3a0c456964f26d07403e1dfac5fd78498 Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Tue, 29 Aug 2023 15:39:41 -0400 Subject: [PATCH 3/4] update jdaviz pin --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ea224bf6..930cc0db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ classifiers = [ ] dependencies = [ "astropy>=5.2", - "jdaviz>=3.6", + "jdaviz>=3.7", "lightkurve@git+https://github.com/lightkurve/lightkurve", # until https://github.com/lightkurve/lightkurve/pull/1342 is in a release (anything after 2.4.0) ] dynamic = [ From a447db6e4d3463c962e472bea87900b3f6fdcaff Mon Sep 17 00:00:00 2001 From: Kyle Conroy Date: Fri, 22 Sep 2023 08:26:18 -0400 Subject: [PATCH 4/4] fix missing import --- lcviz/template_mixin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lcviz/template_mixin.py b/lcviz/template_mixin.py index 23634f1d..6765d87f 100644 --- a/lcviz/template_mixin.py +++ b/lcviz/template_mixin.py @@ -4,7 +4,7 @@ from glue.core import HubListener import jdaviz -from jdaviz.core.template_mixin import ViewerSelect, SelectPluginComponent +from jdaviz.core.template_mixin import ViewerSelect, DatasetSelect, SelectPluginComponent from lcviz.events import ViewerRenamedMessage, EphemerisComponentChangedMessage __all__ = ['EphemerisSelect', 'EphemerisSelectMixin']