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

View File

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