napari / napari-animation

A napari plugin for making animations
https://napari.github.io/napari-animation/
Other
74 stars 27 forks source link

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

Open romainGuiet opened 1 year ago

romainGuiet commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 https://github.com/napari/napari-animation/blob/78eef3ec1343d67cd9e1e6e611ba01cb115696dd/napari_animation/key_frame.py#L19-L42

and are created here... https://github.com/napari/napari-animation/blob/78eef3ec1343d67cd9e1e6e611ba01cb115696dd/napari_animation/animation.py#L79-L80

The list of key frames is available at Animation.key_frames https://github.com/napari/napari-animation/blob/78eef3ec1343d67cd9e1e6e611ba01cb115696dd/napari_animation/animation.py#L17-L29

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 commented 1 year ago

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 commented 1 year ago

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 :)