Remove section timing marks from displayed headers

This commit is contained in:
Keith Edmunds 2024-12-14 10:22:25 +00:00
parent ac18773ebd
commit cc01d04fb8

View File

@ -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)]"
)