Skip to content

Commit

Permalink
refactor lookup window
Browse files Browse the repository at this point in the history
add return types
  • Loading branch information
tatsumoto-ren committed Apr 4, 2024
1 parent 2b64067 commit a9b70b7
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from aqt import gui_hooks, mw
from aqt.browser import Browser
from aqt.qt import *
from aqt.utils import showInfo, restoreGeom, saveGeom
from aqt.utils import restoreGeom, saveGeom, tooltip
from aqt.webview import AnkiWebView

from .pitch_accents.common import AccentDict
from .ajt_common.about_menu import menu_root_entry, tweak_window, garbage_collect_on_dialog_finish
from .config_view import config_view as cfg
from .helpers.tokens import clean_furigana
from .pitch_accents.common import AccentDict
from .reading import get_pronunciations, format_pronunciations, update_html

ACTION_NAME = "Pitch Accent lookup"
Expand All @@ -39,7 +39,7 @@ def __init__(self, parent: QWidget):
garbage_collect_on_dialog_finish(self)
tweak_window(self)

def _setup_ui(self):
def _setup_ui(self) -> None:
self.setWindowModality(Qt.WindowModality.ApplicationModal)
self.setWindowTitle(ACTION_NAME)
self.setMinimumSize(420, 240)
Expand All @@ -48,7 +48,7 @@ def _setup_ui(self):
layout.addLayout(self._make_bottom_buttons())
restoreGeom(self, ACTION_NAME)

def _make_bottom_buttons(self):
def _make_bottom_buttons(self) -> QLayout:
buttons = (
("Ok", self.accept),
("Copy HTML to Clipboard", self._copy_pronunciations),
Expand All @@ -61,7 +61,7 @@ def _make_bottom_buttons(self):
hbox.addStretch()
return hbox

def _copy_pronunciations(self):
def _copy_pronunciations(self) -> None:
return QApplication.clipboard().setText(
format_pronunciations(
self._pronunciations,
Expand All @@ -76,7 +76,7 @@ def lookup_pronunciations(self, search: str):
self._pronunciations = get_pronunciations(search)
return self

def _format_html_result(self):
def _format_html_result(self) -> str:
"""Create HTML body"""
assert self._pronunciations, "Populate pronunciations first."
html = io.StringIO()
Expand Down Expand Up @@ -109,12 +109,12 @@ def done(self, *args, **kwargs) -> None:
return super().done(*args, **kwargs)


def on_lookup_pronunciation(parent: QWidget, text: str):
def on_lookup_pronunciation(parent: QWidget, text: str) -> None:
"""Do a lookup on the selection"""
if text := clean_furigana(text).strip():
(ViewPitchAccentsDialog(parent).lookup_pronunciations(text).set_html_result().exec())
else:
showInfo(_("Empty selection."))
tooltip(_("Empty selection."), parent=parent)


def setup_mw_lookup_action(root_menu: QMenu) -> None:
Expand All @@ -141,7 +141,7 @@ def setup_browser_menu(browser: Browser) -> None:
browser.form.menuJump.addAction(action)


def init():
def init() -> None:
# Create the manual look-up menu entry
setup_mw_lookup_action(menu_root_entry())
# Hook to context menu events
Expand Down

0 comments on commit a9b70b7

Please sign in to comment.