def run(): try: _run() except Exception as e: traceback.print_exc() QMessageBox.critical( None, "Startup Error", "Please notify support of this error:\n\n" + traceback.format_exc())
def openProfile(self, profile): if profile: if profile not in self.profiles(): QMessageBox.critical(None, "Error", "Requested profile does not exist.") sys.exit(1) try: self.load(profile) except TypeError: raise Exception("Provided profile does not exist.")
def msgHandler(type, ctx, msg): if "Failed to create OpenGL context" in msg: QMessageBox.critical( None, "Error", "Error loading '%s' graphics driver. Please start Anki again to try next driver." % mode) pm.nextGlMode() return else: print("qt:", msg)
def ensureBaseExists(self): try: self._ensureExists(self.base) except: # can't translate, as lang not initialized 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
def _run(argv=None, exec=True): """Start AnkiQt application or reuse an existing instance if one exists. If the function is invoked with exec=False, the AnkiQt will not enter the main event loop - instead the application object will be returned. The 'exec' and 'argv' arguments will be useful for testing purposes. If no 'argv' is supplied then 'sys.argv' will be used. """ global mw if argv is None: argv = sys.argv # parse args opts, args = parseArgs(argv) # profile manager from aqt.profiles import ProfileManager pm = ProfileManager(opts.base) # gl workarounds setupGL(pm) # opt in to full hidpi support? if not os.environ.get("ANKI_NOHIGHDPI"): QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) # create the app app = AnkiApp(argv) QCoreApplication.setApplicationName("Anki") if app.secondInstance(): # we've signaled the primary instance, so we should close return # disable icons on mac; this must be done before window created if isMac: app.setAttribute(Qt.AA_DontShowIconsInMenus) # proxy configured? from urllib.request import proxy_bypass, getproxies if 'http' in getproxies(): # if it's not set up to bypass localhost, we'll # need to disable proxies in the webviews if not proxy_bypass("127.0.0.1"): print("webview proxy use disabled") proxy = QNetworkProxy() proxy.setType(QNetworkProxy.NoProxy) QNetworkProxy.setApplicationProxy(proxy) # we must have a usable temp dir try: tempfile.gettempdir() except: QMessageBox.critical( None, "Error", """\ No usable temporary folder found. Make sure C:\\temp exists or TEMP in your \ environment points to a valid, writable folder.""") return pm.setupMeta() if opts.profile: pm.openProfile(opts.profile) # i18n setupLang(pm, app, opts.lang) if isLin and pm.glMode() == "auto": from aqt.utils import gfxDriverIsBroken if gfxDriverIsBroken(): pm.nextGlMode() QMessageBox.critical( None, "Error", "Your video driver is incompatible. Please start Anki again, and Anki will switch to a slower, more compatible mode." ) sys.exit(1) # load the main window import aqt.main mw = aqt.main.AnkiQt(app, pm, opts, args) if exec: app.exec() else: return app