Skip to content

Commit

Permalink
InteractivePlayer.save(): add hide_slider/buttons/framecounter params
Browse files Browse the repository at this point in the history
  • Loading branch information
sitic committed Mar 8, 2024
1 parent dd62482 commit a785864
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
27 changes: 21 additions & 6 deletions optimap/video/_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,35 @@ def setup_gui(self, pos):
)
self.slider.on_changed(self.set_pos)

def save(self, *args, **kwargs):
def save(self, *args, hide_slider=True, hide_buttons=True, hide_framecounter=False, **kwargs):
"""Save the animation as a movie file, but hide the GUI buttons and slider.
See FuncAnimation's :meth:`~matplotlib.animation.Animation.save` for arguments.
Parameters
----------
*args :
See FuncAnimation's :meth:`~matplotlib.animation.Animation.save` for arguments.
hide_slider : bool, optional
Hide the slider, by default True
hide_buttons : bool, optional
Hide the play/pause button, by default True
hide_framecounter : bool, optional
Hide the frame counter, by default False
**kwargs :
See FuncAnimation's :meth:`~matplotlib.animation.Animation.save` for arguments.
"""

self.saving = True
# self.save_count = self.max // self.step

self.ax_player.set_visible(False)
self.ax_slider.set_visible(False)
if hide_buttons:
self.ax_player.set_visible(False)
if hide_slider:
self.ax_slider.set_visible(False)
if hide_framecounter:
self.suptitle.set_visible(False)
super().save(*args, **kwargs)

self.saving = False
# self.save_count = None
self.ax_player.set_visible(True)
self.ax_slider.set_visible(True)
self.suptitle.set_visible(True)
16 changes: 16 additions & 0 deletions tests/test_video_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,19 @@ def test_export_video_collage(tmpdir):
om.video.export_video_collage(filename, videos, vmins=0, vmaxs=1, padding=10, ncols=2, padding_color="white")
assert filename.is_file() and filename.stat().st_size > 0
assert mimetypes.guess_type(filename)[0] == "video/mp4"


@pytest.mark.skipif(skvideo._HAS_FFMPEG == 0, reason="ffmpeg not installed")
def test_interactive_player_save(tmpdir):
import matplotlib.pyplot as plt
video = np.zeros((100, 32, 32), dtype=np.float32)

fn = Path(tmpdir / "test.mp4")
# fn = Path('/tmp') / "test.mp4"
fig, ax = plt.subplots()
imshow = ax.imshow(video[0])
player = om.video.InteractivePlayer(fig, lambda i: imshow.set_data(video[i]), end=len(video))
player.save(fn, fps=25, hide_framecounter=True)
plt.close(fig)
assert fn.exists()
assert fn.is_file() and fn.stat().st_size > 0

0 comments on commit a785864

Please sign in to comment.