-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Separate typing test GUI into separate module
- Loading branch information
Showing
2 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,14 @@ | ||
from aqt import mw, gui_hooks | ||
|
||
from .config import Config | ||
from .ui.typing_dialog import TypingDialog | ||
from .config import Config, run_on_configuration_change | ||
from .ui.tools_menu import DropdownMenu | ||
|
||
from .ui.typing_test import TypingTest | ||
|
||
# load config object | ||
config = Config() | ||
config.load() | ||
|
||
def typingTest(card) -> None: | ||
if not config.get('enable_typing_test'): | ||
return | ||
keyList = config.get('trigger_fields') | ||
ans = "N/A" | ||
for key in keyList: | ||
if key in card.note(): | ||
ans = card.note()[key] | ||
break | ||
mw.typeWidget = TypingDialog(mw, "Taipingu", ans) | ||
|
||
# add Taipingu menu item to Tools menu | ||
tools_menu = DropdownMenu("Enable typing test", config) | ||
|
||
gui_hooks.reviewer_did_show_question.append(typingTest) | ||
# add typing test when showing new cards | ||
typing_test = TypingTest(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from aqt import mw, gui_hooks | ||
|
||
from .typing_dialog import TypingDialog | ||
|
||
class TypingTest: | ||
def __init__(self, config): | ||
self.config = config | ||
gui_hooks.reviewer_did_show_question.append(self.typingTest) | ||
|
||
def typingTest(self, card) -> None: | ||
if not self.config.get('enable_typing_test'): | ||
return | ||
keyList = self.config.get('trigger_fields') | ||
ans = "N/A\n Card text not detected. Please check your config for Taipingu." | ||
for key in keyList: | ||
if key in card.note(): | ||
ans = card.note()[key] | ||
break | ||
mw.typeWidget = TypingDialog(mw, "Taipingu", ans) |