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(present): fix presentation size and add screen option #232

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions manim_slides/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"File",
"Rendering",
"Rendered",
"Pressed key",
]


Expand Down
67 changes: 56 additions & 11 deletions manim_slides/present.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
from pydantic import ValidationError
from pydantic_extra_types.color import Color
from PySide6.QtCore import Qt, QThread, Signal, Slot
from PySide6.QtGui import QCloseEvent, QIcon, QImage, QKeyEvent, QPixmap, QResizeEvent
from PySide6.QtGui import (
QCloseEvent,
QIcon,
QImage,
QKeyEvent,
QPixmap,
QResizeEvent,
QScreen,
)
from PySide6.QtWidgets import QApplication, QGridLayout, QLabel, QWidget
from tqdm import tqdm

Expand Down Expand Up @@ -350,7 +358,7 @@

change_video_signal = Signal(np.ndarray)
change_info_signal = Signal(dict)
change_presentation_sigal = Signal()
change_presentation_signal = Signal()
finished = Signal()

def __init__(
Expand Down Expand Up @@ -401,7 +409,7 @@
if -len(self) <= value < len(self):
self.__current_presentation_index = value
self.current_presentation.release_cap()
self.change_presentation_sigal.emit()
self.change_presentation_signal.emit()

Check warning on line 412 in manim_slides/present.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present.py#L412

Added line #L412 was not covered by tests
else:
logger.error(
f"Could not load scene number {value}, playing first scene instead."
Expand All @@ -422,6 +430,10 @@
"""Returns the background color of the current presentation."""
return self.current_presentation.background_color

def start(self) -> None:
super().start()
self.change_presentation_signal.emit()

def run(self) -> None:
"""Runs a series of presentations until end or exit."""
while self.run_flag:
Expand Down Expand Up @@ -650,10 +662,15 @@
aspect_ratio: AspectRatio = AspectRatio.auto,
resize_mode: Qt.TransformationMode = Qt.SmoothTransformation,
background_color: str = "black",
screen: Optional[QScreen] = None,
**kwargs: Any,
):
super().__init__()

if screen:
self.setScreen(screen)
self.move(screen.geometry().topLeft())

Check warning on line 672 in manim_slides/present.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present.py#L671-L672

Added lines #L671 - L672 were not covered by tests

self.setWindowTitle(WINDOW_NAME)
self.icon = QIcon(":/icon.png")
self.setWindowIcon(self.icon)
Expand All @@ -675,10 +692,6 @@
if self.aspect_ratio == AspectRatio.auto:
self.label.setScaledContents(True)
self.label.setAlignment(Qt.AlignCenter)
self.label.resize(self.display_width, self.display_height)
self.label.setStyleSheet(
f"background-color: {self.thread.current_background_color}"
)

self.pixmap = QPixmap(self.width(), self.height())
self.label.setPixmap(self.pixmap)
Expand All @@ -693,11 +706,13 @@

if fullscreen:
self.showFullScreen()
else:
self.resize(self.display_width, self.display_height)

# connect signals
self.thread.change_video_signal.connect(self.update_image)
self.thread.change_info_signal.connect(self.info.update_info)
self.thread.change_presentation_sigal.connect(self.update_canvas)
self.thread.change_presentation_signal.connect(self.update_canvas)
self.thread.finished.connect(self.closeAll)
self.send_key_signal.connect(self.thread.set_key)

Expand Down Expand Up @@ -755,8 +770,12 @@
def update_canvas(self) -> None:
"""Update the canvas when a presentation has changed."""
logger.debug("Updating canvas")
self.display_width, self.display_height = self.thread.current_resolution
if not self.isFullScreen():
w, h = self.thread.current_resolution

if not self.isFullScreen() and (
self.display_width != w or self.display_height != h
):
self.display_width, self.display_height = w, h

Check warning on line 778 in manim_slides/present.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present.py#L778

Added line #L778 was not covered by tests
self.resize(self.display_width, self.display_height)
self.label.setStyleSheet(
f"background-color: {self.thread.current_background_color}"
Expand Down Expand Up @@ -997,6 +1016,14 @@
default=0,
help="Start presenting at a given animation number (0 is first, -1 is last). This conflicts with slide number since animation number is absolute to the presentation.",
)
@click.option(
"--screen",
"screen_number",
metavar="NUMBER",
type=int,
default=None,
help="Presents content on the given screen (a.k.a. display).",
)
@click.help_option("-h", "--help")
@verbosity_option
def present(
Expand All @@ -1017,6 +1044,7 @@
start_at_scene_number: Optional[int],
start_at_slide_number: Optional[int],
start_at_animation_number: Optional[int],
screen_number: Optional[int] = None,
) -> None:
"""
Present SCENE(s), one at a time, in order.
Expand Down Expand Up @@ -1068,7 +1096,9 @@
ext = record_to.suffix
if ext.lower() != ".avi":
raise click.UsageError(
"Recording only support '.avi' extension. For other video formats, please convert the resulting '.avi' file afterwards."
"Recording only support '.avi' extension. "
"For other video formats, "
"please convert the resulting '.avi' file afterwards."
)

if start_at[0]:
Expand All @@ -1086,6 +1116,19 @@
app = QApplication.instance()

app.setApplicationName("Manim Slides")

if screen_number is not None:
try:
screen = app.screens()[screen_number]
except IndexError:
logger.error(

Check warning on line 1124 in manim_slides/present.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present.py#L1121-L1124

Added lines #L1121 - L1124 were not covered by tests
f"Invalid screen number {screen_number}, "
f"allowed values are from 0 to {len(app.screens())-1} (incl.)"
)
screen = None

Check warning on line 1128 in manim_slides/present.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present.py#L1128

Added line #L1128 was not covered by tests
else:
screen = None

a = App(
presentations,
config=config,
Expand All @@ -1100,6 +1143,8 @@
start_at_scene_number=start_at_scene_number,
start_at_slide_number=start_at_slide_number,
start_at_animation_number=start_at_animation_number,
screen=screen,
)

a.show()
sys.exit(app.exec_())
Loading