-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
options.py
192 lines (159 loc) · 4.78 KB
/
options.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# -*- coding: utf-8 -*-
"""
This file is part of the Review Heatmap add-on for Anki
Options dialog and associated code
Copyright: (c) 2016-2018 Glutanimate <https://glutanimate.com/>
License: GNU AGPLv3 <https://www.gnu.org/licenses/agpl.html>
"""
from __future__ import unicode_literals
import time
from aqt.qt import *
from aqt import mw
from aqt.studydeck import StudyDeck
from .libaddon.gui.options import OptionsDialog
from .config import (config, heatmap_colors, heatmap_modes, activity_stats)
from .consts import ANKI21
if ANKI21:
from .forms5 import options as option_qtform # noqa: F401
else:
from .forms4 import options as option_qtform # noqa: F401
# Widget <-> config mappings
# order is important (e.g. set items before current value)
option_widgets = (
("form.selHmColor", (
("items", {
"getter": "getHeatmapColors"
}),
("value", {
"confPath": ("synced", "colors"),
}),
)),
("form.selHmCalMode", (
("items", {
"getter": "getHeatmapModes"
}),
("value", {
"confPath": ("synced", "mode")
}),
)),
("form.selActivity", (
("items", {
"getter": "getActivityStats"
}),
("value", {
"confPath": ("synced", "stat")
}),
)),
("form.cbHmMain", (
("value", {
"confPath": ("profile", "display", 0)
}),
)),
("form.cbHmDeck", (
("value", {
"confPath": ("profile", "display", 1)
}),
)),
("form.cbHmStats", (
("value", {
"confPath": ("profile", "display", 2)
}),
)),
("form.cbStreakAll", (
("value", {
"confPath": ("profile", "statsvis")
}),
)),
("form.spinLimHist", (
("value", {
"confPath": ("synced", "limhist")
}),
)),
("form.spinLimFcst", (
("value", {
"confPath": ("synced", "limfcst")
}),
)),
("form.dateLimData", (
("value", {
"confPath": ("synced", "limdate")
}),
("min", {
"getter": "getColCreationTime"
}),
("max", {
"getter": "getCurrentTime"
}),
)),
("form.cbLimDel", (
("value", {
"confPath": ("synced", "limcdel")
}),
)),
("form.keyGrabToggle", (
("value", {
"confPath": ("profile", "hotkeys", "toggle")
}),
)),
("form.listDecks", (
("value", {
"confPath": ("synced", "limdecks"),
"getter": "getIgnoredDecks",
}),
)),
)
class RevHmOptions(OptionsDialog):
"""
Add-on-specific options dialog implementation
"""
def __init__(self, config, mw):
self.mw = mw
super(RevHmOptions, self).__init__(option_qtform, option_widgets,
config, parent=mw)
# Events:
def setupEvents(self):
super(RevHmOptions, self).setupEvents()
self.form.btnDeckAdd.clicked.connect(self.onAddIgnoredDeck)
self.form.btnDeckDel.clicked.connect(self.onDeleteIgnoredDeck)
# Actions:
def onAddIgnoredDeck(self):
list_widget = self.form.listDecks
ret = StudyDeck(self.mw, accept=_("Choose"),
title=_("Choose Deck"), help="",
parent=self, geomKey="selectDeck")
deck_name = ret.name
deck_id = self.mw.col.decks.id(deck_name)
item_tuple = (deck_name, deck_id)
if not self.interface.setCurrent(list_widget, item_tuple):
self.interface.setValuesAndCurrent(
list_widget, [item_tuple], item_tuple)
def onDeleteIgnoredDeck(self):
list_widget = self.form.listDecks
selected = self.interface.getSelected(list_widget)
self.interface.removeValues(list_widget, selected)
# Config Getters/Setters:
def getColCreationTime(self):
return self.mw.col.crt
def getCurrentTime(self):
return int(round(time.time()))
def getComboItems(self, dct):
return list((val["label"], key) for key, val in dct.items())
def getHeatmapColors(self):
return self.getComboItems(heatmap_colors)
def getHeatmapModes(self):
return self.getComboItems(heatmap_modes)
def getActivityStats(self):
return self.getComboItems(activity_stats)
def getIgnoredDecks(self, dids):
item_tuples = []
for did in dids:
name = self.mw.col.decks.nameOrNone(did)
if not name:
continue
item_tuples.append((name, did))
return item_tuples
def invokeOptionsDialog():
"""Call settings dialog"""
dialog = RevHmOptions(config, mw)
return dialog.exec_()
config.setConfigAction(invokeOptionsDialog)