diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index ded63cb952..920d9c3376 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -12,7 +12,7 @@ from urlparse import urlparse from PyQt5.Qt import ( QObject, QApplication, QDialog, QGridLayout, QLabel, QSize, Qt, - QDialogButtonBox, QIcon, QTimer, QPixmap, QInputDialog, QUrl) + QDialogButtonBox, QIcon, QPixmap, QInputDialog, QUrl) from calibre import prints, isbytestring from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory @@ -76,6 +76,7 @@ class Boss(QObject): self.tdir = None self.save_manager = SaveManager(parent, notify) self.save_manager.report_error.connect(self.report_save_error) + self.save_manager.check_for_completion.connect(self.check_terminal_save) self.doing_terminal_save = False self.ignore_preview_to_editor_sync = False setup_cssutils_serialization() @@ -951,8 +952,8 @@ class Boss(QObject): def report_save_error(self, tb): if self.doing_terminal_save: prints(tb, file=sys.stderr) - return - self.gui.action_save.setEnabled(True) + self.abort_terminal_save() + self.set_modified() error_dialog(self.gui, _('Could not save'), _('Saving of the book failed. Click "Show Details"' ' for more information. You can try to save a copy' @@ -1370,13 +1371,15 @@ class Boss(QObject): self.gui.blocking_job.set_msg(_('Saving, please wait...')) self.gui.blocking_job.start() self.doing_terminal_save = True - QTimer.singleShot(50, self.check_terminal_save) + + def abort_terminal_save(self): + self.doing_terminal_save = False + self.gui.blocking_job.stop() def check_terminal_save(self): - if self.save_manager.has_tasks: - return QTimer.singleShot(50, self.check_terminal_save) - self.shutdown() - QApplication.instance().quit() + if self.doing_terminal_save and not self.save_manager.has_tasks: # terminal save could have been aborted + self.shutdown() + QApplication.instance().quit() def shutdown(self): self.gui.preview.stop_refresh_timer() diff --git a/src/calibre/gui2/tweak_book/save.py b/src/calibre/gui2/tweak_book/save.py index a20d637341..4462fcbdb2 100644 --- a/src/calibre/gui2/tweak_book/save.py +++ b/src/calibre/gui2/tweak_book/save.py @@ -99,6 +99,7 @@ class SaveManager(QObject): start_save = pyqtSignal() report_error = pyqtSignal(object) save_done = pyqtSignal() + check_for_completion = pyqtSignal() def __init__(self, parent, notify=None): QObject.__init__(self, parent) @@ -128,14 +129,17 @@ class SaveManager(QObject): self.requests.task_done() self.__empty_queue() break + error_occurred = True try: count, tdir, container = x - self.process_save(count, tdir, container) + error_occurred = self.process_save(count, tdir, container) except: import traceback traceback.print_exc() finally: self.requests.task_done() + if not error_occurred: + self.check_for_completion.emit() def notify_calibre(self): while True: @@ -162,14 +166,17 @@ class SaveManager(QObject): return self.last_saved = count self.start_save.emit() + error_occurred = False try: self.do_save(tdir, container) except: import traceback self.report_error.emit(traceback.format_exc()) + error_occurred = True self.save_done.emit() if self.notify_data: self.notify_requests.put(True) + return error_occurred def do_save(self, tdir, container): try: