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

fix(present): bug with Qt and Windows + debug messages #377

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[bumpversion]
current_version = 5.1.3
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-rc(?P<release>\d+))?
serialize =
serialize =
{major}.{minor}.{patch}-rc{release}
{major}.{minor}.{patch}
commit = True
Expand Down
41 changes: 41 additions & 0 deletions manim_slides/present/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
):
super().__init__()

logger.debug("Instantiating Player instance.")

# Wizard's config

self.config = config
Expand All @@ -206,21 +208,29 @@
# Widgets

if screen:
logger.debug(f"Moving window to specific {screen =}.")
self.setScreen(screen)
self.move(screen.geometry().topLeft())

if full_screen:
logger.debug("Toggling window full screen.")
self.setWindowState(Qt.WindowFullScreen)
else:
w, h = self.current_presentation_config.resolution
logger.debug(
f"Setting window size accordingly to first presentation resolution: {w}-by-{h}."
)
geometry = self.geometry()
geometry.setWidth(w)
geometry.setHeight(h)
self.setGeometry(geometry)

if hide_mouse:
logger.debug("Hiding mouse cursor.")
self.setCursor(Qt.BlankCursor)

logger.debug("Creating main window.")

self.setWindowTitle(WINDOW_NAME)
self.icon = QIcon(":/icon.png")
self.setWindowIcon(self.icon)
Expand All @@ -237,6 +247,8 @@
self.presentation_changed.connect(self.presentation_changed_callback)
self.slide_changed.connect(self.slide_changed_callback)

logger.debug("Creating (secondary) info window.")

self.info = Info(
full_screen=full_screen, aspect_ratio_mode=aspect_ratio_mode, screen=screen
)
Expand All @@ -249,6 +261,8 @@

# Connecting key callbacks

logger.debug("Attaching callbacks")

self.config.keys.QUIT.connect(self.close)
self.config.keys.PLAY_PAUSE.connect(self.play_pause)
self.config.keys.NEXT.connect(self.next)
Expand All @@ -268,6 +282,7 @@
# Setting-up everything

if skip_all:
logger.debug("All slides will be skipped after being played.")

def media_status_changed(status: QMediaPlayer.MediaStatus) -> None:
self.media_player.setLoops(1) # Otherwise looping slides never end
Expand All @@ -277,6 +292,9 @@
self.media_player.mediaStatusChanged.connect(media_status_changed)

else:
logger.debug(

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L295

Added line #L295 was not covered by tests
"Adding a custom signal handler to skip slide if `--auto-next` is used."
)

def media_status_changed(status: QMediaPlayer.MediaStatus) -> None:
if (
Expand All @@ -288,6 +306,7 @@
self.media_player.mediaStatusChanged.connect(media_status_changed)

if self.current_slide_config.loop:
logger.debug("First slide is a loop.")
self.media_player.setLoops(-1)

self.load_current_media(start_paused=start_paused)
Expand Down Expand Up @@ -391,6 +410,7 @@

def load_current_media(self, start_paused: bool = False) -> None:
url = QUrl.fromLocalFile(str(self.current_file))
logger.debug(f"Loading media from {url = }.")
self.media_player.setSource(url)

if self.playing_reversed_slide:
Expand All @@ -403,11 +423,14 @@
)

