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

Create position from script and send them to the GUI - feature request #162

Open
romainGuiet opened this issue Mar 23, 2023 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@romainGuiet
Copy link

Dear @team ,

Thank you for this great tool !

It would be nice if after creating the position from a script it would be possible to send them to the GUI (something like animation.send_keyframe() ? ), so one can eventually correct the order manually.

NOTE : when double-clicking on a key_frame in the GUI we can change the name, is it possible to do so using code ?

Thank you again ,

Romain

@alisterburt
Copy link
Collaborator

alisterburt commented Mar 23, 2023

Hi @romainGuiet - thanks for the kind words!

It would be nice if after creating the position from a script it would be possible to send them to the GUI (something like animation.send_keyframe() ? ), so one can eventually correct the order manually.

Interesting! There is probably a hacky way to get this working already which might be enough for you... let me know what you think

import napari
from napari_animation._qt.animation_widget import AnimationWidget

viewer = napari.Viewer()
animation_widget = AnimationWidget(viewer)
animation = animation_widget.animation

# capture keyframes

Let me know if this does the sort of thing you're looking for

@alisterburt
Copy link
Collaborator

when double-clicking on a key_frame in the GUI we can change the name, is it possible to do so using code ?
Key frames have a name attribute

class KeyFrame:
"""A single keyframe in the animation.
Parameters
----------
viewer_state : napari_animation.ViewerState
The state of the viewer at this keyframe.
thumbnail : np.ndarray
A thumbnail representing this keyframe.
steps : int
Number of interpolation steps between last keyframe and captured one.
ease : callable, optional
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.
name : str
A name for the keyframe.
"""
viewer_state: ViewerState
thumbnail: np.ndarray
steps: int = 15
ease: Easing = Easing.LINEAR
name: str = "KeyFrame"

and are created here...

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

The list of key frames is available at Animation.key_frames

class Animation:
"""Make animations using the napari viewer.
Parameters
----------
viewer : napari.Viewer
napari viewer.
Attributes
----------
key_frames : list of KeyFrame
List of key-frames in the animation.
"""

So you could jump in there to modify them programmatically - whether or not those changes will be updated in the GUI I'm not sure without testing

@romainGuiet
Copy link
Author

Thank you for your swift answer @alisterburt !

I'm probably doing something wrong because nothing different happened 😅

I tried with (or without) the napari-animation widget opened before running the lines below but no key_frame appeared in the widget ...

import napari
from napari_animation._qt.animation_widget import AnimationWidget

viewer = napari.Viewer()
animation_widget = AnimationWidget(viewer)
animation = animation_widget.animation

# capture keyframes
viewer.add_image( image_nd )

viewer3D.camera.angles = (0.0, 0.0, 0.0)
animation.capture_keyframe()

viewer3D.camera.angles = (0.0, 60.0, 90.0)
animation.capture_keyframe()

@alisterburt
Copy link
Collaborator

Strange... I was expecting that to work and I'm not sure why it doesn't, the 'view' you see should change whenever the model (the key frame list) changes

I could delve into this but I don't really need the feature myself and it would take more time than I have right now... maybe someone interested can try to take a look :)

@psobolewskiPhD psobolewskiPhD added the enhancement New feature or request label Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants