Tidy playlist header colours

Simplify and also ensure that playlist tab is uncoloured after
unsetting next track.
This commit is contained in:
Keith Edmunds 2023-03-25 15:52:17 +00:00
parent 4a03596bd3
commit 25287c8f7f
2 changed files with 59 additions and 70 deletions

View File

@ -579,7 +579,7 @@ class Window(QMainWindow, Ui_MainWindow):
self.actionSelect_previous_track.triggered.connect(
self.select_previous_row)
self.actionMoveUnplayed.triggered.connect(self.move_unplayed)
self.actionSetNext.triggered.connect(self.set_next_track_from_mm)
self.actionSetNext.triggered.connect(self.set_selected_track_next)
self.actionSkipToNext.triggered.connect(self.play_next)
self.actionStop.triggered.connect(self.stop)
self.btnDrop3db.clicked.connect(self.drop3db)
@ -1304,27 +1304,25 @@ class Window(QMainWindow, Ui_MainWindow):
with Session() as session:
# Set next plr to be track to resume
plr_resume = session.get(PlaylistRows, self.previous_track.plr_id)
if not plr_resume:
if not self.previous_track.plr_id:
return
plr_tab_resume = self.previous_track.playlist_tab
if not plr_tab_resume:
if not self.previous_track.playlist_tab:
return
# Resume last track
self._set_next_plr(session, plr_resume, plr_tab_resume)
self.set_next_plr_id(self.previous_track.plr_id,
self.previous_track.playlist_tab)
self.play_next(self.previous_track_position)
# If a track was playing when we were called, get details to
# set it as the next track
if playing_track:
plr_next = session.get(PlaylistRows, playing_track.plr_id)
if not plr_next:
if not playing_track.plr_id:
return
plr_tab_next = playing_track.playlist_tab
if not plr_tab_next:
if not playing_track.playlist_tab:
return
self._set_next_plr(session, plr_next, plr_tab_next)
self.set_next_plr_id(playing_track.plr_id,
playing_track.playlist_tab)
def save_as_template(self) -> None:
"""Save current playlist as template"""
@ -1497,68 +1495,59 @@ class Window(QMainWindow, Ui_MainWindow):
# May also be called when last tab is closed
pass
def set_next_track_from_playlist(self, playlist_tab: PlaylistTab,
next_plr_id: int) -> None:
"""
Called from playlist tab to notify us of next track
"""
with Session() as session:
next_plr = session.get(PlaylistRows, next_plr_id)
if not next_plr:
return
self._set_next_plr(session, next_plr, playlist_tab)
def set_next_track_from_mm(self) -> None:
def set_selected_track_next(self) -> None:
"""
Set currently-selected row on visible playlist tab as next track
"""
playlist_tab = self.visible_playlist_tab()
selected_plr_ids = playlist_tab.get_selected_playlistrow_ids()
if len(selected_plr_ids) != 1:
log.error(f"set_next_track:_from_mm {selected_plr_ids=}")
return
self.set_next_plr_id(selected_plr_ids[0], playlist_tab)
def set_next_plr_id(self, next_plr_id: Optional[int],
playlist_tab: PlaylistTab) -> None:
"""
Set passed plr_id as next track to play, or clear next track if None
Actions required:
- Update self.next_track PlaylistTrack structure
- Set playlist tab colours
- Tell playlist tabs to update their 'next track' highlighting
- Update headers
- Set playlist tab colours
- Populate info tabs
"""
with Session() as session:
playlist_tab = self.visible_playlist_tab()
selected_plrs = playlist_tab.get_selected_playlistrows(session)
if len(selected_plrs) != 1:
log.error(f"set_next_track:_from_mm {selected_plrs=}")
return
next_plr = selected_plrs[0]
self._set_next_plr(session, next_plr, playlist_tab)
# Update self.next_track PlaylistTrack structure
old_next_track = self.next_track
self.next_track = PlaylistTrack()
if next_plr_id:
next_plr = session.get(PlaylistRows, next_plr_id)
if next_plr:
self.next_track.set_plr(session, next_plr, playlist_tab)
def _set_next_plr(self, session: scoped_session,
next_plr: PlaylistRows,
playlist_tab: PlaylistTab) -> None:
"""
Set next_plr as the next track to play
"""
# Tell playlist tabs to update their 'next track' highlighting
self.signals.set_next_track_signal.emit(old_next_track.plr_id,
next_plr_id)
# Build PlaylistTrack structure for new next track
old_next_track = self.next_track
self.next_track = PlaylistTrack()
self.next_track.set_plr(session, next_plr, playlist_tab)
# Update headers
self.update_headers()
# Set playlist tab colours
self._set_next_track_playlist_tab_colours(old_next_track)
# Set playlist tab colours
self._set_next_track_playlist_tab_colours(old_next_track)
# Tell playlist tabs to update themselves
self.signals.set_next_track_signal.emit(old_next_track.plr_id,
next_plr.id)
# Update headers
self.update_headers()
# Populate 'info' tabs with Wikipedia info, but queue it because
# it isn't quick
track_title = self.next_track.title
QTimer.singleShot(
1, lambda: self.tabInfolist.open_in_wikipedia(track_title)
)
if next_plr_id:
# Populate 'info' tabs with Wikipedia info, but queue it
# because it isn't quick
if self.next_track.title:
QTimer.singleShot(
1, lambda: self.tabInfolist.open_in_wikipedia(
self.next_track.title)
)
def _set_next_track_playlist_tab_colours(
self, old_next_track: Optional[PlaylistTrack]) -> None:

View File

@ -464,7 +464,7 @@ class PlaylistTab(QTableWidget):
else:
return self.rowCount()
def get_selected_playlistrow_ids(self) -> Optional[List]:
def get_selected_playlistrow_ids(self) -> list:
"""
Return a list of PlaylistRow ids of the selected rows
"""
@ -651,8 +651,8 @@ class PlaylistTab(QTableWidget):
# Set next track
next_row = self._find_next_track_row(session, current_row + 1)
if next_row:
self.musicmuster.set_next_track_from_playlist(
self, self._get_row_plr_id(next_row))
self.musicmuster.set_next_plr_id(self._get_row_plr_id(next_row),
self)
# Display row as current track
self._set_row_colour_current(current_row)
@ -740,6 +740,8 @@ class PlaylistTab(QTableWidget):
self._set_row_colour_default(row_number)
self.clear_selection()
self.musicmuster.set_next_plr_id(None, self)
def save_playlist(self, session: scoped_session) -> None:
"""
Get the PlaylistRow objects for each row in the display. Correct
@ -1722,21 +1724,19 @@ class PlaylistTab(QTableWidget):
old_plr = new_plr = None
if old_plrid:
old_plr = session.get(PlaylistRows, old_plrid)
if not new_plrid:
log.error(f"_reset_next called with {new_plrid=}")
return
new_plr = session.get(PlaylistRows, new_plrid)
if not new_plr:
log.error(f"_reset_next({new_plrid=}): plr not found")
return
# Unmark next track
if old_plr and old_plr.playlist_id == self.playlist_id:
self._set_row_colour_default(old_plr.row_number)
# Mark next track
if new_plr and new_plr.playlist_id == self.playlist_id:
self._set_row_colour_next(new_plr.row_number)
if new_plrid:
new_plr = session.get(PlaylistRows, new_plrid)
if not new_plr:
log.error(f"_reset_next({new_plrid=}): plr not found")
return
if new_plr.playlist_id == self.playlist_id:
self._set_row_colour_next(new_plr.row_number)
# Update start/stop times
self._update_start_end_times(session)