Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions napari_animation/_hookimpls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ def napari_experimental_provide_dock_widget():
"add_vertical_stretch": False,
}
return AnimationWidget, widget_options


@napari_hook_implementation
def napari_register_actions():
return [
(AnimationWidget, "Alt-f", AnimationWidget._capture_keyframe_callback)
(AnimationWidget, "Alt-r", AnimationWidget._replace_keyframe_callback)
(AnimationWidget, "Alt-d", AnimationWidget._capture_keyframe_callback)
(AnimationWidget, "Alt-a", lambda w: w.animation.key_frames.select_next())
(AnimationWidget, "Alt-b", lambda w: w.animation.key_frames.select_previous())
# ('napari.Viewer', 'alt-f', viewer_function) # To register action to viewer (not used, but illustrative)
# ('napari.layers.Points', 'alt-p', points_function) # To register action to points layer (not used, but illustrative)
]
18 changes: 0 additions & 18 deletions napari_animation/_qt/animation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,6 @@ def __init__(self, viewer: Viewer, parent=None):
self._add_keybind_callbacks()
self._add_callbacks()

def _add_keybind_callbacks(self):
"""Bind keys"""
self._keybindings = [
("Alt-f", self._capture_keyframe_callback),
("Alt-r", self._replace_keyframe_callback),
("Alt-d", self._delete_keyframe_callback),
("Alt-a", lambda e: self.animation.key_frames.select_next()),
("Alt-b", lambda e: self.animation.key_frames.select_previous()),
]
for key, cb in self._keybindings:
self.viewer.bind_key(key, cb)

def _add_callbacks(self):
"""Establish callbacks"""
self.keyframesListControlWidget.deleteButton.clicked.connect(
Expand Down Expand Up @@ -176,9 +164,3 @@ def _nframes_changed(self, event):
self.animationSlider.setEnabled(has_frames)
self.animationSlider.blockSignals(has_frames)
self.animationSlider.setMaximum(event.value - 1 if has_frames else 0)

def closeEvent(self, ev) -> None:
# release callbacks
for key, _ in self._keybindings:
self.viewer.bind_key(key, None)
return super().closeEvent(ev)