From b9fd7a5d218a3e1df49c34d68c56510dede74592 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sun, 12 Mar 2023 16:23:36 +0000 Subject: [PATCH] Clean up editing --- app/playlists.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/app/playlists.py b/app/playlists.py index 9aece64..3119c0c 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -295,11 +295,9 @@ class PlaylistTab(QTableWidget): # Call sequences: # Start editing: # edit() - # _cell_edit_started() # End editing: # _cell_changed() (only if changes made) # closeEditor() - # _cell_edit_ended() def _cell_changed(self, row: int, column: int) -> None: """Called when cell content has changed""" @@ -386,18 +384,17 @@ class PlaylistTab(QTableWidget): event: QEvent) -> bool: """ Override PySide2.QAbstractItemView.edit to catch when editing starts + + Editing only ever starts with a double click on a cell """ + # 'result' will only be true on double-click result = super(PlaylistTab, self).edit(index, trigger, event) - if result: # will only be true on double-clicke + if result: row = index.row() column = index.column() - - # Is this a track row? - track_row = self._get_row_track_id(row) - note_column = 0 - if track_row: + if self._get_row_track_id(row): # If a track row, we only allow editing of title, artist and # note. Check that this column is one of those. if column in [TITLE, ARTIST, ROW_NOTES]: @@ -423,19 +420,14 @@ class PlaylistTab(QTableWidget): # If this is a note cell, we need to remove any existing section # timing so user can't edit that. Keep it simple: refresh text - # from database. Note column will only be non-zero if we are + # from database. note_column will only be non-zero if we are # editing a note. if note_column: with Session() as session: plr_item = self._get_row_plr(session, row) - item = self.item(row, note_column) - if not item: - return False if not plr_item: return False - if not plr_item.note: - plr_item.note = '' - item.setText(plr_item.note) + self._set_row_note_text(session, row, plr_item.note) # Connect signal so we know when cell has changed. self.cellChanged.connect(self._cell_changed)