feat(cli): add next-terminates-loop CLI option (#299)

* feat(cli): add `next-terminates-loop` CLI option

Closes #254

* chore(lib): fix `--next-terminates-loop`

* chore(CHANGELOG): document changes
This commit is contained in:
Jérome Eertmans
2023-10-30 10:50:26 +01:00
committed by GitHub
parent 6c52906037
commit 106c7d4c06
3 changed files with 22 additions and 2 deletions

View File

@ -219,6 +219,12 @@ def start_at_callback(
default=1.0,
help="Playback rate of the video slides, see PySide6 docs for details.",
)
@click.option(
"--next-terminates-loop",
"next_terminates_loop",
is_flag=True,
help="If set, pressing next will turn any looping slide into a play slide.",
)
@click.help_option("-h", "--help")
@verbosity_option
def present(
@ -234,8 +240,9 @@ def present(
start_at: Tuple[Optional[int], Optional[int], Optional[int]],
start_at_scene_number: int,
start_at_slide_number: int,
screen_number: Optional[int] = None,
playback_rate: float = 1.0,
screen_number: Optional[int],
playback_rate: float,
next_terminates_loop: bool,
) -> None:
"""
Present SCENE(s), one at a time, in order.
@ -296,6 +303,7 @@ def present(
slide_index=start_at_slide_number,
screen=screen,
playback_rate=playback_rate,
next_terminates_loop=next_terminates_loop,
)
player.show()

View File

@ -54,6 +54,7 @@ class Player(QMainWindow): # type: ignore[misc]
slide_index: int = 0,
screen: Optional[QScreen] = None,
playback_rate: float = 1.0,
next_terminates_loop: bool = False,
):
super().__init__()
@ -125,6 +126,7 @@ class Player(QMainWindow): # type: ignore[misc]
# Misc
self.exit_after_last_slide = exit_after_last_slide
self.next_terminates_loop = next_terminates_loop
# Setting-up everything
@ -313,6 +315,12 @@ class Player(QMainWindow): # type: ignore[misc]
def next(self) -> None:
if self.media_player.playbackState() == QMediaPlayer.PausedState:
self.media_player.play()
elif self.next_terminates_loop and self.media_player.loops() != 1:
position = self.media_player.position()
self.media_player.setLoops(1)
self.media_player.stop()
self.media_player.setPosition(position)
self.media_player.play()
else:
self.load_next_slide()