-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
config.py
124 lines (92 loc) · 3.68 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
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
# Copyright: Ren Tatsumoto <tatsu at autistici.org>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import enum
from .ajt_common.addon_config import AddonConfigManager, ConfigSubViewBase
class ScrollKeysConfig(ConfigSubViewBase):
_view_key: str = "scroll"
@property
def up(self) -> str:
return self["up"]
@property
def down(self) -> str:
return self["down"]
@property
def left(self) -> str:
return self["left"]
@property
def right(self) -> str:
return self["right"]
class RemainingCountType(enum.Enum):
"""
How to display remaining cards on the bottom toolbar.
By default, new+learn+due are separate. Single number sums all queues. None prints nothing.
"""
default = enum.auto()
single = enum.auto()
none = enum.auto()
class FlexibleGradingConfig(AddonConfigManager):
def __init__(self, default: bool = False) -> None:
super().__init__(default)
self._scroll = ScrollKeysConfig(self)
@property
def remaining_count_type(self) -> RemainingCountType:
return RemainingCountType[self["remaining_count_type"]]
@remaining_count_type.setter
def remaining_count_type(self, value: RemainingCountType) -> None:
self["remaining_count_type"] = value.name
@property
def scroll(self) -> ScrollKeysConfig:
return self._scroll
@property
def scroll_amount(self) -> int:
return self["scroll_amount"]
@scroll_amount.setter
def scroll_amount(self, amount_px: int) -> None:
self["scroll_amount"] = int(amount_px)
def _get_sub(self, sub_key: str) -> dict[str, str]:
return {
key.lower(): self._config[sub_key].get(key.lower(), default_value)
for key, default_value in self._default_config[sub_key].items()
}
@staticmethod
def get_label(ease: int, default_ease: int = 3) -> str:
if ease == 1:
return "Again"
if ease == default_ease:
return "Good"
if ease == 2:
return "Hard"
if ease > default_ease:
return "Easy"
return "Unknown"
def get_ease_color(self, ease: int, default_ease: int) -> str:
return self._config["colors"][self.get_label(ease, default_ease).lower()]
def get_label_color(self, label: str) -> str:
return self._config["colors"][label.lower()]
@property
def colors(self) -> dict[str, str]:
"""Returns a dict mapping buttons' labels to their colors."""
return self._get_sub("colors")
@property
def buttons(self) -> dict[str, str]:
"""Returns a dict mapping buttons' labels to their key bindings."""
return self._get_sub("buttons")
def get_key(self, answer: str) -> str:
"""Returns shortcut key for answer button, e.g. 'again'=>'h'."""
return self._config["buttons"].get(answer.lower(), "").lower()
def set_key(self, answer: str, letter: str):
"""Sets shortcut key for answer button, e.g. 'again'=>'h'."""
self._config["buttons"][answer.lower()] = letter.lower()
def set_color(self, btn_label: str, color: str):
self._config["colors"][btn_label.lower()] = color
def get_zoom_state(self, state: str) -> float:
return self._config.setdefault("zoom_states", {}).get(state, 1)
def set_zoom_state(self, state: str, value: float) -> None:
self._config.setdefault("zoom_states", {})[state] = value
@property
def show_last_review(self) -> bool:
return bool(self["show_last_review"])
@property
def show_reps_done_today(self) -> bool:
return bool(self["show_reps_done_today"])
config = FlexibleGradingConfig()