Implement hiding played sections

This commit is contained in:
Keith Edmunds 2024-12-14 20:46:19 +00:00
parent b16845f352
commit efde8fe7bc
4 changed files with 46 additions and 4 deletions

View File

@ -61,6 +61,8 @@ class Config(object):
HEADER_START_TIME = "Start"
HEADER_TITLE = "Title"
HIDE_AFTER_PLAYING_OFFSET = 5000
HIDE_PLAYED_MODE_TRACKS = "TRACKS"
HIDE_PLAYED_MODE_SECTIONS = "SECTIONS"
INFO_TAB_TITLE_LENGTH = 15
INTRO_SECONDS_FORMAT = ".1f"
INTRO_SECONDS_WARNING_MS = 3000
@ -114,5 +116,6 @@ class Config(object):
WIKIPEDIA_ON_NEXT = False
# These rely on earlier definitions
HIDE_PLAYED_MODE = HIDE_PLAYED_MODE_SECTIONS
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
REPLACE_FILES_DEFAULT_DESTINATION = os.path.dirname(REPLACE_FILES_DEFAULT_SOURCE)

View File

@ -655,8 +655,8 @@ class Window(QMainWindow, Ui_MainWindow):
track_sequence.previous = track_sequence.current
track_sequence.current = None
# Tell model previous track has finished
self.active_proxy_model().previous_track_ended()
# Tell playlist previous track has finished
self.active_tab().previous_track_ended()
# Reset clocks
self.frame_fade.setStyleSheet("")
@ -736,6 +736,9 @@ class Window(QMainWindow, Ui_MainWindow):
self.hide_played_tracks = True
self.active_proxy_model().hide_played_tracks(True)
self.btnHidePlayed.setText("Show played")
if Config.HIDE_PLAYED_MODE == Config.HIDE_PLAYED_MODE_SECTIONS:
self.active_tab().hide_played_sections()
# Reset row heights
self.active_tab().resize_rows()

View File

@ -102,6 +102,22 @@ class PlaylistModel(QAbstractTableModel):
f"<PlaylistModel: playlist_id={self.playlist_id}, {self.rowCount()} rows>"
)
def active_section_header(self) -> int:
"""
Return the row number of the header above the first unplayed
or currently being played track.
"""
header_row = 0
for row_number in range(len(self.playlist_rows)):
if self.is_header_row(row_number):
header_row = row_number
elif not self.is_played_row(row_number):
return header_row
return header_row
def add_track_to_header(
self, row_number: int, track_id: int, note: Optional[str] = None
) -> None:
@ -1647,6 +1663,9 @@ class PlaylistProxyModel(QSortFilterProxyModel):
Subclass to filter by played status. Return True to show this row, False to hide it.
"""
if Config.HIDE_PLAYED_MODE != Config.HIDE_PLAYED_MODE_TRACKS:
return True
if self.source_model.played_tracks_hidden:
if self.source_model.is_played_row(source_row):
# Don't hide current track

View File

@ -801,6 +801,13 @@ class PlaylistTab(QTableView):
log.debug(f"get_selected_rows() returned: {result=}")
return result
def hide_played_sections(self) -> None:
"""
Scroll played sections off screen
"""
self.scroll_to_top(self.source_model.active_section_header())
def _import_from_audacity(self, row_number: int) -> None:
"""
Import current Audacity track to passed row
@ -871,6 +878,17 @@ class PlaylistTab(QTableView):
except ApplicationError as e:
show_warning(self.musicmuster, "Audacity error", str(e))
def previous_track_ended(self) -> None:
"""
Called when track ends
"""
# Let the model know
self.source_model.previous_track_ended()
# Scroll to current section if hide mode is by section
if Config.HIDE_PLAYED_MODE == Config.HIDE_PLAYED_MODE_SECTIONS:
self.hide_played_sections()
def _remove_comments(self) -> None:
"""
Remove comments from selected rows
@ -913,8 +931,7 @@ class PlaylistTab(QTableView):
def scroll_to_top(self, row_number: int) -> None:
"""
Scroll to put passed row_number Config.SCROLL_TOP_MARGIN from the
top.
Scroll to put passed row_number at the top of the displayed playlist.
"""
if row_number is None: