From 36f6e670221b05b0df7cb2c9c7d59f9739677c10 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 14 Jun 2010 14:56:15 +0100 Subject: [PATCH] Small cleanups after testing --- .../gui2/dialogs/edit_authors_dialog.py | 28 +++++++++++++------ src/calibre/library/database2.py | 4 +-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/dialogs/edit_authors_dialog.py b/src/calibre/gui2/dialogs/edit_authors_dialog.py index 8d13f98f7a..6e7eef3add 100644 --- a/src/calibre/gui2/dialogs/edit_authors_dialog.py +++ b/src/calibre/gui2/dialogs/edit_authors_dialog.py @@ -23,7 +23,6 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): self.setupUi(self) self.buttonBox.accepted.connect(self.accepted) - self.table.cellChanged.connect(self.cell_changed) self.table.setSelectionMode(QAbstractItemView.SingleSelection) self.table.setColumnCount(2) @@ -43,13 +42,18 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): self.table.setItem(row, 1, sort) if id == id_to_select: select_item = sort + self.table.resizeColumnsToContents() + # set up the signal after the table is filled + self.table.cellChanged.connect(self.cell_changed) + + self.table.setSortingEnabled(True) + self.table.sortByColumn(1, Qt.AscendingOrder) if select_item is not None: self.table.setCurrentItem(select_item) self.table.editItem(select_item) - self.table.resizeColumnsToContents() - self.table.setSortingEnabled(True) - self.table.sortByColumn(1, Qt.AscendingOrder) + else: + self.table.setCurrentCell(0, 0) def accepted(self): self.result = [] @@ -63,8 +67,16 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog): def cell_changed(self, row, col): if col == 0: - aut = unicode(self.table.item(row, 0).text()) + item = self.table.item(row, 0) + aut = unicode(item.text()) c = self.table.item(row, 1) - if c is not None: - c.setText(author_to_author_sort(aut)) - self.table.setCurrentItem(c) + c.setText(author_to_author_sort(aut)) + item = c + else: + item = self.table.item(row, 1) + self.table.setCurrentItem(item) + # disable and reenable sorting to force the sort now, so we can scroll + # to the item after it moves + self.table.setSortingEnabled(False) + self.table.setSortingEnabled(True) + self.table.scrollToItem(item) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index e2302c1c77..72f33b677c 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -938,8 +938,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): def author_sort_from_authors(self, authors): result = [] for aut in authors: - aut = aut.replace(',', '|') - r = self.conn.get('SELECT sort FROM authors WHERE name=?', (aut,), all=False) + r = self.conn.get('SELECT sort FROM authors WHERE name=?', + (aut.replace(',', '|'),), all=False) if r is None: result.append(author_to_author_sort(aut)) else: