diff --git a/holonote/annotate/annotator.py b/holonote/annotate/annotator.py index 527777c..d93a921 100644 --- a/holonote/annotate/annotator.py +++ b/holonote/annotate/annotator.py @@ -497,8 +497,6 @@ def selection_enabled(self) -> bool: @selection_enabled.setter def selection_enabled(self, enabled: bool) -> None: self._selection_enabled = enabled - if not enabled: - self.select_by_index() @property def editable_enabled(self) -> bool: @@ -759,6 +757,9 @@ def __init__(self, spec: dict, **params): **params, ) + self._selection_enabled = True + self._editable_enabled = True + @classmethod def _infer_kdim_dtypes(self, element: hv.Element) -> dict: # Remove? @@ -873,3 +874,24 @@ def revert_to_snapshot(self): def set_regions(self, **items): super().set_regions(**items) self.refresh() + + @property + def selection_enabled(self) -> bool: + return self._selection_enabled + + @selection_enabled.setter + def selection_enabled(self, enabled: bool) -> None: + for v in self._elements.values(): + v.selection_enabled = enabled + + if not enabled: + self.select_by_index() + + @property + def editable_enabled(self) -> bool: + return self._editable_enabled + + @editable_enabled.setter + def editable_enabled(self, enabled: bool) -> None: + for v in self._elements.values(): + v.editable_enabled = enabled diff --git a/holonote/tests/test_annotators_element.py b/holonote/tests/test_annotators_element.py index 22a0325..262ab6f 100644 --- a/holonote/tests/test_annotators_element.py +++ b/holonote/tests/test_annotators_element.py @@ -143,3 +143,27 @@ def test_set_regions_multiple(multiple_annotators, element_range1d, element_rang output2 = output.iloc[0, 4] expected2 = "Test" assert output2 == expected2 + + +def test_editable_enabled(annotator_range1d, element_range1d): + annotator_range1d * element_range1d + + annotator_range1d.editable_enabled = False + for element in annotator_range1d._elements.values(): + assert not element.editable_enabled + + annotator_range1d.editable_enabled = True + for element in annotator_range1d._elements.values(): + assert element.editable_enabled + + +def test_selection_enabled(annotator_range1d, element_range1d): + annotator_range1d * element_range1d + + annotator_range1d.selection_enabled = False + for element in annotator_range1d._elements.values(): + assert not element.selection_enabled + + annotator_range1d.selection_enabled = True + for element in annotator_range1d._elements.values(): + assert element.selection_enabled