def _defaultBase(self): if isWin: from aqt.winpaths import get_appdata return os.path.join(get_appdata(), "Anki2") elif isMac: return os.path.expanduser("~/Library/Application Support/Anki2") else: dataDir = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share")) if not os.path.exists(dataDir): os.makedirs(dataDir) return os.path.join(dataDir, "Anki2")
def _defaultBase(self): if isWin: from aqt.winpaths import get_appdata return os.path.join(get_appdata(), "Anki2") elif isMac: return os.path.expanduser("~/Library/Application Support/Anki2") else: dataDir = os.environ.get( "XDG_DATA_HOME", os.path.expanduser("~/.local/share")) if not os.path.exists(dataDir): os.makedirs(dataDir) return os.path.join(dataDir, "Anki2")
def _defaultBase(self): """The folder containing every file related to anki's configuration. """ if isWin: from aqt.winpaths import get_appdata return os.path.join(get_appdata(), "Anki2") elif isMac: return os.path.expanduser("~/Library/Application Support/Anki2") else: dataDir = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share")) if not os.path.exists(dataDir): os.makedirs(dataDir) return os.path.join(dataDir, "Anki2")
from aqt.winpaths import get_appdata import os ret = os.path.join(get_appdata(), "Anki2", "addons21", '1807206748', 'service', 'dict') #获取Anki的Fast Words Query插件dict位置 print(ret) ret = os.path.join( get_appdata(), "Anki2", "addons21", '1807206748', 'service', 'static', ) #获取Anki的Fast Words Query插件static css位置 print(ret)
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) if not opts.base: sys.exit("ERROR: the --base CLI argument is mandatory") if isMac: default_base_folder_abs_path = os.path.expanduser( "~/Library/Application Support/Anki2") elif isLin: data_dir = os.environ.get("XDG_DATA_HOME", os.path.expanduser("~/.local/share")) if not os.path.exists(data_dir): os.makedirs(data_dir) default_base_folder_abs_path = os.path.join(data_dir, "Anki2") else: from aqt.winpaths import get_appdata default_base_folder_abs_path = os.path.join(get_appdata(), "Anki2") if os.path.abspath(opts.base) == default_base_folder_abs_path: sys.exit( "ERROR: cannot use this location for the base folder as it might conflict with a regular installation of Anki" ) # 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) # Opt into software rendering. Useful for buggy systems. if os.environ.get("ANKI_SOFTWAREOPENGL"): QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL) # create the app QCoreApplication.setApplicationName("Anki") QGuiApplication.setDesktopFileName("anki.desktop") app = AnkiApp(argv) 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