-
Notifications
You must be signed in to change notification settings - Fork 26
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
Synced slider with frame index rather than active keyframe #99
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cac71bf
Synced slider with movie_frame_index rather than only active_keyframe…
Fifourche 0e056a6
Switched event to an evented hidden attribute '_set_frame_index' for …
Fifourche 8ee471b
Change way to compute the frame index of keyframe. Other minor correc…
Fifourche 63269bd
Merge branch 'main' of https://github.com/napari/napari-animation int…
Fifourche 643e5fc
Switched to a _current_index attribute for FrameSequence, and added m…
Fifourche File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,10 @@ def __init__(self, key_frames: KeyFrameList) -> None: | |
key_frames.events.changed.connect(self._rebuild_frame_index) | ||
key_frames.events.reordered.connect(self._rebuild_frame_index) | ||
|
||
self.events = EmitterGroup(source=self, n_frames=None) | ||
self.__current_index = 0 | ||
self.events = EmitterGroup( | ||
source=self, n_frames=None, _current_index=None | ||
) | ||
|
||
self.state_interpolation_map: InterpolationMap = { | ||
"camera.angles": Interpolation.SLERP, | ||
|
@@ -57,16 +60,23 @@ def _rebuild_frame_index(self, event=None): | |
"""Create a map of frame number -> (kf0, kf1, fraction)""" | ||
self._frame_index.clear() | ||
self._cache.clear() | ||
if len(self._key_frames) < 2: | ||
|
||
n_keyframes = len(self._key_frames) | ||
|
||
if n_keyframes == 0: | ||
self.events.n_frames(value=len(self)) | ||
return | ||
elif n_keyframes == 1: | ||
f = 0 | ||
kf1 = self._key_frames[0] | ||
else: | ||
f = 0 | ||
for kf0, kf1 in pairwise(self._key_frames): | ||
for s in range(kf1.steps): | ||
fraction = kf1.ease(s / kf1.steps) | ||
self._frame_index[f] = (kf0, kf1, fraction) | ||
f += 1 | ||
|
||
f = 0 | ||
for kf0, kf1 in pairwise(self._key_frames): | ||
for s in range(kf1.steps): | ||
fraction = kf1.ease(s / kf1.steps) | ||
self._frame_index[f] = (kf0, kf1, fraction) | ||
f += 1 | ||
self._frame_index[f] = (kf1, kf1, 0) | ||
self.events.n_frames(value=len(self)) | ||
|
||
|
@@ -160,3 +170,17 @@ def iter_frames( | |
frame = ndi.zoom(frame, (scale_factor, scale_factor, 1)) | ||
frame = frame.astype(np.uint8) | ||
yield frame | ||
|
||
def set_movie_frame_index(self, viewer: napari.viewer.Viewer, index: int): | ||
self[index].apply(viewer) | ||
self._current_index = index | ||
|
||
@property | ||
def _current_index(self): | ||
return self.__current_index | ||
|
||
@_current_index.setter | ||
def _current_index(self, frame_index): | ||
if frame_index != self._frame_index: | ||
self.__current_index = frame_index | ||
self.events._current_index(value=frame_index) | ||
Comment on lines
+178
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like having this directly on the |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is looking much nicer! 🙂