From ee7436221e784ec95cda68b330b31ca87903bafa Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Thu, 9 Mar 2023 08:35:16 +0000 Subject: [PATCH] Playlist save / session work --- app/musicmuster.py | 6 ++++-- app/playlists.py | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/musicmuster.py b/app/musicmuster.py index 6772b44..6958099 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1813,8 +1813,10 @@ class DbDialog(QDialog): self.musicmuster.visible_playlist_tab().insert_header( self.session, note=self.ui.txtNote.text()) - # Save to database (which will also commit changes) - self.musicmuster.visible_playlist_tab().save_playlist(self.session) + # TODO: this shouldn't be needed as insert_track() saves + # playlist + # # Save to database (which will also commit changes) + # self.musicmuster.visible_playlist_tab().save_playlist(self.session) # Clear note field and select search text to make it easier for # next search self.ui.txtNote.clear() diff --git a/app/playlists.py b/app/playlists.py index 9b351c3..df41b9d 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -566,7 +566,7 @@ class PlaylistTab(QTableWidget): if update_track_times: # Queue time updates so playlist updates first - QTimer.singleShot(0, lambda: self._update_start_end_times()) + QTimer.singleShot(0, self._update_start_end_times) def insert_track(self, session: scoped_session, track: Tracks, note: str = "", repaint: bool = True) -> None: @@ -606,8 +606,11 @@ class PlaylistTab(QTableWidget): plr = PlaylistRows(session, self.playlist_id, track.id, row_number, note) self.insert_row(session, plr) + session.flush() + # Let display update, then save playlist - QTimer.singleShot(0, lambda: self.save_playlist(session)) + # TODO: QTimer.singleShot(0, lambda: self.save_playlist(session)) + self.save_playlist(session) def play_ended(self) -> None: """ @@ -1085,8 +1088,8 @@ class PlaylistTab(QTableWidget): self.save_playlist(session) - # Queue time updates so playlist updates first - QTimer.singleShot(0, lambda: self._update_start_end_times()) + # Queue time updates so playlist updates first + QTimer.singleShot(0, self._update_start_end_times) def _drop_on(self, event): """ @@ -1549,7 +1552,8 @@ class PlaylistTab(QTableWidget): ) self._set_row_colour_unreadable(row) - self.clear_selection() + self._update_start_end_times() + self.clear_selection() def _run_subprocess(self, args): """Run args in subprocess""" @@ -2125,9 +2129,13 @@ class PlaylistTab(QTableWidget): header_rows = [] - # Get section header PlaylistRows + # Get section header PlaylistRows. Flush session first in case + # there are pending playlist changes that affect which row + # numbers are headers. + session.flush() plrs = PlaylistRows.get_section_header_rows(session, self.playlist_id) for plr in plrs: + # TODO: print(f"{plr.row_number=}") if plr.note.endswith("+"): header_rows.append(plr) continue