From c078cdddfdf01c4ed5c83b3c1b24d07cd8791547 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Dec 2019 20:33:39 +1000 Subject: [PATCH] if base folder can't be written, defer displaying message until qt is ready --- aqt/__init__.py | 29 ++++++++++++++++++++++------- aqt/profiles.py | 17 +---------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/aqt/__init__.py b/aqt/__init__.py index b9b4f56f5..f55769f60 100644 --- a/aqt/__init__.py +++ b/aqt/__init__.py @@ -332,11 +332,19 @@ def _run(argv=None, exec=True): opts, args = parseArgs(argv) # profile manager - pm = ProfileManager(opts.base) - pmLoadResult = pm.setupMeta() + pm = None + try: + pm = ProfileManager(opts.base) + pmLoadResult = pm.setupMeta() + except: + # will handle below + pass - # gl workarounds - setupGL(pm) + if pm: + # gl workarounds + setupGL(pm) + # apply user-provided scale factor + os.environ["QT_SCALE_FACTOR"] = str(pm.uiScale()) # opt in to full hidpi support? if not os.environ.get("ANKI_NOHIGHDPI"): @@ -348,9 +356,6 @@ def _run(argv=None, exec=True): if os.environ.get("ANKI_SOFTWAREOPENGL"): QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL) - # apply user-provided scale factor - os.environ["QT_SCALE_FACTOR"] = str(pm.uiScale()) - # create the app QCoreApplication.setApplicationName("Anki") QGuiApplication.setDesktopFileName("anki.desktop") @@ -359,6 +364,16 @@ def _run(argv=None, exec=True): # we've signaled the primary instance, so we should close return + if not pm: + QMessageBox.critical( + None, + "Error", + """\ +Anki could not create its data folder. Please see the File Locations \ +section of the manual, and ensure that location is not read-only.""", + ) + return + # disable icons on mac; this must be done before window created if isMac: app.setAttribute(Qt.AA_DontShowIconsInMenus) diff --git a/aqt/profiles.py b/aqt/profiles.py index 4e2e956b9..1b3f7e619 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -97,22 +97,7 @@ class ProfileManager: ###################################################################### def ensureBaseExists(self): - try: - self._ensureExists(self.base) - except: - # can't translate, as lang not initialized, and qt may not be - print("unable to create base folder") - QMessageBox.critical( - None, - "Error", - """\ -Anki could not create the folder %s. Please ensure that location is not \ -read-only and you have permission to write to it. If you cannot fix this \ -issue, please see the documentation for information on running Anki from \ -a flash drive.""" - % self.base, - ) - raise + self._ensureExists(self.base) # Folder migration ######################################################################