Skip to content

Commit 1e7f8a0

Browse files
committed
Cleanups on passfail2.py
1 parent b6caefe commit 1e7f8a0

File tree

2 files changed

+28
-43
lines changed

2 files changed

+28
-43
lines changed

logger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import logging
2+
log = logging.getLogger("Pass/Fail 2 Addon")

passfail2.py

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
# Regards to Dmitry Mikheev for writing the original add-on this was
1313
# derived from, and the Anki team.
1414

15+
from .logger import log
16+
1517
try:
1618
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)
1921

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
2423

2524
try:
2625
from anki.utils import point_version
@@ -32,11 +31,8 @@
3231
def point_version():
3332
return int(version.split(".")[-1])
3433

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
4036

4137
from anki.hooks import wrap
4238

@@ -54,7 +50,7 @@ def point_version():
5450
else:
5551
from anki.lang import _
5652

57-
# Start of Setup for Button Colors
53+
# Setup config
5854
toggle_names_textcolors = False
5955
toggle_bgcolor = False
6056
again_button_name = "Fail"
@@ -70,33 +66,25 @@ def point_version():
7066
good_button_name = config['good_button_name']
7167
again_button_textcolor = config['again_button_textcolor']
7268
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)
7771

7872
# Hooks
7973
def pf2_hook_replace_buttons(
8074
buttons_tuple, # type: tuple[tuple[int, str], ...]
8175
reviewer, # type: Reviewer
8276
card # type: Card
8377
): # 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+
)
10088

10189
def pf2_hook_remap_answer_ease(
10290
ease_tuple, # type: tuple[bool, Literal[1, 2, 3, 4]]
@@ -150,7 +138,8 @@ def pf2_fix_pass_title(
150138
# Init
151139
def init():
152140
version = point_version()
153-
configuration_menu.configuration_menu_init() # Initialize the Anki Plugin Config Qt Menu
141+
142+
configuration_menu.configuration_menu_init()
154143

155144
# Answer button list
156145
if version >= 31:
@@ -167,15 +156,9 @@ def init():
167156
# Show "Shortcut key: 2" rather than "Shortcut key: 3" for "Pass" button
168157
Reviewer._showEaseButtons = wrap(Reviewer._showEaseButtons, pf2_fix_pass_title, 'after')
169158

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:
173162
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:
178164
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

Comments
 (0)