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 59fc5c66..d063ec69 100644 --- a/lcviz/helper.py +++ b/lcviz/helper.py @@ -10,7 +10,7 @@ __all__ = ['LCviz'] -custom_components = {'lcviz-editable-select': 'components/plugin_editable_select.vue'} +custom_components = {} # 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 38aecee0..1d2762cf 100644 --- a/lcviz/plugins/ephemeris/ephemeris.py +++ b/lcviz/plugins/ephemeris/ephemeris.py @@ -7,13 +7,12 @@ 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 -from lcviz.template_mixin import EditableSelectPluginComponent from lcviz.viewers import PhaseScatterView __all__ = ['Ephemeris'] @@ -31,7 +30,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. @@ -85,6 +84,7 @@ def __init__(self, *args, **kwargs): self._ephemerides = {} 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 852e6d89..7fa93dbc 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 a9b4ddc3..1c76348c 100644 --- a/lcviz/template_mixin.py +++ b/lcviz/template_mixin.py @@ -1,10 +1,8 @@ import jdaviz -from jdaviz.core.events import SnackbarMessage -from jdaviz.core.template_mixin import SelectPluginComponent from jdaviz.core.template_mixin import ViewerSelect from lcviz.events import ViewerRenamedMessage -__all__ = ['EditableSelectPluginComponent'] +__all__ = [] # TODO: remove this if/when jdaviz supports renaming viewers natively @@ -16,88 +14,3 @@ def __init__(self, *args, **kwargs): # monkey-patch upstream version so all plugins use the viewer-renamed logic 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)