forked from Arthur-Milchior/anki-enhance-main-window
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
38 lines (33 loc) · 1.05 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from aqt import mw
import sys
userOption = None
def getUserOption(key = None, default = None):
#print(f"getUserOption(key = {key}, default = {default})")
global userOption
if userOption is None:
userOption = mw.addonManager.getConfig(__name__)
#debug("userOption read from the file and is {userOption}")
if key is None:
#debug("return {userOption}")
return userOption
if key in userOption:
#debug("key in userOption. Returning {userOption[key]}")
return userOption[key]
else:
#debug("key not in userOption. Returning default.")
return default
def writeConfig():
aqt.mw.addonManager.writeConfig(__name__,userOption)
def update(_):
global userOption, fromName
userOption = None
fromName = None
mw.addonManager.setConfigUpdatedAction(__name__,update)
fromName = None
def getFromName(name):
global fromName
if fromName is None:
fromName = dict()
for dic in getUserOption("columns"):
fromName[dic["name"]]=dic
return fromName.get(name)