From 96080cdca082058ff5cc8a5d708cbb36f7810ab8 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 21 Jul 2024 09:49:18 +0100 Subject: [PATCH] Simply musicmuster:play_next Split out return_pressed_in_error() --- app/musicmuster.py | 71 +++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index 9504168..99ad8f9 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1123,35 +1123,8 @@ class Window(QMainWindow, Ui_MainWindow): return # Check for inadvertent press of 'return' - if track_sequence.current and self.catch_return_key: - # Suppress inadvertent double press - if ( - track_sequence.current - and track_sequence.current.start_time - and track_sequence.current.start_time - + dt.timedelta(milliseconds=Config.RETURN_KEY_DEBOUNCE_MS) - > dt.datetime.now() - ): - return - # If return is pressed during first PLAY_NEXT_GUARD_MS then - # default to NOT playing the next track, else default to - # playing it. - default_yes: bool = track_sequence.current.start_time is not None and ( - (dt.datetime.now() - track_sequence.current.start_time).total_seconds() - * 1000 - > Config.PLAY_NEXT_GUARD_MS - ) - if default_yes: - msg = "Hit return to play next track now" - else: - msg = "Press tab to select Yes and hit return to play next track" - if not helpers.ask_yes_no( - "Play next track", - msg, - default_yes=default_yes, - parent=self, - ): - return + if self.return_pressed_in_error(): + return # Issue #223 concerns a very short pause (maybe 0.1s) sometimes # when starting to play at track. @@ -1386,6 +1359,46 @@ class Window(QMainWindow, Ui_MainWindow): session.rollback() session.close() + def return_pressed_in_error(self) -> bool: + """ + Check whether Return key has been pressed in error. + + Return True if it has, False if not + """ + + if track_sequence.current and self.catch_return_key: + # Suppress inadvertent double press + if ( + track_sequence.current + and track_sequence.current.start_time + and track_sequence.current.start_time + + dt.timedelta(milliseconds=Config.RETURN_KEY_DEBOUNCE_MS) + > dt.datetime.now() + ): + return True + + # If return is pressed during first PLAY_NEXT_GUARD_MS then + # default to NOT playing the next track, else default to + # playing it. + default_yes: bool = track_sequence.current.start_time is not None and ( + (dt.datetime.now() - track_sequence.current.start_time).total_seconds() + * 1000 + > Config.PLAY_NEXT_GUARD_MS + ) + if default_yes: + msg = "Hit return to play next track now" + else: + msg = "Press tab to select Yes and hit return to play next track" + if not helpers.ask_yes_no( + "Play next track", + msg, + default_yes=default_yes, + parent=self, + ): + return True + + return False + def resume(self) -> None: """ Resume playing last track. We may be playing the next track