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>
This commit is contained in:
Jérome Eertmans
2022-09-14 13:41:25 +02:00
committed by GitHub
parent 5f730593fb
commit 2ba0d48ac1

View File

@ -18,6 +18,8 @@ from .config import Config
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 @@ class Display:
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 @@ class Display:
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 @@ class Display:
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 @@ class Display:
*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)