Skip to content

Commit

Permalink
fix(present): bug with Qt and Windows + debug messages
Browse files Browse the repository at this point in the history
Apparently, the "recommended* versions of Qt (i.e., Qt 6.5.1 and 6.5.2) produces errors.

I could not exactly re-produce #315, but I also have `failed to get textures for frame; format: 172 textureConverter null` in the output, as #315 (comment) mentioned.

After searching a bit, this feels like the faulty lines are (at least related to) https://github.com/jeertmans/manim-slides/blob/1dbd2fdde58030867f15d7bf0ecede11d59d6903/manim_slides/present/player.py#L245-L247.

I could not yet find a fix for that, but I created this PR for testing purposes... I also added quite a few debug prints, for the future.

When upgrading  Qt to 6.5.3 and above, the error message disappear, but we then have the same visual issue as described in #293.
  • Loading branch information
jeertmans committed Feb 27, 2024
1 parent 1dbd2fd commit d58af3a
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions manim_slides/present/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def __init__(
):
super().__init__()

logger.debug("Instantiating Player instance.")

# Wizard's config

self.config = config
Expand All @@ -206,21 +208,27 @@ def __init__(
# 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 +245,8 @@ def __init__(
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 +259,8 @@ def __init__(

# 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 +280,7 @@ def __init__(
# 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 +290,7 @@ def media_status_changed(status: QMediaPlayer.MediaStatus) -> None:
self.media_player.mediaStatusChanged.connect(media_status_changed)

else:
logger.debug("Adding a custom signal handler to skip slide if `--auto-next` is used.")

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L293

Added line #L293 was not covered by tests

def media_status_changed(status: QMediaPlayer.MediaStatus) -> None:
if (
Expand All @@ -288,6 +302,7 @@ def media_status_changed(status: QMediaPlayer.MediaStatus) -> None:
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 +406,7 @@ def playing_reversed_slide(self, playing_reversed_slide: bool) -> None:

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 +419,14 @@ def load_current_media(self, start_paused: bool = False) -> None:
)

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L422

Added line #L422 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 +438,7 @@ def load_current_slide(self) -> None:
self.load_current_media()

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L441

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

if self.current_slide_index > 0:
Expand All @@ -433,6 +453,7 @@ def load_previous_slide(self) -> None:
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 +472,7 @@ def load_next_slide(self) -> None:
self.load_current_slide()

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L475

Added line #L475 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 +483,22 @@ def load_reversed_slide(self) -> None:

@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 +518,7 @@ def close(self) -> None:

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L521

Added line #L521 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 +532,55 @@ def next(self) -> None:

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L535

Added line #L535 was not covered by tests
self.load_previous_slide()

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L540

Added line #L540 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 546 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L546

Added line #L546 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 554 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L554

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L557

Added line #L557 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 563 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L563

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L566

Added line #L566 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 572 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L572

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

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

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L575

Added line #L575 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 583 in manim_slides/present/player.py

View check run for this annotation

Codecov / codecov/patch

manim_slides/present/player.py#L583

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

0 comments on commit d58af3a

Please sign in to comment.