From 2ba0d48ac1fe5b2883421db5119a93b1577ee4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Wed, 14 Sep 2022 13:41:25 +0200 Subject: [PATCH] fix(cli): resize only on fullscreen (#12) * fix(cli): resize only on fullscreen Closes #10 * [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> --- manim_slides/present.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/manim_slides/present.py b/manim_slides/present.py index ac648dcd..84817842 100644 --- a/manim_slides/present.py +++ b/manim_slides/present.py @@ -18,6 +18,8 @@ from .defaults import CONFIG_PATH, FOLDER_PATH from .slide import reverse_video_path +WINDOW_NAME = "Manim Slides" + @unique class State(IntEnum): @@ -186,6 +188,8 @@ def __init__( self.start_paused = start_paused self.config = config self.skip_all = skip_all + self.fullscreen = fullscreen + self.is_windows = platform.system() == "Windows" self.state = State.PLAYING self.lastframe = None @@ -194,16 +198,16 @@ def __init__( self.lag = 0 self.last_time = now() - if platform.system() == "Windows": + if self.is_windows: user32 = ctypes.windll.user32 self.screen_width, self.screen_height = user32.GetSystemMetrics( 0 ), user32.GetSystemMetrics(1) - if fullscreen: - cv2.namedWindow("Video", cv2.WND_PROP_FULLSCREEN) + if self.fullscreen: + cv2.namedWindow(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN) cv2.setWindowProperty( - "Video", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN + WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN ) def resize_frame_to_screen(self, frame: np.ndarray): @@ -245,10 +249,10 @@ def show_video(self): frame = self.lastframe - if platform.system() == "Windows": + if self.is_windows and self.fullscreen: frame = self.resize_frame_to_screen(frame) - cv2.imshow("Video", frame) + cv2.imshow(WINDOW_NAME, frame) def show_info(self): info = np.zeros((130, 420), np.uint8) @@ -284,7 +288,7 @@ def show_info(self): *font_args, ) - cv2.imshow("Info", info) + cv2.imshow(f"{WINDOW_NAME}: Info", info) def handle_key(self): sleep_time = math.ceil(1000 / self.current_presentation.fps)