Playlist save / session work

This commit is contained in:
Keith Edmunds 2023-03-09 08:35:16 +00:00
parent 889d32cc90
commit ee7436221e
2 changed files with 18 additions and 8 deletions

View File

@ -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()

View File

@ -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