diff --git a/manim_slides/__init__.py b/manim_slides/__init__.py index fa1c50a..b11020e 100644 --- a/manim_slides/__init__.py +++ b/manim_slides/__init__.py @@ -1,2 +1,2 @@ -from .slide import Slide, ThreeDSlide from .__version__ import __version__ +from .slide import Slide, ThreeDSlide diff --git a/manim_slides/commons.py b/manim_slides/commons.py index e753f4f..83cacec 100644 --- a/manim_slides/commons.py +++ b/manim_slides/commons.py @@ -1,4 +1,5 @@ import click + from .defaults import CONFIG_PATH diff --git a/manim_slides/main.py b/manim_slides/main.py index 7cf24e4..5b45540 100644 --- a/manim_slides/main.py +++ b/manim_slides/main.py @@ -3,7 +3,7 @@ from click_default_group import DefaultGroup from . import __version__ from .present import present -from .wizard import wizard, init +from .wizard import init, wizard @click.group(cls=DefaultGroup, default="present", default_if_no_args=True) diff --git a/manim_slides/present.py b/manim_slides/present.py index 305e042..d31e056 100644 --- a/manim_slides/present.py +++ b/manim_slides/present.py @@ -9,9 +9,9 @@ import click import cv2 import numpy as np +from .commons import config_path_option from .config import Config from .defaults import CONFIG_PATH, FOLDER_PATH -from .commons import config_path_option class State(Enum): @@ -42,7 +42,7 @@ class Presentation: self.lastframe = [] self.caps = [None for _ in self.files] - self.reset() + self.reset() self.add_last_slide() def add_last_slide(self): @@ -62,14 +62,14 @@ class Presentation: self.load_this_cap(0) self.current_slide_i = 0 self.slides[-1]["terminated"] = False - + def next(self): if self.current_slide["type"] == "last": self.current_slide["terminated"] = True else: self.current_slide_i = min(len(self.slides) - 1, self.current_slide_i + 1) self.rewind_slide() - + def prev(self): self.current_slide_i = max(0, self.current_slide_i - 1) self.rewind_slide() @@ -77,7 +77,7 @@ class Presentation: def rewind_slide(self): self.current_animation = self.current_slide["start_animation"] self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) - + def load_this_cap(self,cap_number): if self.caps[cap_number] == None: # unload other caps @@ -91,7 +91,7 @@ class Presentation: @property def current_slide(self): return self.slides[self.current_slide_i] - + @property def current_cap(self): self.load_this_cap(self.current_animation) @@ -143,7 +143,7 @@ class Presentation: self.load_this_cap(self.current_animation) # Reset video to position zero if it has been played before self.current_cap.set(cv2.CAP_PROP_POS_FRAMES, 0) - + return self.lastframe, state @@ -163,11 +163,11 @@ class Display: if fullscreen: cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty("Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) - + @property def current_presentation(self): return self.presentations[self.current_presentation_i] - + def run(self): while True: self.lastframe, self.state = self.current_presentation.update_state(self.state) @@ -184,11 +184,11 @@ class Display: self.handle_key() self.show_video() self.show_info() - + def show_video(self): self.lag = now() - self.last_time self.last_time = now() - cv2.imshow("Video", self.lastframe) + cv2.imshow("Video", self.lastframe) def show_info(self): info = np.zeros((130, 420), np.uint8) @@ -230,11 +230,11 @@ class Display: ) cv2.imshow("Info", info) - + def handle_key(self): sleep_time = math.ceil(1000/self.current_presentation.fps) key = cv2.waitKeyEx(fix_time(sleep_time - self.lag)) - + if self.config.QUIT.match(key): self.quit() elif self.state == State.PLAYING and self.config.PLAY_PAUSE.match(key): @@ -258,7 +258,7 @@ class Display: self.current_presentation.rewind_slide() self.state = State.PLAYING - + def quit(self): cv2.destroyAllWindows() sys.exit() diff --git a/manim_slides/slide.py b/manim_slides/slide.py index 03ff9e7..87e5572 100644 --- a/manim_slides/slide.py +++ b/manim_slides/slide.py @@ -20,7 +20,7 @@ class Slide(Scene): def play(self, *args, **kwargs): super(Slide, self).play(*args, **kwargs) self.current_animation += 1 - + def pause(self): self.slides.append(dict( type="slide", @@ -30,11 +30,11 @@ class Slide(Scene): )) self.current_slide += 1 self.pause_start_animation = self.current_animation - + def start_loop(self): assert self.loop_start_animation is None, "You cannot nest loops" self.loop_start_animation = self.current_animation - + def end_loop(self): assert self.loop_start_animation is not None, "You have to start a loop before ending it" self.slides.append(dict( @@ -46,32 +46,32 @@ class Slide(Scene): self.current_slide += 1 self.loop_start_animation = None self.pause_start_animation = self.current_animation - + def render(self, *args, **kwargs): # We need to disable the caching limit since we rely on intermidiate files max_files_cached = config["max_files_cached"] config["max_files_cached"] = float("inf") - + super(Slide, self).render(*args, **kwargs) config["max_files_cached"] = max_files_cached if not os.path.exists(self.output_folder): os.mkdir(self.output_folder) - + files_folder = os.path.join(self.output_folder, "files") if not os.path.exists(files_folder): os.mkdir(files_folder) - + scene_name = type(self).__name__ scene_files_folder = os.path.join(files_folder, scene_name) - + if os.path.exists(scene_files_folder): shutil.rmtree(scene_files_folder) - - if not os.path.exists(scene_files_folder): + + if not os.path.exists(scene_files_folder): os.mkdir(scene_files_folder) - + files = list() for src_file in self.renderer.file_writer.partial_movie_files: dst_file = os.path.join(scene_files_folder, os.path.basename(src_file)) diff --git a/manim_slides/wizard.py b/manim_slides/wizard.py index dca1a64..f2403f3 100644 --- a/manim_slides/wizard.py +++ b/manim_slides/wizard.py @@ -5,8 +5,8 @@ import click import cv2 import numpy as np -from .config import Config from .commons import config_options +from .config import Config from .defaults import CONFIG_PATH @@ -37,7 +37,7 @@ def _init(config_path, force, merge, skip_interactive=False): if os.path.exists(config_path): click.secho(f"The `{CONFIG_PATH}` configuration file exists") - + if not force and not merge: choice = click.prompt("Do you want to continue and (o)verwrite / (m)erge it, or (q)uit?", type=click.Choice(["o", "m", "q"], case_sensitive=False))