Skip to content

Commit 05c1a16

Browse files
taibeledpre-commit-ci[bot]jeertmans
authored
feat(cli): smarter info window hiding logic (#482)
* Adds features from #327 This changes the ``--hide-info-window-`` command to accept three options: auto, always, and never. Auto will hide the info window if there is only one screen. This also fixes the --full-screen option by moving the info window to monitor 1 and the presentation to monitor 0 by default. * chore(fmt): auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Let Qt decide the screens * Fix full screen bug * chore(fmt): auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix(cli): improve logic * fix * Revert fixes and clean code * Update changelog --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jérome Eertmans <[email protected]>
1 parent 3bd8c38 commit 05c1a16

File tree

4 files changed

+68
-21
lines changed

4 files changed

+68
-21
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
(unreleased)=
1111
## [Unreleased](https://github.com/jeertmans/manim-slides/compare/v5.1.10...HEAD)
1212

13+
(unreleased-changed)=
14+
### Changed
15+
16+
- The info window is now only shown in presentations when there
17+
are multiple monitors. However, the `--show-info-window` option
18+
was added to `manim-slides present` to force the info window.
19+
When there are multiple monitors, the info window will no longer
20+
be on the same monitor as the main window, unless overridden.
21+
[@PeculiarProgrammer](https://github.com/PeculiarProgrammer)
22+
[#482](https://github.com/jeertmans/manim-slides/pull/482)
23+
1324
(v5.1.10)=
1425
## [v5.1.10](https://github.com/jeertmans/manim-slides/compare/v5.1.9...v5.1.10)
1526

manim_slides/present/__init__.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import signal
22
import sys
33
from pathlib import Path
4-
from typing import Optional
4+
from typing import Literal, Optional
55

66
import click
77
from click import Context, Parameter
@@ -222,20 +222,28 @@ def str_to_int_or_none(value: str) -> Optional[int]:
222222
)
223223
@click.option(
224224
"--hide-info-window",
225-
is_flag=True,
226-
help="Hide info window.",
225+
flag_value="always",
226+
help="Hide info window. By default, hide the info window if there is only one screen.",
227+
)
228+
@click.option(
229+
"--show-info-window",
230+
"hide_info_window",
231+
flag_value="never",
232+
help="Force to show info window.",
227233
)
228234
@click.option(
229235
"--info-window-screen",
230236
"info_window_screen_number",
231237
metavar="NUMBER",
232238
type=int,
233239
default=None,
234-
help="Put info window on the given screen (a.k.a. display).",
240+
help="Put info window on the given screen (a.k.a. display). "
241+
"If there is more than one screen, it will by default put the info window "
242+
"on a different screen than the main player.",
235243
)
236244
@click.help_option("-h", "--help")
237245
@verbosity_option
238-
def present(
246+
def present( # noqa: C901
239247
scenes: list[str],
240248
config_path: Path,
241249
folder: Path,
@@ -251,7 +259,7 @@ def present(
251259
screen_number: Optional[int],
252260
playback_rate: float,
253261
next_terminates_loop: bool,
254-
hide_info_window: bool,
262+
hide_info_window: Optional[Literal["always", "never"]],
255263
info_window_screen_number: Optional[int],
256264
) -> None:
257265
"""
@@ -294,22 +302,36 @@ def present(
294302
app = qapp()
295303
app.setApplicationName("Manim Slides")
296304

305+
screens = app.screens()
306+
297307
def get_screen(number: int) -> Optional[QScreen]:
298308
try:
299-
return app.screens()[number]
309+
return screens[number]
300310
except IndexError:
301311
logger.error(
302312
f"Invalid screen number {number}, "
303-
f"allowed values are from 0 to {len(app.screens())-1} (incl.)"
313+
f"allowed values are from 0 to {len(screens)-1} (incl.)"
304314
)
305315
return None
306316

317+
should_hide_info_window = False
318+
319+
if hide_info_window is None:
320+
should_hide_info_window = len(screens) == 1
321+
elif hide_info_window == "always":
322+
should_hide_info_window = True
323+
324+
if should_hide_info_window and info_window_screen_number is not None:
325+
logger.warning(
326+
f"Ignoring `--info-window-screen` because `--hide-info-window` is set to `{hide_info_window}`."
327+
)
328+
307329
if screen_number is not None:
308330
screen = get_screen(screen_number)
309331
else:
310332
screen = None
311333

312-
if info_window_screen_number is not None:
334+
if info_window_screen_number is not None and not should_hide_info_window:
313335
info_window_screen = get_screen(info_window_screen_number)
314336
else:
315337
info_window_screen = None
@@ -333,11 +355,11 @@ def get_screen(number: int) -> Optional[QScreen]:
333355
screen=screen,
334356
playback_rate=playback_rate,
335357
next_terminates_loop=next_terminates_loop,
336-
hide_info_window=hide_info_window,
358+
hide_info_window=should_hide_info_window,
337359
info_window_screen=info_window_screen,
338360
)
339361

340-
player.show()
362+
player.show(screens)
341363

342364
signal.signal(signal.SIGINT, signal.SIG_DFL)
343365
sys.exit(app.exec())

manim_slides/present/player.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class Info(QWidget): # type: ignore[misc]
2828
def __init__(
2929
self,
3030
*,
31-
full_screen: bool,
3231
aspect_ratio_mode: Qt.AspectRatioMode,
3332
screen: Optional[QScreen],
3433
) -> None:
@@ -38,9 +37,6 @@ def __init__(
3837
self.setScreen(screen)
3938
self.move(screen.geometry().topLeft())
4039

41-
if full_screen:
42-
self.setWindowState(Qt.WindowFullScreen)
43-
4440
layout = QHBoxLayout()
4541

4642
# Current slide view
@@ -243,7 +239,6 @@ def __init__(
243239
self.slide_changed.connect(self.slide_changed_callback)
244240

245241
self.info = Info(
246-
full_screen=full_screen,
247242
aspect_ratio_mode=aspect_ratio_mode,
248243
screen=info_window_screen,
249244
)
@@ -484,11 +479,28 @@ def preview_next_slide(self) -> None:
484479
self.info.next_media_player.setSource(url)
485480
self.info.next_media_player.play()
486481

487-
def show(self) -> None:
482+
def show(self, screens: list[QScreen]) -> None:
483+
"""Screens is necessary to prevent the info window from being shown on the same screen as the main window (especially in full screen mode)."""
488484
super().show()
489485

490486
if not self.hide_info_window:
491-
self.info.show()
487+
if len(screens) > 1 and self.isFullScreen():
488+
self.ensure_different_screens(screens)
489+
490+
if self.isFullScreen():
491+
self.info.showFullScreen()
492+
else:
493+
self.info.show()
494+
495+
if (
496+
len(screens) > 1 and self.info.screen() == self.screen()
497+
): # It is better when Qt assigns the location, but if it fails to, this is a fallback
498+
self.ensure_different_screens(screens)
499+
500+
def ensure_different_screens(self, screens: list[QScreen]) -> None:
501+
target_screen = screens[1] if self.screen() == screens[0] else screens[0]
502+
self.info.setScreen(target_screen)
503+
self.info.move(target_screen.geometry().topLeft())
492504

493505
@Slot()
494506
def close(self) -> None:
@@ -538,8 +550,10 @@ def play_pause(self) -> None:
538550
def full_screen(self) -> None:
539551
if self.windowState() == Qt.WindowFullScreen:
540552
self.setWindowState(Qt.WindowNoState)
553+
self.info.setWindowState(Qt.WindowNoState)
541554
else:
542555
self.setWindowState(Qt.WindowFullScreen)
556+
self.info.setWindowState(Qt.WindowFullScreen)
543557

544558
@Slot()
545559
def hide_mouse(self) -> None:

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)