-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
config.py
79 lines (53 loc) · 1.48 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
from aqt import mw
from aqt.utils import showWarning
# to be configured by Dev
############################
addonName = "Copy notes"
version = 2
def newVersion():
pass
"""A string stating what could occurs with a wrong configuration file"""
otherwise = ""
# end configuration
userOption = None
def _getUserOption():
global userOption
if userOption is None:
userOption = mw.addonManager.getConfig(__name__)
def getUserOption(key=None, default=None):
_getUserOption()
if key is None:
return userOption
if key in userOption:
return userOption[key]
else:
return default
lastVersion = getUserOption(version, 0)
if lastVersion < version:
newVersion()
pass
if lastVersion > version:
t = f"Please update add-on {addonName}. It seems that your configuration file is made for a more recent version of the add-on."
if otherwise:
t += "\n"+otherwise
showWarning(t)
def writeConfig():
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)
def setUserOption(key, value):
_getUserOption()
userOption[key] = value
writeConfig()