From 16edfe4f5cc37ec2b30608fc200e44ab199d56d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Fri, 20 Oct 2023 10:15:20 +0200 Subject: [PATCH 1/2] feat(lib): add `Slide.next_section` method --- CHANGELOG.md | 3 +++ docs/source/reference/api.md | 1 + manim_slides/slide/base.py | 15 ++++++++++++++- manim_slides/slide/manim.py | 19 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5672a460..ed03716d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,9 @@ In an effort to better document changes, this CHANGELOG document is now created. - Added `loop` option to `Slide`'s `next_slide` method. Calling `next_slide` will never fail anymore. [#294](https://github.com/jeertmans/manim-slides/pull/294) +- Added `Slide.next_section` for compatibility with `manim`'s + `Scene.next_section` method. + [#295](https://github.com/jeertmans/manim-slides/pull/295) (v5-changed)= ### Changed diff --git a/docs/source/reference/api.md b/docs/source/reference/api.md index 19e2b7df..3a707933 100644 --- a/docs/source/reference/api.md +++ b/docs/source/reference/api.md @@ -15,6 +15,7 @@ use, not the methods used internally when rendering. canvas, canvas_mobjects, mobjects_without_canvas, + next_section, next_slide, remove_from_canvas, wait_time_between_slides, diff --git a/manim_slides/slide/base.py b/manim_slides/slide/base.py index f7e40a76..b45e2302 100644 --- a/manim_slides/slide/base.py +++ b/manim_slides/slide/base.py @@ -252,7 +252,7 @@ def play(self, *args: Any, **kwargs: Any) -> None: super().play(*args, **kwargs) # type: ignore[misc] self._current_animation += 1 - def next_slide(self, loop: bool = False) -> None: + def next_slide(self, *, loop: bool = False, **kwargs: Any) -> None: """ Create a new slide with previous animations, and setup options for the next slide. @@ -260,8 +260,16 @@ def next_slide(self, loop: bool = False) -> None: This usually means that the user will need to press some key before the next slide is played. By default, this is the right arrow key. + :param args: + Positional arguments to be passed to + :meth:`Scene.next_section`, + or ignored if `manimlib` API is used. :param loop: If set, next slide will be looping. + :param kwargs: + Keyword arguments to be passed to + :meth:`Scene.next_section`, + or ignored if `manimlib` API is used. .. note:: @@ -273,6 +281,11 @@ def next_slide(self, loop: bool = False) -> None: When rendered with RevealJS, loops cannot be in the first nor the last slide. + .. seealso:: + + When using ``manim`` API, this method will also call + :meth:`Scene.next_section`. + Examples -------- The following contains 3 slides: diff --git a/manim_slides/slide/manim.py b/manim_slides/slide/manim.py index 11d262a0..80885547 100644 --- a/manim_slides/slide/manim.py +++ b/manim_slides/slide/manim.py @@ -64,6 +64,25 @@ def _leave_progress_bar(self) -> bool: def _start_at_animation_number(self) -> Optional[int]: return config["from_animation_number"] # type: ignore + def next_section(self, *args: Any, **kwargs: Any) -> None: + """ + Alias to :meth:`next_slide`. + + :param args: + Positional arguments to be passed to :meth:`next_slide`. + :param kwargs: + Keyword arguments to be passed to :meth:`next_slide`. + + .. attention:: + + This method is only available when using ``manim`` API. + """ + self.next_slide(*args, **kwargs) + + def next_slide(self, *args: Any, loop: bool = False, **kwargs: Any) -> None: + Scene.next_section(self, *args, **kwargs) + BaseSlide.next_slide(self, loop=loop) + def render(self, *args: Any, **kwargs: Any) -> None: """MANIM render.""" # We need to disable the caching limit since we rely on intermediate files From 837e68742136e7fe81679e062db467cc456030bf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Oct 2023 08:15:42 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- manim_slides/slide/base.py | 2 +- manim_slides/slide/manim.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manim_slides/slide/base.py b/manim_slides/slide/base.py index b45e2302..d90ada35 100644 --- a/manim_slides/slide/base.py +++ b/manim_slides/slide/base.py @@ -282,7 +282,7 @@ def next_slide(self, *, loop: bool = False, **kwargs: Any) -> None: the last slide. .. seealso:: - + When using ``manim`` API, this method will also call :meth:`Scene.next_section`. diff --git a/manim_slides/slide/manim.py b/manim_slides/slide/manim.py index 80885547..67d1e52b 100644 --- a/manim_slides/slide/manim.py +++ b/manim_slides/slide/manim.py @@ -74,7 +74,7 @@ def next_section(self, *args: Any, **kwargs: Any) -> None: Keyword arguments to be passed to :meth:`next_slide`. .. attention:: - + This method is only available when using ``manim`` API. """ self.next_slide(*args, **kwargs)