Fix development bug that truncated playlists

Saving of playlist and updating note colours more consistent.
This commit is contained in:
Keith Edmunds 2023-03-12 10:33:10 +00:00
parent 80e698680b
commit f30fff5356
2 changed files with 44 additions and 19 deletions

View File

@ -727,11 +727,9 @@ class Window(QMainWindow, Ui_MainWindow):
Actions required:
- Set flag to say we're not playing a track
- Reset current track
- Tell playlist_tab track has finished
- Reset current playlist_tab
- Reset PlaylistTrack objects
- Reset clocks
- Reset end time
- Update headers
- Enable controls
"""
@ -740,7 +738,7 @@ class Window(QMainWindow, Ui_MainWindow):
# doesn't see player=None and kick off end-of-track actions
self.playing = False
# Remove currently playing track colour
# Tell playlist_tab track has finished
if self.current_track.playlist_tab:
self.current_track.playlist_tab.play_ended()

View File

@ -518,6 +518,10 @@ class PlaylistTab(QTableWidget):
plr = PlaylistRows(session, self.playlist_id, None, row_number, note)
self.insert_row(session, plr)
self._set_row_header_text(session, row_number, note)
self.save_playlist(session)
# Queue up time calculations to take place after UI has
# updated
QTimer.singleShot(0, self._update_start_end_times)
def insert_row(self, session: scoped_session, plr: PlaylistRows,
update_track_times: bool = True, played=False) -> None:
@ -556,13 +560,6 @@ class PlaylistTab(QTableWidget):
# Set bold as needed
self._set_row_bold(row, bold)
self.save_playlist(session)
if update_track_times:
# Queue up time calculations to take place after UI has
# updated
QTimer.singleShot(0, self._update_start_end_times)
def insert_track(self, session: scoped_session, track: Tracks,
note: str = "", repaint: bool = True) -> None:
"""
@ -601,17 +598,23 @@ class PlaylistTab(QTableWidget):
plr = PlaylistRows(session, self.playlist_id, track.id,
row_number, note)
self.insert_row(session, plr)
self.save_playlist(session)
# Queue up time calculations to take place after UI has
# updated
QTimer.singleShot(0, self._update_start_end_times)
def play_ended(self) -> None:
"""
Called by musicmuster when play has ended
"""
row = self._get_current_track_row_number()
if not row:
row_number = self._get_current_track_row_number()
if not row_number:
return
self._set_row_colour_default(row)
self._set_row_colour_default(row_number)
self.clear_selection()
with Session() as session:
self._set_row_note_colour(session, row_number)
def play_started(self, session: scoped_session) -> None:
"""
@ -685,13 +688,14 @@ class PlaylistTab(QTableWidget):
# Set widths
self._set_column_widths(session)
self.save_playlist(session)
# Queue up time calculations to take place after UI has
# updated
QTimer.singleShot(0, self._update_start_end_times)
# Needed to wrap notes column correctly - add to event queue so
# that it's processed after list is populated
QTimer.singleShot(0, self.tab_visible)
# Set track start/end times after track list is populated
QTimer.singleShot(0, self._update_start_end_times)
def remove_rows(self, row_numbers: List[int]) -> None:
"""Remove passed rows from display"""
@ -1422,6 +1426,9 @@ class PlaylistTab(QTableWidget):
plr.row_number = new_row_number
self.insert_row(session, plr)
self.save_playlist(session)
# Queue up time calculations to take place after UI has
# updated
QTimer.singleShot(0, self._update_start_end_times)
def _mplayer_play(self, track_id: int) -> None:
"""Play track with mplayer"""
@ -1930,6 +1937,27 @@ class PlaylistTab(QTableWidget):
self._set_row_bold(row, False)
def _set_row_note_colour(self, session: scoped_session,
row_number: int) -> None:
"""
Set row note colour
"""
# Sanity check: this should be a track row and thus have a
# track associated
if not self._get_row_track_id(row_number):
send_mail(Config.ERRORS_TO,
Config.ERRORS_FROM,
"playists:_set_row_note_colour() called on header row",
stackprinter.format()
)
return
# Set colour
note_text = self._get_row_note(row_number)
note_colour = NoteColours.get_colour(session, note_text)
self._set_cell_colour(row_number, ROW_NOTES, note_colour)
def _set_row_note_text(self, session: scoped_session,
row_number: int, text: str) -> None:
"""
@ -1950,8 +1978,7 @@ class PlaylistTab(QTableWidget):
_ = self._set_item_text(row_number, ROW_NOTES, text)
# Set colour
note_colour = NoteColours.get_colour(session, text)
self._set_cell_colour(row_number, ROW_NOTES, note_colour)
self._set_row_note_colour(session, row_number)
def _set_row_plr_id(self, row: int, plr_id: int) -> QTableWidgetItem:
"""