From b126a701391d84bab8a44489d73a51c383ce1f65 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 12 Mar 2023 13:00:46 +0000 Subject: [PATCH] Fix and improve hide played tracks Last played track is now not hidden until Config.HIDE_AFTER_PLAYING_OFFSET milliseconds after next track starts playing. --- app/config.py | 1 + app/musicmuster.py | 7 ++----- app/playlists.py | 35 ++++++++++++++++++++--------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/config.py b/app/config.py index 0b08a71..c64f846 100644 --- a/app/config.py +++ b/app/config.py @@ -49,6 +49,7 @@ class Config(object): ERRORS_TO = ['kae@midnighthax.com'] FADE_STEPS = 20 FADE_TIME = 3000 + HIDE_AFTER_PLAYING_OFFSET = 5000 INFO_TAB_TITLE_LENGTH = 15 LAST_PLAYED_TODAY_STRING = "Today" LOG_LEVEL_STDERR = logging.ERROR diff --git a/app/musicmuster.py b/app/musicmuster.py index 9a3dcf1..d1de68a 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -867,11 +867,8 @@ class Window(QMainWindow, Ui_MainWindow): self.hide_played_tracks = True self.btnHidePlayed.setText("Show played") - # Update all displayed playlists - with Session() as session: - for i in range(self.tabPlaylist.count()): - self.tabPlaylist.widget(i).hide_played_tracks( - self.hide_played_tracks) + # Update displayed playlist + self.visible_playlist_tab().hide_or_show_played_tracks() def import_track(self) -> None: """Import track file""" diff --git a/app/playlists.py b/app/playlists.py index 3f2a4c2..a485191 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -255,6 +255,8 @@ class PlaylistTab(QTableWidget): with Session() as session: self.save_playlist(session) + self.hide_or_show_played_tracks() + def _add_context_menu(self, text: str, action: Callable, disabled: bool = False) -> QAction: """ @@ -479,9 +481,9 @@ class PlaylistTab(QTableWidget): return [plr for plr in plrs if plr is not None] - def hide_played_tracks(self, hide: bool) -> None: + def hide_or_show_played_tracks(self) -> None: """ - Hide played tracks if hide is True else show them + Hide or show played tracks. Never hide current or next track """ @@ -489,19 +491,15 @@ class PlaylistTab(QTableWidget): current_next = [self._get_current_track_row_number(), self._get_next_track_row_number()] - with Session() as session: - played = [ - p.row_number for p in PlaylistRows.get_played_rows( - session, self.playlist_id) - ] - for row in range(self.rowCount()): - if row in current_next: - continue - if row in played: - if hide: - self.hideRow(row) - else: - self.showRow(row) + for row_number in range(self.rowCount()): + if row_number in current_next: + continue + + if self._get_row_userdata(row_number, self.PLAYED): + if self.musicmuster.hide_played_tracks: + self.hideRow(row_number) + else: + self.showRow(row_number) def insert_header(self, session: scoped_session, note: str) -> None: """ @@ -650,6 +648,10 @@ class PlaylistTab(QTableWidget): # Update start/stop times self._update_start_end_times() + # Update hidden tracks* + QTimer.singleShot(Config.HIDE_AFTER_PLAYING_OFFSET, + self.hide_or_show_played_tracks) + def populate_display(self, session: scoped_session, playlist_id: int, scroll_to_top: bool = True) -> None: """ @@ -860,6 +862,8 @@ class PlaylistTab(QTableWidget): # Set row heights self.resizeRowsToContents() self.setColumnWidth(len(columns) - 1, 0) + # Hide/show rows + self.hide_or_show_played_tracks() # # ########## Internally called functions ########## @@ -1408,6 +1412,7 @@ class PlaylistTab(QTableWidget): if not plr: return plr.played = False + self.hide_or_show_played_tracks() self._update_start_end_times() def _move_row(self, session: scoped_session, plr: PlaylistRows,