From 79b13973a1689e610439ecbdfdca1eb57bd9907a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Dec 2013 14:00:40 +0530 Subject: [PATCH] Auto-fixing of individual errors --- src/calibre/gui2/tweak_book/boss.py | 4 ++-- src/calibre/gui2/tweak_book/check.py | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index c690cc430d..fd4d3e44fb 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -705,13 +705,13 @@ class Boss(QObject): c.run_checks(current_container()) @in_thread_job - def fix_requested(self): + def fix_requested(self, errors): self.commit_all_editors_to_container() self.add_savepoint(_('Auto-fix errors')) c = self.gui.check_book c.parent().show() c.parent().raise_() - changed = c.fix_errors(current_container()) + changed = c.fix_errors(current_container(), errors) if changed: self.apply_container_update_to_gui() self.set_modified() diff --git a/src/calibre/gui2/tweak_book/check.py b/src/calibre/gui2/tweak_book/check.py index 3a1aaf6991..e9f62ed86a 100644 --- a/src/calibre/gui2/tweak_book/check.py +++ b/src/calibre/gui2/tweak_book/check.py @@ -39,7 +39,7 @@ class Check(QSplitter): item_activated = pyqtSignal(object) check_requested = pyqtSignal() - fix_requested = pyqtSignal() + fix_requested = pyqtSignal(object) def __init__(self, parent=None): QSplitter.__init__(self, parent) @@ -79,7 +79,12 @@ class Check(QSplitter): elif url == 'run:check': self.check_requested.emit() elif url == 'fix:errors': - self.fix_requested.emit() + errors = [self.items.item(i).data(Qt.UserRole).toPyObject() for i in xrange(self.items.count())] + self.fix_requested.emit(errors) + elif url.startswith('fix:error,'): + num = int(url.rpartition(',')[-1]) + errors = [self.items.item(num).data(Qt.UserRole).toPyObject()] + self.fix_requested.emit(errors) def next_error(self, delta=1): row = self.items.currentRow() @@ -108,13 +113,18 @@ class Check(QSplitter): loc += ' column: %d' % err.col if loc: loc = ' (%s)' % loc + ifix = '' + if err.INDIVIDUAL_FIX: + ifix = '%s

' % ( + self.items.currentRow(), _('Try to fix only this error'), err.INDIVIDUAL_FIX) + self.help.setText( '''

%s [%d]

%s %s

%s

-
%s

+
%s%s

%s
- ''' % (header, self.items.currentRow()+1, _('Click to open in editor'), err.name, loc, err.HELP, + ''' % (header, self.items.currentRow()+1, _('Click to open in editor'), err.name, loc, err.HELP, ifix, _('Try to fix all errors automatically. Only works for some types of error.'), _('Try fixing errors automatically'), _('Re-run the check'), _('Re-run check'))) @@ -137,10 +147,9 @@ class Check(QSplitter): else: self.clear_help(_('No problems found')) - def fix_errors(self, container): + def fix_errors(self, container, errors): from calibre.gui2.tweak_book.boss import BusyCursor with BusyCursor(): - errors = [self.items.item(i).data(Qt.UserRole).toPyObject() for i in xrange(self.items.count())] self.show_busy(_('Running fixers, please wait...')) QApplication.processEvents() changed = fix_errors(container, errors)