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..d33b2f69 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,14 +92,16 @@ 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', 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() 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..6765d87f 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, DatasetSelect, 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. 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 = [