Ensure splash screen is hidden if there is an error during startup, so that the error message does not appear behind the splash screen thanks to regressions in Qt 5

This commit is contained in:
Kovid Goyal 2014-09-02 11:17:41 +05:30
parent 38d9af3fe0
commit a2a111da8c

View File

@ -121,7 +121,7 @@ def get_default_library_path():
return x return x
def get_library_path(parent=None): def get_library_path(gui_runner):
library_path = prefs['library_path'] library_path = prefs['library_path']
if library_path is None: # Need to migrate to new database layout if library_path is None: # Need to migrate to new database layout
base = os.path.expanduser('~') base = os.path.expanduser('~')
@ -130,9 +130,7 @@ def get_library_path(parent=None):
if not base or not os.path.exists(base): if not base or not os.path.exists(base):
from PyQt5.Qt import QDir from PyQt5.Qt import QDir
base = unicode(QDir.homePath()).replace('/', os.sep) base = unicode(QDir.homePath()).replace('/', os.sep)
candidate = choose_dir(None, 'choose calibre library', candidate = gui_runner.choose_dir(base)
_('Choose a location for your calibre e-book library'),
default_dir=base)
if not candidate: if not candidate:
candidate = os.path.join(base, 'Calibre Library') candidate = os.path.join(base, 'Calibre Library')
library_path = os.path.abspath(candidate) library_path = os.path.abspath(candidate)
@ -140,13 +138,11 @@ def get_library_path(parent=None):
try: try:
os.makedirs(library_path) os.makedirs(library_path)
except: except:
error_dialog(parent, _('Failed to create library'), gui_runner.show_error(_('Failed to create library'),
_('Failed to create calibre library at: %r.\n' _('Failed to create calibre library at: %r.\n'
'You will be asked to choose a new library location.')%library_path, 'You will be asked to choose a new library location.')%library_path,
det_msg=traceback.format_exc(), show=True) det_msg=traceback.format_exc())
library_path = choose_dir(parent, 'choose calibre library', library_path = gui_runner.choose_dir(get_default_library_path())
_('Choose a location for your new calibre e-book library'),
default_dir=get_default_library_path())
return library_path return library_path
def repair_library(library_path): def repair_library(library_path):
@ -201,6 +197,21 @@ class GuiRunner(QObject):
add_filesystem_book(event) add_filesystem_book(event)
self.app.file_event_hook = add_filesystem_book self.app.file_event_hook = add_filesystem_book
def hide_splash_screen(self):
if self.splash_screen is not None:
self.splash_screen.hide()
self.splash_screen = None
def choose_dir(self, initial_dir):
self.hide_splash_screen()
return choose_dir(None, 'choose calibre library',
_('Choose a location for your new calibre e-book library'),
default_dir=initial_dir)
def show_error(self, title, msg, det_msg=''):
self.hide_splash_screen()
error_dialog(self.main, title, msg, det_msg=det_msg, show=True)
def initialization_failed(self): def initialization_failed(self):
print 'Catastrophic failure initializing GUI, bailing out...' print 'Catastrophic failure initializing GUI, bailing out...'
QCoreApplication.exit(1) QCoreApplication.exit(1)
@ -211,14 +222,11 @@ class GuiRunner(QObject):
if db is None and tb is not None: if db is None and tb is not None:
# DB Repair failed # DB Repair failed
error_dialog(None, _('Repairing failed'), self.show_error(_('Repairing failed'), _(
_('The database repair failed. Starting with ' 'The database repair failed. Starting with a new empty library.'),
'a new empty library.'), det_msg=tb)
det_msg=tb, show=True)
if db is None: if db is None:
candidate = choose_dir(None, 'choose calibre library', candidate = self.choose_dir(get_default_library_path())
_('Choose a location for your new calibre e-book library'),
default_dir=get_default_library_path())
if not candidate: if not candidate:
self.initialization_failed() self.initialization_failed()
@ -226,19 +234,18 @@ class GuiRunner(QObject):
self.library_path = candidate self.library_path = candidate
db = LibraryDatabase(candidate) db = LibraryDatabase(candidate)
except: except:
error_dialog(None, _('Bad database location'), self.show_error(_('Bad database location'), _(
_('Bad database location %r. calibre will now quit.' 'Bad database location %r. calibre will now quit.')%self.library_path,
)%self.library_path, det_msg=traceback.format_exc())
det_msg=traceback.format_exc(), show=True)
self.initialization_failed() self.initialization_failed()
try: try:
self.start_gui(db) self.start_gui(db)
except Exception: except Exception:
error_dialog(self.main, _('Startup error'), self.show_error(_('Startup error'), _(
_('There was an error during {0} startup.' 'There was an error during {0} startup. Parts of {0} may not function.'
' Parts of {0} may not function. Click Show details to learn more.').format(__appname__), ' Click Show details to learn more.').format(__appname__),
det_msg=traceback.format_exc(), show=True) det_msg=traceback.format_exc())
def initialize_db(self): def initialize_db(self):
from calibre.db.legacy import LibraryDatabase from calibre.db.legacy import LibraryDatabase
@ -246,6 +253,7 @@ class GuiRunner(QObject):
try: try:
db = LibraryDatabase(self.library_path) db = LibraryDatabase(self.library_path)
except apsw.Error: except apsw.Error:
self.hide_splash_screen()
repair = question_dialog(None, _('Corrupted database'), repair = question_dialog(None, _('Corrupted database'),
_('The library database at %s appears to be corrupted. Do ' _('The library database at %s appears to be corrupted. Do '
'you want calibre to try and rebuild it automatically? ' 'you want calibre to try and rebuild it automatically? '
@ -258,10 +266,10 @@ class GuiRunner(QObject):
if repair_library(self.library_path): if repair_library(self.library_path):
db = LibraryDatabase(self.library_path) db = LibraryDatabase(self.library_path)
except: except:
error_dialog(None, _('Bad database location'), self.show_error(_('Bad database location'),
_('Bad database location %r. Will start with ' _('Bad database location %r. Will start with '
' a new, empty calibre library')%self.library_path, ' a new, empty calibre library')%self.library_path,
det_msg=traceback.format_exc(), show=True) det_msg=traceback.format_exc())
self.initialize_db_stage2(db, None) self.initialize_db_stage2(db, None)
@ -273,7 +281,7 @@ class GuiRunner(QObject):
if gprefs['show_splash_screen']: if gprefs['show_splash_screen']:
self.show_splash_screen() self.show_splash_screen()
self.library_path = get_library_path(parent=None) self.library_path = get_library_path(self)
if not self.library_path: if not self.library_path:
self.initialization_failed() self.initialization_failed()