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