WIP playlists refactor including fixing saving playlist

This commit is contained in:
Keith Edmunds 2023-02-25 19:45:56 +00:00
parent cc2f3733b2
commit 45a564729b
2 changed files with 29 additions and 27 deletions

View File

@ -527,11 +527,9 @@ class Window(QMainWindow, Ui_MainWindow):
"Can't close current track playlist", 5000)
return False
# Don't close next track playlist
# Attempt to close next track playlist
if self.tabPlaylist.widget(tab_index) == self.next_track.playlist_tab:
self.statusbar.showMessage(
"Can't close next track playlist", 5000)
return False
self.next_track.playlist_tab.mark_unnext()
# Record playlist as closed and update remaining playlist tabs
with Session() as session:
@ -648,6 +646,8 @@ class Window(QMainWindow, Ui_MainWindow):
def debug(self):
"""Invoke debugger"""
visible_playlist_id = self.visible_playlist_tab().playlist_id
print(f"Active playlist id={visible_playlist_id}")
import ipdb # type: ignore
ipdb.set_trace()

View File

@ -170,6 +170,7 @@ class PlaylistTab(QTableWidget):
self.horizontalHeader().sectionResized.connect(
self.resizeRowsToContents)
# Drag and drop setup
self.setAcceptDrops(True)
self.viewport().setAcceptDrops(True)
self.setDragDropOverwriteMode(False)
@ -291,7 +292,7 @@ class PlaylistTab(QTableWidget):
act_unnext = self.menu.addAction(
"Unmark as next track")
act_unnext.triggered.connect(
lambda: self._mark_unnext(row_number))
lambda: self.mark_unnext())
if sep:
self.menu.addSeparator()
@ -441,7 +442,7 @@ class PlaylistTab(QTableWidget):
track_id = self._get_row_track_id(row)
# Determin cell type changed
# Determine cell type changed
with Session() as session:
# Get playlistrow object
plr_id = self._get_playlistrow_id(row)
@ -461,8 +462,12 @@ class PlaylistTab(QTableWidget):
self._set_row_start_time(row, start_time)
else:
self._set_row_start_time(row, None)
# Update display including note colour
# Update note display
self._set_row_note(session, row, new_text)
# If this is a header row, ecalcuate track times in case
# note added a start time
if not track_id:
self._update_start_end_times()
else:
track = None
if track_id:
@ -594,14 +599,14 @@ class PlaylistTab(QTableWidget):
return [self._get_playlistrow_id(a) for a in self._get_selected_rows()]
def get_selected_playlistrows(
self, session: scoped_session) -> Optional[List[PlaylistRows]]:
self, session: scoped_session) -> List[PlaylistRows]:
"""
Return a list of PlaylistRows of the selected rows
"""
plr_ids = self.get_selected_playlistrow_ids()
if not plr_ids:
return None
return []
plrs = [session.get(PlaylistRows, a) for a in plr_ids]
return [plr for plr in plrs if plr is not None]
@ -701,7 +706,8 @@ class PlaylistTab(QTableWidget):
_ = self._set_row_userdata(row, self.ROW_TRACK_ID, 0)
if update_track_times:
self._update_start_end_times()
# Queue time updates so playlist updates first
QTimer.singleShot(0, lambda: self._update_start_end_times())
def insert_track(self, session: scoped_session, track: Tracks,
note: Optional[str] = None, repaint: bool = True) -> None:
@ -744,6 +750,19 @@ class PlaylistTab(QTableWidget):
# Let display update, then save playlist
QTimer.singleShot(0, lambda: self.save_playlist(session))
def mark_unnext(self) -> None:
"""
Unmark passed row as next track
"""
row = self._get_next_track_row_number()
if not row:
return
self.musicmuster.clear_next()
self.clear_selection()
self._set_row_colour(row, None)
self.musicmuster.update_headers()
def play_started(self, session: scoped_session) -> None:
"""
Notification from musicmuster that track has started playing.
@ -834,13 +853,6 @@ class PlaylistTab(QTableWidget):
for row in sorted(row_numbers, reverse=True):
self.removeRow(row)
def remove_selected_rows(self) -> None:
"""Remove selected rows from display"""
self.remove_rows(self._get_selected_rows())
# Reset drag mode
self.setDragEnabled(False)
def reset_plr_row_colour(self, plr_id: int) -> None:
"""Reset background of row pointed to by plr_id"""
@ -1639,16 +1651,6 @@ class PlaylistTab(QTableWidget):
and pos.y() >= rect.center().y() # noqa W503
)
def _mark_unnext(self, row: int) -> None:
"""
Unmark passed row as next track
"""
self.musicmuster.clear_next()
self.clear_selection()
self._set_row_colour(row, None)
self.musicmuster.update_headers()
def _mark_unplayed(self, plr: PlaylistRows) -> None:
"""
Mark passed row as unplayed in this playlist