diff --git a/micro_sam/sam_annotator/_annotator.py b/micro_sam/sam_annotator/_annotator.py index 127c09e0..fcd58cc4 100644 --- a/micro_sam/sam_annotator/_annotator.py +++ b/micro_sam/sam_annotator/_annotator.py @@ -72,6 +72,20 @@ def _create_keybindings(self): def _segment(viewer): self._widgets["segment"](viewer) + # Note: we also need to over-write the keybindings for specific layers. + # See https://github.com/napari/napari/issues/7302 for details. + # Here, we need to over-write the 's' keybinding for both of the prompt layers. + prompt_layer = self._viewer.layers["prompts"] + point_prompt_layer = self._viewer.layers["point_prompts"] + + @prompt_layer.bind_key("s", overwrite=True) + def _segment_prompts(event): + self._widgets["segment"](self._viewer) + + @point_prompt_layer.bind_key("s", overwrite=True) + def _segment_point_prompts(event): + self._widgets["segment"](self._viewer) + @self._viewer.bind_key("c", overwrite=True) def _commit(viewer): self._widgets["commit"](viewer)