From 0f1d5117cc14d619de6df2c6db2c539b82c1a038 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Mon, 27 Nov 2023 22:44:20 +0000 Subject: [PATCH] V3 tweaks --- app/classes.py | 1 + app/musicmuster.py | 2 -- app/playlistmodel.py | 21 ++++++++++++++------- app/playlists.py | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/app/classes.py b/app/classes.py index 25c78e6..04b7cd0 100644 --- a/app/classes.py +++ b/app/classes.py @@ -83,6 +83,7 @@ class MusicMusterSignals(QObject): enable_escape_signal = pyqtSignal(bool) end_reset_model_signal = pyqtSignal(int) next_track_changed_signal = pyqtSignal() + resize_rows_signal = pyqtSignal(int) row_order_changed_signal = pyqtSignal(int) search_songfacts_signal = pyqtSignal(str) search_wikipedia_signal = pyqtSignal(str) diff --git a/app/musicmuster.py b/app/musicmuster.py index 520d895..179e4f0 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1218,8 +1218,6 @@ class Window(QMainWindow, Ui_MainWindow): def search_playlist_clear(self) -> None: """Tidy up and reset search bar""" - # Clear the search text - self.active_tab().set_search("") # Clean up search bar self.txtSearch.setText("") self.txtSearch.setHidden(True) diff --git a/app/playlistmodel.py b/app/playlistmodel.py index 0d0f673..a8b46bb 100644 --- a/app/playlistmodel.py +++ b/app/playlistmodel.py @@ -182,6 +182,8 @@ class PlaylistModel(QAbstractTableModel): # Repaint row self.invalidate_row(row_number) + self.signals.resize_rows_signal.emit(self.playlist_id) + def background_role(self, row: int, column: int, prd: PlaylistRowData) -> QBrush: """Return background setting""" @@ -578,6 +580,7 @@ class PlaylistModel(QAbstractTableModel): """ count: int = 0 + unplayed_count: int = 0 duration: int = 0 if prd.note.endswith("+"): @@ -595,6 +598,7 @@ class PlaylistModel(QAbstractTableModel): else: count += 1 if not row_prd.played: + unplayed_count += 1 duration += row_prd.duration return ( f"{prd.note[:-1].strip()} " @@ -632,19 +636,21 @@ class PlaylistModel(QAbstractTableModel): stripped_note = prd.note[:-1].strip() if stripped_note: return ( - f"{stripped_note} [{count} track{'s' if count > 1 else ''}, " - f"{ms_to_mmss(duration)} unplayed{end_time_str}]" + f"{stripped_note} [" + f"{unplayed_count}/{count} track{'s' if count > 1 else ''} " + f"({ms_to_mmss(duration)}) unplayed{end_time_str}]" ) else: return ( - f"[Subtotal: {count} track{'s' if count > 1 else ''}, " - f"{ms_to_mmss(duration, none='none')} unplayed{end_time_str}]" + f"[{unplayed_count}/{count} track{'s' if count > 1 else ''} " + f"({ms_to_mmss(duration)}) unplayed{end_time_str}]" ) else: continue else: count += 1 if not row_prd.played: + unplayed_count += 1 duration += row_prd.duration return prd.note @@ -885,6 +891,7 @@ class PlaylistModel(QAbstractTableModel): # Carry out the move outside of the session context to ensure # database updated with any note change self.move_rows([existing_prd.plr_rownum], new_row_number) + self.signals.resize_rows_signal.emit(self.playlist_id) def move_track_to_header( self, header_row_number: int, existing_prd: PlaylistRowData, note: Optional[str] @@ -932,6 +939,8 @@ class PlaylistModel(QAbstractTableModel): log.error(f"OBS SDK error ({e})") return + self.signals.resize_rows_signal.emit(self.playlist_id) + def open_in_audacity(self, row_number: int) -> None: """ Open track at passed row number in Audacity @@ -965,9 +974,6 @@ class PlaylistModel(QAbstractTableModel): # Update display self.invalidate_row(track_sequence.previous.plr_rownum) - # Update track times - # TODO - def refresh_data(self, session: scoped_session): """Populate dicts for data calls""" @@ -1006,6 +1012,7 @@ class PlaylistModel(QAbstractTableModel): set_track_metadata(track) self.refresh_row(session, row_number) self.invalidate_row(row_number) + self.signals.resize_rows_signal.emit(self.playlist_id) def _reversed_contiguous_row_groups( self, row_numbers: List[int] diff --git a/app/playlists.py b/app/playlists.py index c3a21db..1403d41 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -123,7 +123,7 @@ class EscapeDelegate(QStyledItemDelegate): else: edit_index = index - value = editor.toPlainText() + value = editor.toPlainText().strip() self.playlist_model.setData(edit_index, value, Qt.ItemDataRole.EditRole) def updateEditorGeometry(self, editor, option, index): @@ -187,6 +187,7 @@ class PlaylistTab(QTableView): h_header.setStretchLastSection(True) # self.signals.set_next_track_signal.connect(self._reset_next) self.signals = MusicMusterSignals() + self.signals.resize_rows_signal.connect(self.resizeRowsToContents) self.signals.span_cells_signal.connect(self._span_cells) # Initialise miscellaneous instance variables @@ -583,6 +584,7 @@ class PlaylistTab(QTableView): return self.playlist_model.delete_rows(self.selected_model_row_numbers()) + self.clear_selection() def get_selected_rows(self) -> List[int]: """Return a list of selected row numbers sorted by row"""