From cf66cef60ae4514fb1b9ec9477558ed71bd37771 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Mon, 25 Mar 2024 17:48:56 +0000 Subject: [PATCH] Use dialog box to check for unintended play next track --- app/musicmuster.py | 55 ++++++++++++---------------------------- app/ui/main_window.ui | 2 -- app/ui/main_window_ui.py | 4 +-- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index dd9ac9b..e782378 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -238,13 +238,13 @@ class Window(QMainWindow, Ui_MainWindow): else: self.carts_init() self.disable_selection_timing = False - self.enable_play_next_controls() self.clock_counter = 0 self.timer10.start(10) self.timer500.start(500) self.timer1000.start(1000) self.signals = MusicMusterSignals() self.connect_signals_slots() + self.catch_return_key = False self.load_last_playlists() def about(self) -> None: @@ -517,7 +517,6 @@ class Window(QMainWindow, Ui_MainWindow): self.actionDownload_CSV_of_played_tracks.triggered.connect( self.download_played_tracks ) - self.actionEnable_controls.triggered.connect(self.enable_play_next_controls) self.actionExport_playlist.triggered.connect(self.export_playlist_tab) self.actionFade.triggered.connect(self.fade) self.actionImport.triggered.connect(self.import_track) @@ -652,14 +651,6 @@ class Window(QMainWindow, Ui_MainWindow): else: log.error("Failed to retrieve playlist") - def disable_play_next_controls(self) -> None: - """ - Disable "play next" keyboard controls - """ - - self.actionPlay_next.setEnabled(False) - self.show_status_message("Play controls: Disabled", 0) - def download_played_tracks(self) -> None: """Download a CSV of played tracks""" @@ -705,14 +696,6 @@ class Window(QMainWindow, Ui_MainWindow): self.action_Clear_selection.setEnabled(enabled) - def enable_play_next_controls(self) -> None: - """ - Enable "play next" keyboard controls - """ - - self.actionPlay_next.setEnabled(True) - self.show_status_message("Play controls: Enabled", 0) - def export_playlist_tab(self) -> None: """Export the current playlist to an m3u file""" @@ -1106,6 +1089,16 @@ class Window(QMainWindow, Ui_MainWindow): - Update headers """ + # Check for inadvertent press of 'return' + if self.catch_return_key: + if not helpers.ask_yes_no( + "Track playing", + "Really play next track now?", + default_yes=True, + parent=self, + ): + return + log.info(f"play_next({position=})") # If there is no next track set, return. @@ -1148,7 +1141,7 @@ class Window(QMainWindow, Ui_MainWindow): self.playing = True # Disable play next controls - self.disable_play_next_controls() + self.catch_return_key = True # Notify model self.active_proxy_model().current_track_started() @@ -1170,22 +1163,6 @@ class Window(QMainWindow, Ui_MainWindow): break sleep(0.1) - # Try making playing the last thing we do here to see whether - # the occasional short pause at the start of the track can be - # eliminated. - - # # Notify model - # self.active_proxy_model().current_track_started() - - # # Note that track is now playing - # self.playing = True - - # # Disable play next controls - # self.disable_play_next_controls() - - # # Update headers - # self.update_headers() - def preview(self) -> None: """ Preview selected or next track. We use a different mechanism to @@ -1291,7 +1268,7 @@ class Window(QMainWindow, Ui_MainWindow): # Disable play controls so that 'return' in search box doesn't # play next track - self.disable_play_next_controls() + self.catch_return_key = True self.txtSearch.setHidden(False) self.txtSearch.setFocus() # Select any text that may already be there @@ -1498,7 +1475,7 @@ class Window(QMainWindow, Ui_MainWindow): self.update_headers() # Enable controls - self.enable_play_next_controls() + self.catch_return_key = False def tab_change(self): """Called when active tab changed""" @@ -1578,7 +1555,7 @@ class Window(QMainWindow, Ui_MainWindow): css_silence = f"background: {Config.COLOUR_ENDING_TIMER}" if self.frame_silent.styleSheet() != css_silence: self.frame_silent.setStyleSheet(css_silence) - self.enable_play_next_controls() + self.catch_return_key = False # Set warning colour on time to silence box when fade starts elif time_to_fade <= 500: css_fade = f"background: {Config.COLOUR_WARNING_TIMER}" @@ -1590,7 +1567,7 @@ class Window(QMainWindow, Ui_MainWindow): self.frame_fade.setStyleSheet( f"background: {Config.COLOUR_WARNING_TIMER}" ) - self.enable_play_next_controls() + self.catch_return_key = False else: self.frame_silent.setStyleSheet("") self.frame_fade.setStyleSheet("") diff --git a/app/ui/main_window.ui b/app/ui/main_window.ui index 5193324..e1e3bcc 100644 --- a/app/ui/main_window.ui +++ b/app/ui/main_window.ui @@ -775,8 +775,6 @@ padding-left: 8px; - - diff --git a/app/ui/main_window_ui.py b/app/ui/main_window_ui.py index f640405..0e2413b 100644 --- a/app/ui/main_window_ui.py +++ b/app/ui/main_window_ui.py @@ -1,6 +1,6 @@ # Form implementation generated from reading ui file 'app/ui/main_window.ui' # -# Created by: PyQt6 UI code generator 6.6.0 +# Created by: PyQt6 UI code generator 6.6.1 # # WARNING: Any manual changes made to this file will be lost when pyuic6 is # run again. Do not edit this file unless you know what you are doing. @@ -487,8 +487,6 @@ class Ui_MainWindow(object): self.menuPlaylist.addAction(self.actionSetNext) self.menuPlaylist.addAction(self.action_Clear_selection) self.menuPlaylist.addSeparator() - self.menuPlaylist.addAction(self.actionEnable_controls) - self.menuPlaylist.addSeparator() self.menuPlaylist.addAction(self.actionMark_for_moving) self.menuPlaylist.addAction(self.actionPaste) self.menuSearc_h.addAction(self.actionSearch)