Skip to content

Commit

Permalink
refactor: Separate typing test GUI into separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-min committed Jan 27, 2024
1 parent d1c86f5 commit 9779bf9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
20 changes: 4 additions & 16 deletions __init__.py
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)
19 changes: 19 additions & 0 deletions ui/typing_test.py
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)

0 comments on commit 9779bf9

Please sign in to comment.