From a74e6eda0662f1c032fee4e5c04f6484d21131dc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 2 Sep 2014 12:44:15 +0530 Subject: [PATCH] Workaround for Qt 5 behavior change on OS X which prevented error handling during startup on OS X to not work --- src/calibre/gui2/__init__.py | 6 ++++++ src/calibre/gui2/main.py | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 5632bf9546..bb20aea75f 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1040,6 +1040,12 @@ class Application(QApplication): if colors != self.color_prefs.get('custom_colors_for_color_dialog', None): self.color_prefs.set('custom_colors_for_color_dialog', colors) + def __enter__(self): + self.setQuitOnLastWindowClosed(False) + + def __exit__(self, *args): + self.setQuitOnLastWindowClosed(True) + _store_app = None class SanitizeLibraryPath(object): diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 91aea0c038..8fa8143c31 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -199,7 +199,8 @@ class GuiRunner(QObject): def hide_splash_screen(self): if self.splash_screen is not None: - self.splash_screen.hide() + with self.app: + self.splash_screen.hide() self.splash_screen = None def choose_dir(self, initial_dir): @@ -210,7 +211,8 @@ class GuiRunner(QObject): def show_error(self, title, msg, det_msg=''): self.hide_splash_screen() - error_dialog(self.main, title, msg, det_msg=det_msg, show=True) + with self.app: + error_dialog(self.main, title, msg, det_msg=det_msg, show=True) def initialization_failed(self): print 'Catastrophic failure initializing GUI, bailing out...' @@ -254,14 +256,15 @@ class GuiRunner(QObject): db = LibraryDatabase(self.library_path) except apsw.Error: self.hide_splash_screen() - repair = question_dialog(None, _('Corrupted database'), - _('The library database at %s appears to be corrupted. Do ' - 'you want calibre to try and rebuild it automatically? ' - 'The rebuild may not be completely successful. ' - 'If you say No, a new empty calibre library will be created.') - % force_unicode(self.library_path, filesystem_encoding), - det_msg=traceback.format_exc() - ) + with self.app: + repair = question_dialog(None, _('Corrupted database'), + _('The library database at %s appears to be corrupted. Do ' + 'you want calibre to try and rebuild it automatically? ' + 'The rebuild may not be completely successful. ' + 'If you say No, a new empty calibre library will be created.') + % force_unicode(self.library_path, filesystem_encoding), + det_msg=traceback.format_exc() + ) if repair: if repair_library(self.library_path): db = LibraryDatabase(self.library_path)