if start_paused:
logger.debug("Media is not playing, starting paused.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L426

Added line #L426 was not covered by tests
self.media_player.pause()
else:
logger.debug("Playing the media...")
self.media_player.play()

def load_current_slide(self) -> None:
logger.debug("Loading (current) slide.")
slide_config = self.current_slide_config
self.current_file = slide_config.file

Expand All @@ -419,6 +442,7 @@
self.load_current_media()

def load_previous_slide(self) -> None:
logger.debug("Loading previous slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L445

Added line #L445 was not covered by tests
self.playing_reversed_slide = False

if self.current_slide_index > 0:
Expand All @@ -433,6 +457,7 @@
self.load_current_slide()

def load_next_slide(self) -> None:
logger.debug("Loading next slide.")
if self.playing_reversed_slide:
self.playing_reversed_slide = False
self.preview_next_slide() # Slide number did not change, but next did
Expand All @@ -451,6 +476,7 @@
self.load_current_slide()

def load_reversed_slide(self) -> None:
logger.debug("Loading reversed slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L479

Added line #L479 was not covered by tests
self.playing_reversed_slide = True
self.current_file = self.current_slide_config.rev_file
self.load_current_media()
Expand All @@ -461,19 +487,22 @@

@Slot()
def presentation_changed_callback(self) -> None:
logger.debug("Signal that presentation changed.")
index = self.current_presentation_index
count = self.presentations_count
self.info.scene_label.setText(f"{index+1:4d}/{count:4<d}")

@Slot()
def slide_changed_callback(self) -> None:
logger.debug("Signal that slide changed.")
index = self.current_slide_index
count = self.current_slides_count
self.info.slide_label.setText(f"{index+1:4d}/{count:4<d}")
self.info.slide_notes.setText(self.current_slide_config.notes)
self.preview_next_slide()

def preview_next_slide(self) -> None:
logger.debug("Previewing next slide (if any).")
if slide_config := self.next_slide_config:
url = QUrl.fromLocalFile(str(slide_config.file))
self.info.next_media_player.setSource(url)
Expand All @@ -493,6 +522,7 @@

@Slot()
def next(self) -> None:
logger.debug("[USER] Calling next slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L525

Added line #L525 was not covered by tests
if self.media_player.playbackState() == QMediaPlayer.PlaybackState.PausedState:
self.media_player.play()
elif self.next_terminates_loop and self.media_player.loops() != 1:
Expand All @@ -506,44 +536,55 @@

@Slot()
def previous(self) -> None:
logger.debug("[USER] Calling previous slide.")

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
self.load_previous_slide()

@Slot()
def reverse(self) -> None:
logger.debug("[USER] Reversing current slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L544

Added line #L544 was not covered by tests
self.load_reversed_slide()
self.preview_next_slide()

@Slot()
def replay(self) -> None:
logger.debug("[USER] Starting the current slide from the beginning.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L550

Added line #L550 was not covered by tests
self.media_player.setPosition(0)
self.media_player.play()

@Slot()
def play_pause(self) -> None:
state = self.media_player.playbackState()
if state == QMediaPlayer.PlaybackState.PausedState:
logger.debug("[USER] Playing the slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L558

Added line #L558 was not covered by tests
self.media_player.play()
elif state == QMediaPlayer.PlaybackState.PlayingState:
logger.debug("[USER] Pausing the slide.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L561

Added line #L561 was not covered by tests
self.media_player.pause()

@Slot()
def full_screen(self) -> None:
if self.windowState() == Qt.WindowFullScreen:
logger.debug("[USER] Disabling full screen.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L567

Added line #L567 was not covered by tests
self.setWindowState(Qt.WindowNoState)
else:
logger.debug("[USER] Toggling full screen.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L570

Added line #L570 was not covered by tests
self.setWindowState(Qt.WindowFullScreen)

@Slot()
def hide_mouse(self) -> None:
if self.cursor().shape() == Qt.BlankCursor:
logger.debug("[USER] Showing the mouse cursor.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L576

Added line #L576 was not covered by tests
self.setCursor(Qt.ArrowCursor)
else:
logger.debug("[USER] Hiding the mouse cursor.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L579

Added line #L579 was not covered by tests
self.setCursor(Qt.BlankCursor)

def closeEvent(self, event: QCloseEvent) -> None: # noqa: N802
logger.debug("[USER] Close event.")
self.close()

def keyPressEvent(self, event: QKeyEvent) -> None: # noqa: N802
logger.debug(f"[USER] Key press event {event}.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L587

Added line #L587 was not covered by tests
key = event.key()
self.dispatch(key)
event.accept()
Loading