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>
This commit is contained in:
Jérome Eertmans
2022-09-22 19:11:26 +02:00
committed by GitHub
parent 9900b3123e
commit 2457ca8a05
2 changed files with 17 additions and 11 deletions

View File

@ -6,22 +6,21 @@
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'Manim Slides' project = "Manim Slides"
copyright = '2022, Jérome Eertmans' copyright = "2022, Jérome Eertmans"
author = 'Jérome Eertmans' author = "Jérome Eertmans"
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = ["sphinx.ext.autodoc", "sphinx_click"] extensions = ["sphinx.ext.autodoc", "sphinx_click"]
templates_path = ['_templates'] templates_path = ["_templates"]
exclude_patterns = [] exclude_patterns = []
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'furo' html_theme = "furo"
html_static_path = ['_static'] html_static_path = ["_static"]

View File

@ -134,6 +134,13 @@ class Presentation:
self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) 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): def reverse_current_slide(self):
"""Reverses current slide.""" """Reverses current slide."""
self.reverse = True self.reverse = True
@ -142,9 +149,7 @@ class Presentation:
def load_next_slide(self): def load_next_slide(self):
"""Loads next slide.""" """Loads next slide."""
if self.reverse: if self.reverse:
self.reverse = False self.cancel_reverse()
self.reversed_animation = -1
self.release_cap()
self.rewind_current_slide() self.rewind_current_slide()
elif self.current_slide.is_last(): elif self.current_slide.is_last():
self.current_slide.terminated = True self.current_slide.terminated = True
@ -156,6 +161,7 @@ class Presentation:
def load_previous_slide(self): def load_previous_slide(self):
"""Loads previous slide.""" """Loads previous slide."""
self.cancel_reverse()
self.current_slide_index = max(0, self.current_slide_index - 1) self.current_slide_index = max(0, self.current_slide_index - 1)
self.rewind_current_slide() self.rewind_current_slide()
@ -425,7 +431,7 @@ class Display:
elif self.config.BACK.match(key): elif self.config.BACK.match(key):
if self.current_presentation.current_slide_index == 0: if self.current_presentation.current_slide_index == 0:
if self.current_presentation_index == 0: if self.current_presentation_index == 0:
self.current_presentation.rewind_current_slide() self.current_presentation.load_previous_slide()
else: else:
self.current_presentation_index -= 1 self.current_presentation_index -= 1
self.current_presentation.load_last_slide() self.current_presentation.load_last_slide()
@ -437,6 +443,7 @@ class Display:
self.current_presentation.reverse_current_slide() self.current_presentation.reverse_current_slide()
self.state = State.PLAYING self.state = State.PLAYING
elif self.config.REWIND.match(key): elif self.config.REWIND.match(key):
self.current_presentation.cancel_reverse()
self.current_presentation.rewind_current_slide() self.current_presentation.rewind_current_slide()
self.state = State.PLAYING self.state = State.PLAYING