From cc01d04fb842a6e5127378272c4c747d2bb663d4 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 14 Dec 2024 10:22:25 +0000 Subject: [PATCH] Remove section timing marks from displayed headers --- app/playlistmodel.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 62c19d3..dfa4e06 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -1213,6 +1213,19 @@ class PlaylistModel(QAbstractTableModel): log.debug(f"{self}: _reversed_contiguous_row_groups() returned: {result=}") return result + def remove_section_timer_markers(self, header_text: str) -> str: + """ + Remove characters used to mark section timeings from + passed header text. Return header text witout markers + """ + + while header_text.endswith(Config.SECTION_STARTS): + header_text = header_text[0:-1] + while header_text.endswith(Config.SECTION_ENDINGS): + header_text = header_text[0:-1] + + return header_text + def rowCount(self, index: QModelIndex = QModelIndex()) -> int: """Standard function for view""" @@ -1256,10 +1269,10 @@ class PlaylistModel(QAbstractTableModel): ", section end time " + section_end_time.strftime(Config.TRACK_TIME_FORMAT) ) - stripped_note = rat.note[:-1].strip() - if stripped_note: + clean_header = self.remove_section_timer_markers(rat.note) + if clean_header: return ( - f"{stripped_note} [" + f"{clean_header} [" f"{unplayed_count}/{count} track{'s' if count > 1 else ''} " f"({ms_to_mmss(duration)}) unplayed{end_time_str}]" ) @@ -1469,12 +1482,14 @@ class PlaylistModel(QAbstractTableModel): unplayed_count: int = 0 duration: int = 0 + clean_header = self.remove_section_timer_markers(rat.note) + for row_number in range(rat.row_number + 1, len(self.playlist_rows)): row_rat = self.playlist_rows[row_number] if self.is_header_row(row_number): if row_rat.note.endswith(Config.SECTION_ENDINGS): return ( - f"{rat.note[:-1].strip()} " + f"{clean_header} " f"[{count} tracks, {ms_to_mmss(duration)} unplayed]" ) else: @@ -1485,7 +1500,7 @@ class PlaylistModel(QAbstractTableModel): unplayed_count += 1 duration += row_rat.duration return ( - f"{rat.note[:-1].strip()} " + f"{clean_header} " f"[{count} tracks, {ms_to_mmss(duration, none='none')} " "unplayed (to end of playlist)]" )