Fix and improve hide played tracks

Last played track is now not hidden until
Config.HIDE_AFTER_PLAYING_OFFSET milliseconds after next track starts
playing.
This commit is contained in:
Keith Edmunds 2023-03-12 13:00:46 +00:00
parent f30fff5356
commit b126a70139
3 changed files with 23 additions and 20 deletions

View File

@ -49,6 +49,7 @@ class Config(object):
ERRORS_TO = ['kae@midnighthax.com'] ERRORS_TO = ['kae@midnighthax.com']
FADE_STEPS = 20 FADE_STEPS = 20
FADE_TIME = 3000 FADE_TIME = 3000
HIDE_AFTER_PLAYING_OFFSET = 5000
INFO_TAB_TITLE_LENGTH = 15 INFO_TAB_TITLE_LENGTH = 15
LAST_PLAYED_TODAY_STRING = "Today" LAST_PLAYED_TODAY_STRING = "Today"
LOG_LEVEL_STDERR = logging.ERROR LOG_LEVEL_STDERR = logging.ERROR

View File

@ -867,11 +867,8 @@ class Window(QMainWindow, Ui_MainWindow):
self.hide_played_tracks = True self.hide_played_tracks = True
self.btnHidePlayed.setText("Show played") self.btnHidePlayed.setText("Show played")
# Update all displayed playlists # Update displayed playlist
with Session() as session: self.visible_playlist_tab().hide_or_show_played_tracks()
for i in range(self.tabPlaylist.count()):
self.tabPlaylist.widget(i).hide_played_tracks(
self.hide_played_tracks)
def import_track(self) -> None: def import_track(self) -> None:
"""Import track file""" """Import track file"""

View File

@ -255,6 +255,8 @@ class PlaylistTab(QTableWidget):
with Session() as session: with Session() as session:
self.save_playlist(session) self.save_playlist(session)
self.hide_or_show_played_tracks()
def _add_context_menu(self, text: str, action: Callable, def _add_context_menu(self, text: str, action: Callable,
disabled: bool = False) -> QAction: disabled: bool = False) -> QAction:
""" """
@ -479,9 +481,9 @@ class PlaylistTab(QTableWidget):
return [plr for plr in plrs if plr is not None] return [plr for plr in plrs if plr is not None]
def hide_played_tracks(self, hide: bool) -> None: def hide_or_show_played_tracks(self) -> None:
""" """
Hide played tracks if hide is True else show them Hide or show played tracks.
Never hide current or next track Never hide current or next track
""" """
@ -489,19 +491,15 @@ class PlaylistTab(QTableWidget):
current_next = [self._get_current_track_row_number(), current_next = [self._get_current_track_row_number(),
self._get_next_track_row_number()] self._get_next_track_row_number()]
with Session() as session: for row_number in range(self.rowCount()):
played = [ if row_number in current_next:
p.row_number for p in PlaylistRows.get_played_rows( continue
session, self.playlist_id)
] if self._get_row_userdata(row_number, self.PLAYED):
for row in range(self.rowCount()): if self.musicmuster.hide_played_tracks:
if row in current_next: self.hideRow(row_number)
continue else:
if row in played: self.showRow(row_number)
if hide:
self.hideRow(row)
else:
self.showRow(row)
def insert_header(self, session: scoped_session, note: str) -> None: def insert_header(self, session: scoped_session, note: str) -> None:
""" """
@ -650,6 +648,10 @@ class PlaylistTab(QTableWidget):
# Update start/stop times # Update start/stop times
self._update_start_end_times() self._update_start_end_times()
# Update hidden tracks*
QTimer.singleShot(Config.HIDE_AFTER_PLAYING_OFFSET,
self.hide_or_show_played_tracks)
def populate_display(self, session: scoped_session, playlist_id: int, def populate_display(self, session: scoped_session, playlist_id: int,
scroll_to_top: bool = True) -> None: scroll_to_top: bool = True) -> None:
""" """
@ -860,6 +862,8 @@ class PlaylistTab(QTableWidget):
# Set row heights # Set row heights
self.resizeRowsToContents() self.resizeRowsToContents()
self.setColumnWidth(len(columns) - 1, 0) self.setColumnWidth(len(columns) - 1, 0)
# Hide/show rows
self.hide_or_show_played_tracks()
# # ########## Internally called functions ########## # # ########## Internally called functions ##########
@ -1408,6 +1412,7 @@ class PlaylistTab(QTableWidget):
if not plr: if not plr:
return return
plr.played = False plr.played = False
self.hide_or_show_played_tracks()
self._update_start_end_times() self._update_start_end_times()
def _move_row(self, session: scoped_session, plr: PlaylistRows, def _move_row(self, session: scoped_session, plr: PlaylistRows,