-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.py
85 lines (60 loc) · 2.17 KB
/
settings.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
80
81
82
83
84
85
from aqt import mw, os
this_addon_name = os.path.dirname(__file__)
class _settings:
def _ensure_dir(self, name):
if not os.path.isdir(name):
os.makedirs(name)
return name
@property
def profile_folder(self):
return self._ensure_dir(mw.pm.profileFolder())
@property
def addons_folder(self):
return self._ensure_dir(mw.addonManager.addonsFolder())
@property
def media_folder(self):
return self._ensure_dir(os.path.join(self.profile_folder, "collection.media"))
@property
def this_addon_folder(self):
return self._ensure_dir(mw.addonManager.addonsFolder(this_addon_name))
@property
def user_files_folder(self):
return self._ensure_dir(os.path.join(self.this_addon_folder, "user_files"))
@property
def imported_db_path(self):
return os.path.join(self.profile_folder, "youdao2anki_imported_words.db")
@property
def deck_template_file(self):
return os.path.join(self.this_addon_folder, "data\Template.apkg")
@property
def addon_config(self):
return mw.addonManager.getConfig(__name__)
@property
def config_file(self):
return os.path.join(self.this_addon_folder, "config.json")
settings = _settings()
class _addon_config:
def __init__(self):
self.config = settings.addon_config
def SaveConfig(self):
mw.addonManager.writeConfig(__name__, self.config)
@property
def QueryWordOnce(self):
value = self.config['QueryWordOnce']
return True if value else False
@QueryWordOnce.setter
def QueryWordOnce(self, value):
self.config['QueryWordOnce'] = True if value else False
@property
def WordVoiceType(self):
return str(self.config['WordVoiceType']).strip().lower()
@WordVoiceType.setter
def WordVoiceType(self, value):
self.config['WordVoiceType'] = str(value).strip().lower()
@property
def DefaultSourceTag(self):
return str(self.config["DefaultSourceTag"]).strip()
@DefaultSourceTag.setter
def DefaultSourceTag(self, value):
self.config["DefaultSourceTag"] = str(value).strip()
addon_config = _addon_config()