From 95aadb867a77145fc6cc23eb4c720599e538526b Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Tue, 28 Nov 2023 14:29:49 +0000 Subject: [PATCH] V3 hide played tracks Don't hide previous track until delay after playing next track. --- app/playlistmodel.py | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index bc0fdb6..f6335b1 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -13,6 +13,7 @@ from PyQt6.QtCore import ( QRegularExpression, QSortFilterProxyModel, Qt, + QTimer, QVariant, ) from PyQt6.QtGui import ( @@ -278,6 +279,11 @@ class PlaylistModel(QAbstractTableModel): # Update colour and times for current row self.invalidate_row(row_number) + + # Update previous row in case we're hiding played rows + if track_sequence.previous.plr_rownum: + self.invalidate_row(track_sequence.previous.plr_rownum) + # Update all other track times self.update_track_times() @@ -1365,9 +1371,46 @@ class PlaylistProxyModel(QSortFilterProxyModel): if ( now_plr and now_plr.plr_rownum == source_row - and now_plr.playlist_id == self.playlist_model.playlist_id + and now_plr.playlist_id == self.data_model.playlist_id ): return True + # Don't hide previous track until + # HIDE_AFTER_PLAYING_OFFSET milliseconds after + # current track has started + if track_sequence.previous.plr_id: + previous_plr = session.get( + PlaylistRows, track_sequence.previous.plr_id + ) + if ( + previous_plr + and previous_plr.plr_rownum == source_row + and previous_plr.playlist_id == self.data_model.playlist_id + ): + print("Checking previous track") + if track_sequence.now.start_time: + if datetime.now() > ( + track_sequence.now.start_time + + timedelta( + milliseconds=Config.HIDE_AFTER_PLAYING_OFFSET + ) + ): + return False + else: + # Invalidate this row in + # HIDE_AFTER_PLAYING_OFFSET and a + # bit milliseconds + # so that it hides then - add 100mS + # on so that it if clause above it + # true next time through. + print("queuing singleshot") + QTimer.singleShot( + Config.HIDE_AFTER_PLAYING_OFFSET + 100, + lambda: self.data_model.invalidate_row(source_row), + ) + return True + else: + return True + return False return super().filterAcceptsRow(source_row, source_parent)