12
12
# Regards to Dmitry Mikheev for writing the original add-on this was
13
13
# derived from, and the Anki team.
14
14
15
+ from .logger import log
16
+
15
17
try :
16
18
from typing import Literal , Callable
17
- except ImportError as emp :
18
- print ( emp )
19
+ except ImportError as err :
20
+ log . debug ( "Typing import failure: %s" , err )
19
21
20
- try :
21
- from aqt import mw
22
- except Exception as except1 :
23
- print ("Error Here Pass Fail: " + str (except1 ))
22
+ from aqt import mw
24
23
25
24
try :
26
25
from anki .utils import point_version
32
31
def point_version ():
33
32
return int (version .split ("." )[- 1 ])
34
33
35
- try :
36
- from . import button_color
37
- from . import configuration_menu
38
- except Exception as e3 :
39
- print ("Issue with Pass / Fail: 4-" + str (e3 ))
34
+ from . import button_color
35
+ from . import configuration_menu
40
36
41
37
from anki .hooks import wrap
42
38
@@ -54,7 +50,7 @@ def point_version():
54
50
else :
55
51
from anki .lang import _
56
52
57
- # Start of Setup for Button Colors
53
+ # Setup config
58
54
toggle_names_textcolors = False
59
55
toggle_bgcolor = False
60
56
again_button_name = "Fail"
@@ -70,33 +66,25 @@ def point_version():
70
66
good_button_name = config ['good_button_name' ]
71
67
again_button_textcolor = config ['again_button_textcolor' ]
72
68
good_button_textcolor = config ['good_button_textcolor' ]
73
-
74
- except Exception as e :
75
- print ("Pass / Fail Minor Error: " + str (e ))
76
- # End of Setup for Button Colors
69
+ except Exception as err :
70
+ log .warn ("Failed to import configuration, using defaults: %s" , err )
77
71
78
72
# Hooks
79
73
def pf2_hook_replace_buttons (
80
74
buttons_tuple , # type: tuple[tuple[int, str], ...]
81
75
reviewer , # type: Reviewer
82
76
card # type: Card
83
77
): # type: (...) -> tuple[tuple[int,str], ...]
84
-
85
- # Use the Updated Version Custom TextColors and Button Names
86
- try :
87
- if toggle_names_textcolors :
88
- return (
89
- (1 , f"<font color='{ again_button_textcolor } '>{ again_button_name } </font>" ),
90
- (reviewer ._defaultEase (), f"<font color='{ good_button_textcolor } '>{ good_button_name } </font>" )
91
- )
92
- except Exception as e1 :
93
- print ("Issue with Pass / Fail TextColor: " + str (e1 ))
94
- # end of Updated Version Custom TextColors and Button Names Addition, or use legacy:
95
-
96
- return (
97
- (1 , "Fail" ),
98
- (reviewer ._defaultEase (), "Pass" )
99
- )
78
+ if toggle_names_textcolors :
79
+ return (
80
+ (1 , f"<font color='{ again_button_textcolor } '>{ again_button_name } </font>" ),
81
+ (reviewer ._defaultEase (), f"<font color='{ good_button_textcolor } '>{ good_button_name } </font>" )
82
+ )
83
+ else :
84
+ return (
85
+ (1 , "Fail" ),
86
+ (reviewer ._defaultEase (), "Pass" )
87
+ )
100
88
101
89
def pf2_hook_remap_answer_ease (
102
90
ease_tuple , # type: tuple[bool, Literal[1, 2, 3, 4]]
@@ -150,7 +138,8 @@ def pf2_fix_pass_title(
150
138
# Init
151
139
def init ():
152
140
version = point_version ()
153
- configuration_menu .configuration_menu_init () # Initialize the Anki Plugin Config Qt Menu
141
+
142
+ configuration_menu .configuration_menu_init ()
154
143
155
144
# Answer button list
156
145
if version >= 31 :
@@ -167,15 +156,9 @@ def init():
167
156
# Show "Shortcut key: 2" rather than "Shortcut key: 3" for "Pass" button
168
157
Reviewer ._showEaseButtons = wrap (Reviewer ._showEaseButtons , pf2_fix_pass_title , 'after' )
169
158
170
- # Use the Edited AnswerButtons, to re-draw Buttons, with Background Color Enabled
171
- if toggle_bgcolor and point_version () >= 66 : # WHAT IS THE CUTOFF?
172
- try :
159
+ # Enable colored buttons
160
+ if toggle_bgcolor :
161
+ if point_version () >= 66 :
173
162
Reviewer ._answerButtons = wrap (Reviewer ._answerButtons , button_color .answer_buttons_with_bgcolor , 'after' )
174
- except Exception as e2 :
175
- print ("Issue with the BG Color part of Pass / Fail: " + str (e2 ))
176
- elif toggle_bgcolor and point_version () < 66 :
177
- try :
163
+ else :
178
164
Reviewer ._answerButtons = wrap (Reviewer ._answerButtons , button_color .answer_buttons_bgcolor_2_1_15 , 'after' )
179
- except Exception as e2 :
180
- print ("Issue with the old BG Color part of Pass / Fail: " + str (e2 ))
181
- # End of usage of Edited AnswerButtons
0 commit comments