diff --git a/app/playlists.py b/app/playlists.py index 497a64f..3cc8cac 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -56,6 +56,7 @@ from models import ( ) start_time_re = re.compile(r"@\d\d:\d\d:\d\d") +HEADER_NOTES_COLUMN = 2 class RowMeta: @@ -224,7 +225,7 @@ class PlaylistTab(QTableWidget): # rows. Check and fix: for row in range(drop_row, drop_row + len(rows_to_move)): if not self._get_row_track_id(row): - self.setSpan(row, 1, 1, len(columns)) + self.setSpan(row, HEADER_NOTES_COLUMN, 1, len(columns)) # Scroll to drop zone self.scrollToItem(self.item(row, 1)) @@ -419,8 +420,8 @@ class PlaylistTab(QTableWidget): editor: QWidget, hint: QAbstractItemDelegate.EndEditHint) -> None: """ - Override QAbstractItemView.closeEditor to enable play controls - and update display. + Override PySide2.QAbstractItemView.closeEditor to enable + play controls and update display. """ # update_display to update start times, such as when a note has @@ -437,7 +438,7 @@ class PlaylistTab(QTableWidget): trigger: QAbstractItemView.EditTrigger, event: QEvent) -> bool: """ - Override QAbstractItemView.edit to catch when editing starts + Override PySide2.QAbstractItemView.edit to catch when editing starts """ result = super(PlaylistTab, self).edit(index, trigger, event) @@ -461,16 +462,16 @@ class PlaylistTab(QTableWidget): self.edit_cell_type = "row_notes" else: # Can't edit other columns - return + return False # Check whether we're editing a notes row for later if self.edit_cell_type == "row_notes": note_column = columns['row_notes'].idx else: - # This is a section header. Text is always in row 1. - if column != 1: - return - note_column = 1 + # This is a section header. + if column != HEADER_NOTES_COLUMN: + return False + note_column = HEADER_NOTES_COLUMN self.edit_cell_type = "row_notes" # Disable play controls so that keyboard input doesn't @@ -629,12 +630,16 @@ class PlaylistTab(QTableWidget): # Make empty items (row background won't be coloured without # items present). Any notes should displayed starting in - # column 0 - for i in range(2, len(columns)): + # column 2 for now - bug in Qt means that when row size is + # set, spanned columns are ignored, so put notes in col2 + # (typically title). + for i in range(1, len(columns)): + if i == 2: + continue self.setItem(row, i, QTableWidgetItem()) - self.setSpan(row, 1, 1, len(columns)) + self.setSpan(row, HEADER_NOTES_COLUMN, 1, len(columns) - 1) notes_item = QTableWidgetItem(row_data.note) - self.setItem(row, 1, notes_item) + self.setItem(row, HEADER_NOTES_COLUMN, notes_item) # Save (no) track_id userdata_item.setData(self.ROW_TRACK_ID, 0) @@ -1383,7 +1388,7 @@ class PlaylistTab(QTableWidget): if track_id: item_note = self.item(row, columns['row_notes'].idx) else: - item_note = self.item(row, 1) + item_note = self.item(row, HEADER_NOTES_COLUMN) return item_note.text() def _get_row_start_time(self, row: int) -> Optional[datetime]: @@ -1607,7 +1612,7 @@ class PlaylistTab(QTableWidget): for i in range(2, len(columns)): self.item(row, i).setText("") # Set note text in correct column for section head - self.item(row, 1).setText(plr.note) + self.item(row, HEADER_NOTES_COLUMN).setText(plr.note) # Remove row duration self._set_row_duration(row, 0) # Remote track_id from row @@ -1825,12 +1830,12 @@ class PlaylistTab(QTableWidget): additional_text: str) -> None: """Append additional_text to row display""" - # Column to update is either 1 for a section header or the - # appropriate row_notes column for a track row + # Column to update is either HEADER_NOTES_COLUMN for a section + # header or the appropriate row_notes column for a track row if playlist_row.track_id: column = columns['row_notes'].idx else: - column = 1 + column = HEADER_NOTES_COLUMN # Update text new_text = playlist_row.note + additional_text