Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): smarter info window hiding logic #482

Merged
merged 12 commits into from
Dec 11, 2024
36 changes: 28 additions & 8 deletions manim_slides/present/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import signal
import sys
from pathlib import Path
from typing import Optional
from typing import Literal, Optional

import click
from click import Context, Parameter
Expand Down Expand Up @@ -202,7 +202,7 @@
"screen_number",
metavar="NUMBER",
type=int,
default=None,
default=0,
PeculiarProgrammer marked this conversation as resolved.
Show resolved Hide resolved
help="Present content on the given screen (a.k.a. display).",
)
@click.option(
Expand All @@ -222,8 +222,9 @@
)
@click.option(
"--hide-info-window",
is_flag=True,
help="Hide info window.",
type=click.Choice(["auto", "always", "never"], case_sensitive=False),
default="auto",
help="Hide info window. Auto will hide the info window if there is only one screen.",
)
@click.option(
"--info-window-screen",
Expand All @@ -248,10 +249,10 @@
start_at: tuple[Optional[int], Optional[int], Optional[int]],
start_at_scene_number: int,
start_at_slide_number: int,
screen_number: Optional[int],
screen_number: int,
playback_rate: float,
next_terminates_loop: bool,
hide_info_window: bool,
hide_info_window: Literal["auto", "always", "never"],
info_window_screen_number: Optional[int],
) -> None:
"""
Expand Down Expand Up @@ -304,12 +305,31 @@
)
return None

should_hide_info_window = False

if hide_info_window == "auto":
should_hide_info_window = len(app.screens()) == 1
elif hide_info_window == "always":
should_hide_info_window = True

Check warning on line 313 in manim_slides/present/__init__.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/__init__.py#L312-L313

Added lines #L312 - L313 were not covered by tests

if should_hide_info_window and info_window_screen_number is not None:
logger.warning(

Check warning on line 316 in manim_slides/present/__init__.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/__init__.py#L316

Added line #L316 was not covered by tests
f"Ignoring `--info-window-screen` because `--hide-info-window` is set to `{hide_info_window}`."
)

if (
not should_hide_info_window
and info_window_screen_number is None
and len(app.screens()) > 1
):
info_window_screen_number = 1 if screen_number == 0 else 0

Check warning on line 325 in manim_slides/present/__init__.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/__init__.py#L325

Added line #L325 was not covered by tests

if screen_number is not None:
screen = get_screen(screen_number)
else:
screen = None

if info_window_screen_number is not None:
if info_window_screen_number is not None and not should_hide_info_window:
info_window_screen = get_screen(info_window_screen_number)
else:
info_window_screen = None
Expand All @@ -333,7 +353,7 @@
screen=screen,
playback_rate=playback_rate,
next_terminates_loop=next_terminates_loop,
hide_info_window=hide_info_window,
hide_info_window=should_hide_info_window,
info_window_screen=info_window_screen,
)

Expand Down
10 changes: 5 additions & 5 deletions manim_slides/present/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
def __init__(
self,
*,
full_screen: bool,
aspect_ratio_mode: Qt.AspectRatioMode,
screen: Optional[QScreen],
) -> None:
Expand All @@ -38,9 +37,6 @@
self.setScreen(screen)
self.move(screen.geometry().topLeft())

if full_screen:
self.setWindowState(Qt.WindowFullScreen)

layout = QHBoxLayout()

# Current slide view
Expand Down Expand Up @@ -243,7 +239,6 @@
self.slide_changed.connect(self.slide_changed_callback)

self.info = Info(
full_screen=full_screen,
aspect_ratio_mode=aspect_ratio_mode,
screen=info_window_screen,
)
Expand All @@ -252,6 +247,9 @@
self.video_sink.videoFrameChanged.connect(self.frame_changed)
self.hide_info_window = hide_info_window

if full_screen:
self.info.setWindowState(Qt.WindowFullScreen)

# Connecting key callbacks

self.config.keys.QUIT.connect(self.close)
Expand Down Expand Up @@ -535,8 +533,10 @@
def full_screen(self) -> None:
if self.windowState() == Qt.WindowFullScreen:
self.setWindowState(Qt.WindowNoState)
self.info.setWindowState(Qt.WindowNoState)

Check warning on line 536 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L536

Added line #L536 was not covered by tests
else:
self.setWindowState(Qt.WindowFullScreen)
self.info.setWindowState(Qt.WindowFullScreen)

Check warning on line 539 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L539

Added line #L539 was not covered by tests

@Slot()
def hide_mouse(self) -> None:
Expand Down
Loading