From 2457ca8a0586dda4d965e9bccb045a6299a83863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Thu, 22 Sep 2022 19:11:26 +0200 Subject: [PATCH] fix(cli): properly rewind / previous slide after reverse (#28) * fix(cli): properly rewind / previous slide after reverse Closes #24 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/source/conf.py | 13 ++++++------- manim_slides/present.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 0320e42..3631911 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -6,22 +6,21 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'Manim Slides' -copyright = '2022, Jérome Eertmans' -author = 'Jérome Eertmans' +project = "Manim Slides" +copyright = "2022, Jérome Eertmans" +author = "Jérome Eertmans" # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = ["sphinx.ext.autodoc", "sphinx_click"] -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = [] - # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'furo' -html_static_path = ['_static'] +html_theme = "furo" +html_static_path = ["_static"] diff --git a/manim_slides/present.py b/manim_slides/present.py index d66d8af..3688ead 100644 --- a/manim_slides/present.py +++ b/manim_slides/present.py @@ -134,6 +134,13 @@ class Presentation: self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) + def cancel_reverse(self): + """Cancels any effet produced by a reversed slide.""" + if self.reverse: + self.reverse = False + self.reversed_animation = -1 + self.release_cap() + def reverse_current_slide(self): """Reverses current slide.""" self.reverse = True @@ -142,9 +149,7 @@ class Presentation: def load_next_slide(self): """Loads next slide.""" if self.reverse: - self.reverse = False - self.reversed_animation = -1 - self.release_cap() + self.cancel_reverse() self.rewind_current_slide() elif self.current_slide.is_last(): self.current_slide.terminated = True @@ -156,6 +161,7 @@ class Presentation: def load_previous_slide(self): """Loads previous slide.""" + self.cancel_reverse() self.current_slide_index = max(0, self.current_slide_index - 1) self.rewind_current_slide() @@ -425,7 +431,7 @@ class Display: elif self.config.BACK.match(key): if self.current_presentation.current_slide_index == 0: if self.current_presentation_index == 0: - self.current_presentation.rewind_current_slide() + self.current_presentation.load_previous_slide() else: self.current_presentation_index -= 1 self.current_presentation.load_last_slide() @@ -437,6 +443,7 @@ class Display: self.current_presentation.reverse_current_slide() self.state = State.PLAYING elif self.config.REWIND.match(key): + self.current_presentation.cancel_reverse() self.current_presentation.rewind_current_slide() self.state = State.PLAYING