Skip to content

Commit b07a838

Browse files
authored
feat(lib): add start_skip_animations and stop_skip_animations meth. (#523)
1 parent 074a029 commit b07a838

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
(unreleased)=
1111
## [Unreleased](https://github.com/jeertmans/manim-slides/compare/v5.4.0...HEAD)
1212

13+
(unreleased-added)=
14+
### Added
15+
16+
- Added `start_skip_animations` and `stop_skip_animations` methods.
17+
[#523](https://github.com/jeertmans/manim-slides/pull/523)
18+
1319
(v5.4.0)=
1420
## [v5.4.0](https://github.com/jeertmans/manim-slides/compare/v5.3.1...v5.4.0)
1521

docs/source/reference/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use, not the methods used internally when rendering.
1818
next_section,
1919
next_slide,
2020
remove_from_canvas,
21+
start_skip_animations,
22+
stop_skip_animations,
2123
wait_time_between_slides,
2224
wipe,
2325
zoom,

manim_slides/slide/base.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(
4949
self._start_animation = 0
5050
self._canvas: MutableMapping[str, Mobject] = {}
5151
self._wait_time_between_slides = 0.0
52+
self._skip_animations = False
5253

5354
@property
5455
@abstractmethod
@@ -304,6 +305,11 @@ def next_slide(
304305
305306
If `manim` is used, this is also passed to `:meth:`Scene.next_section<manim.scene.scene.Scene.next_section>`,
306307
which will avoid rendering the corresponding animations.
308+
309+
.. seealso::
310+
311+
:meth:`start_skip_animations`
312+
:meth:`stop_skip_animations`
307313
:param loop:
308314
If set, next slide will be looping.
309315
:param auto_next:
@@ -463,6 +469,9 @@ def construct(self):
463469

464470
self._current_slide += 1
465471

472+
if self._skip_animations:
473+
base_slide_config.skip_animations = True
474+
466475
self._base_slide_config = base_slide_config
467476
self._start_animation = self._current_animation
468477

@@ -572,6 +581,24 @@ def _save_slides(
572581
f"Slide '{scene_name}' configuration written in '{slide_path.absolute()}'"
573582
)
574583

584+
def start_skip_animations(self) -> None:
585+
"""
586+
Start skipping animations.
587+
588+
This automatically applies ``skip_animations=True``
589+
to all subsequent calls to :meth:`next_slide`.
590+
591+
This is useful when you want to skip animations from multiple slides in a row,
592+
without having to manually set ``skip_animations=True``.
593+
"""
594+
self._skip_animations = True
595+
596+
def stop_skip_animations(self) -> None:
597+
"""
598+
Stop skipping animations.
599+
"""
600+
self._skip_animations = False
601+
575602
def wipe(
576603
self,
577604
*args: Any,

tests/test_base_slide.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ def test_wait_time_between_slides(self, base_slide: BaseSlide) -> None:
8686

8787
assert base_slide.wait_time_between_slides == 0.0
8888

89+
def test_skip_animations(self, base_slide: BaseSlide) -> None:
90+
assert base_slide._skip_animations == False
91+
92+
def test_start_and_stop_skip_animations(self, base_slide: BaseSlide) -> None:
93+
base_slide.start_skip_animations()
94+
assert base_slide._skip_animations == True
95+
base_slide.stop_skip_animations()
96+
assert base_slide._skip_animations == False
97+
8998
def test_play(self) -> None:
9099
pass # This method should be tested in test_slide.py
91100

tests/test_slide.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,25 @@ def construct(self) -> None:
527527
assert not self._base_slide_config.skip_animations
528528
self.play(GrowFromCenter(square))
529529

530+
class Baz(CESlide):
531+
def construct(self) -> None:
532+
circle = Circle(color=BLUE)
533+
self.play(GrowFromCenter(circle))
534+
assert not self._base_slide_config.skip_animations
535+
self.start_skip_animations()
536+
self.next_slide()
537+
square = Square(color=BLUE)
538+
self.play(GrowFromCenter(square))
539+
assert self._base_slide_config.skip_animations
540+
self.next_slide()
541+
assert self._base_slide_config.skip_animations
542+
self.play(GrowFromCenter(square))
543+
self.stop_skip_animations()
544+
530545
with tmp_cwd() as tmp_dir:
531546
init_slide(Foo).render()
532547
init_slide(Bar).render()
548+
init_slide(Baz).render()
533549

534550
slides_folder = Path(tmp_dir) / "slides"
535551

@@ -547,6 +563,12 @@ def construct(self) -> None:
547563

548564
assert len(config.slides) == 3
549565

566+
slide_file = slides_folder / "Baz.json"
567+
568+
config = PresentationConfig.from_file(slide_file)
569+
570+
assert len(config.slides) == 1
571+
550572
def test_canvas(self) -> None:
551573
@assert_constructs
552574
class _(CESlide):

0 commit comments

Comments
 (0)