Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop inserting in capture (changing in-place) and instead just add and then remove frames #233

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 7 additions & 1 deletion napari_animation/_qt/animation_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ def _capture_keyframe_callback(self, event=None):

def _replace_keyframe_callback(self, event=None):
"""Replace current key-frame with new view"""
self.animation.capture_keyframe(**self._input_state(), insert=False)
if self.animation.key_frames.selection.active:
self.animation.capture_keyframe(**self._input_state())
self.animation.key_frames.select_previous()
self.animation.key_frames.remove_selected()
self.animation.key_frames.select_next()
else:
raise ValueError("No selected keyframe to replace !")

def _delete_keyframe_callback(self, event=None):
"""Delete current key-frame"""
Expand Down
10 changes: 0 additions & 10 deletions napari_animation/_tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ def test_set_to_key_frame(animation_with_key_frames):
assert animation.key_frames.selection.active == animation.key_frames[i]


def test_replace_keyframe(animation_with_key_frames):
"""Test Animation.set_to_key_frame()"""
animation = animation_with_key_frames
assert len(animation.key_frames) == 2
animation.capture_keyframe(insert=False)
animation.capture_keyframe(insert=False)
animation.capture_keyframe(insert=False)
assert len(animation.key_frames) == 2


def test_get_viewer_state(empty_animation):
"""Test ViewerState.from_viewer()"""
animation = empty_animation
Expand Down
18 changes: 5 additions & 13 deletions napari_animation/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from itertools import count
from pathlib import Path
from time import sleep
from typing import Optional

import imageio
import numpy as np
Expand Down Expand Up @@ -61,9 +62,9 @@ def __init__(self, viewer):
self._filename = None

def capture_keyframe(
self, steps=15, ease=Easing.LINEAR, insert=True, position: int = None
self, steps=15, ease=Easing.LINEAR, position: Optional[int] = None
):
"""Record current key-frame
"""Record current key-frame and insert into list

Parameters
----------
Expand All @@ -73,9 +74,6 @@ def capture_keyframe(
If provided this method should make from `[0, 1]` to `[0, 1]` and will
be used as an easing function for the transition between the last state
and captured one.
insert : bool
If captured key-frame should insert into current list or replace the current
keyframe.
position : int, optional
If provided, place new frame at this index. By default, inserts at current
active frame.
Expand All @@ -86,18 +84,12 @@ def capture_keyframe(
if active_keyframe:
position = self.key_frames.index(active_keyframe)
else:
if insert:
position = -1
else:
raise ValueError("No selected keyframe to replace !")
position = -1

new_frame = KeyFrame.from_viewer(self.viewer, steps=steps, ease=ease)
new_frame.name = f"Key Frame {next(self._keyframe_counter)}"

if insert:
self.key_frames.insert(position + 1, new_frame)
else:
self.key_frames[position] = new_frame
self.key_frames.insert(position + 1, new_frame)

def set_to_keyframe(self, frame: int):
"""Set the viewer to a given key-frame
Expand Down