diff --git a/optimap/video/_player.py b/optimap/video/_player.py index f026711..51d1106 100644 --- a/optimap/video/_player.py +++ b/optimap/video/_player.py @@ -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) diff --git a/tests/test_video_io.py b/tests/test_video_io.py index 6face8f..1ddc5a0 100644 --- a/tests/test_video_io.py +++ b/tests/test_video_io.py @@ -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 \ No newline at end of file