Skip to content

Commit

Permalink
call callback before changing selection
Browse files Browse the repository at this point in the history
* fixes color reverting when renaming footprint
* lcviz still needs callbacks AFTER the selection is changed
  • Loading branch information
kecnry committed Aug 8, 2023
1 parent d878ef1 commit fa6f2e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 0 additions & 1 deletion jdaviz/configs/imviz/plugins/footprints/footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def instrument_in(instruments=[]):
'v2_offset', 'v3_offset',
'footprint_regions'))


def _get_marks(self, viewer, footprint=None):
matches = [mark for mark in viewer.figure.marks
if (isinstance(mark, FootprintOverlay) and
Expand Down
22 changes: 17 additions & 5 deletions jdaviz/core/template_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,17 @@ def __init__(self, *args, **kwargs):
name : str
the user-friendly name of the items, used in error message in place of "entry"
on_add : callable
callback when a new item is added
callback when a new item is added, but before the selection is updated
on_add_after_selection : callable
callback when a new item is added and the selection is updated
on_rename : callable
callback when an item is renamed
callback when an item is renamed, but before the selection is updated
on_rename_after_selection : callable
callback when an item is renamed and the selection is updated
on_remove : callable
callback when an item is removed
callback when an item is removed, but before the selection is updated
on_remove_after_selection : callable
callback when an item is removed and the selection is updated
"""
super().__init__(*args, **kwargs)
if self.is_multiselect:
Expand All @@ -812,8 +818,11 @@ def __init__(self, *args, **kwargs):
self.mode = 'select' # select, rename, add
self._name = kwargs.get('name', 'entry') # used for error messages
self._on_add = kwargs.get('on_add', lambda *args: None)
self._on_add_after_selection = kwargs.get('on_add_after_selection', lambda *args: None)
self._on_rename = kwargs.get('on_rename', lambda *args: None)
self._on_rename_after_selection = kwargs.get('on_rename_after_selection', lambda *args: None) # noqa
self._on_remove = kwargs.get('on_remove', lambda *args: None)
self._on_remove_after_selection = kwargs.get('on_remove_after_selection', lambda *args: None) # noqa

def _multiselect_changed(self):
# already subscribed to traitlet by SelectPluginComponent
Expand Down Expand Up @@ -876,6 +885,7 @@ def add_choice(self, label, set_as_selected=True):
self._on_add(label)
if set_as_selected:
self.selected = label
self._on_add_after_selection(label)

def remove_choice(self, label=None):
"""
Expand All @@ -893,8 +903,9 @@ def remove_choice(self, label=None):
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)
self._apply_default_selection(skip_if_current_valid=True)
self._on_remove_after_selection(label)

def rename_choice(self, old, new):
"""
Expand All @@ -913,9 +924,10 @@ def rename_choice(self, old, new):
was_selected = self.selected == old
self._manual_options[self._manual_options.index(old)] = new
self._update_items()
self._on_rename(old, new)
if was_selected:
self.selected = new
self._on_rename(old, new)
self._on_rename_after_selection(old, new)


class LayerSelect(SelectPluginComponent):
Expand Down

0 comments on commit fa6f2e6

Please sign in to comment.