mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup cell_changed handling
This commit is contained in:
parent
cf3f5f131d
commit
9c0923e110
@ -6,6 +6,7 @@ __docformat__ = 'restructuredtext en'
|
||||
__license__ = 'GPL v3'
|
||||
|
||||
from functools import partial
|
||||
from contextlib import contextmanager
|
||||
|
||||
from qt.core import (Qt, QDialog, QTableWidgetItem, QAbstractItemView, QIcon,
|
||||
QDialogButtonBox, QFrame, QLabel, QTimer, QMenu, QApplication,
|
||||
@ -97,6 +98,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.table.setColumnWidth(2, 200)
|
||||
|
||||
# set up the cellChanged signal only after the table is filled
|
||||
self.ignore_cell_changed = False
|
||||
self.table.cellChanged.connect(self.cell_changed)
|
||||
|
||||
self.recalc_author_sort.clicked.connect(self.do_recalc_author_sort)
|
||||
@ -170,6 +172,15 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.link_order = 1
|
||||
self.show_table(id_to_select, select_sort, select_link, is_first_letter)
|
||||
|
||||
@contextmanager
|
||||
def no_cell_changed(self):
|
||||
orig = self.ignore_cell_changed
|
||||
self.ignore_cell_changed = True
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
self.ignore_cell_changed = orig
|
||||
|
||||
def use_vl_changed(self, x):
|
||||
self.show_table(None, None, None, False)
|
||||
|
||||
@ -440,7 +451,7 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.result.append((id_, orig['name'], v['name'], v['sort'], v['link']))
|
||||
|
||||
def do_recalc_author_sort(self):
|
||||
self.table.cellChanged.disconnect()
|
||||
with self.no_cell_changed():
|
||||
for row in range(0,self.table.rowCount()):
|
||||
item_aut = self.table.item(row, 0)
|
||||
id_ = int(item_aut.data(Qt.ItemDataRole.UserRole))
|
||||
@ -452,10 +463,9 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.authors[id_]['sort'] = aus
|
||||
self.set_icon(item_aus, id_)
|
||||
self.table.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||
self.table.cellChanged.connect(self.cell_changed)
|
||||
|
||||
def do_auth_sort_to_author(self):
|
||||
self.table.cellChanged.disconnect()
|
||||
with self.no_cell_changed():
|
||||
for row in range(0,self.table.rowCount()):
|
||||
aus = str(self.table.item(row, 1).text()).strip()
|
||||
item_aut = self.table.item(row, 0)
|
||||
@ -464,7 +474,6 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
self.authors[id_]['name'] = aus
|
||||
self.set_icon(item_aut, id_)
|
||||
self.table.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||
self.table.cellChanged.connect(self.cell_changed)
|
||||
|
||||
def set_icon(self, item, id_):
|
||||
col_name = self.get_column_name(item.column())
|
||||
@ -474,8 +483,10 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
item.setIcon(self.empty_icon)
|
||||
|
||||
def cell_changed(self, row, col):
|
||||
if self.ignore_cell_changed:
|
||||
return
|
||||
with self.no_cell_changed():
|
||||
id_ = int(self.table.item(row, 0).data(Qt.ItemDataRole.UserRole))
|
||||
self.table.cellChanged.disconnect(self.cell_changed)
|
||||
if col == 0:
|
||||
item = self.table.item(row, 0)
|
||||
aut = str(item.text()).strip()
|
||||
@ -498,6 +509,5 @@ class EditAuthorsDialog(QDialog, Ui_EditAuthorsDialog):
|
||||
item.set_sort_key()
|
||||
self.set_icon(item, id_)
|
||||
self.authors[id_][self.get_column_name(col)] = str(item.text())
|
||||
self.table.cellChanged.connect(self.cell_changed)
|
||||
self.table.setCurrentItem(item)
|
||||
self.table.scrollToItem(item)
|
||||
|
Loading…
x
Reference in New Issue
Block a user