fix some lints

This commit is contained in:
Damien Elmes 2020-08-29 22:00:28 +10:00
parent ac6397ae9e
commit e80b3eeeef
4 changed files with 13 additions and 10 deletions

View File

@ -2866,20 +2866,20 @@ def mytest(web: AnkiWebView):
gui_hooks.webview_did_inject_style_into_page.append(mytest) gui_hooks.webview_did_inject_style_into_page.append(mytest)
''' '''
_hooks: List[Callable[[AnkiWebView], None]] = [] _hooks: List[Callable[["aqt.webview.AnkiWebView"], None]] = []
def append(self, cb: Callable[[AnkiWebView], None]) -> None: def append(self, cb: Callable[["aqt.webview.AnkiWebView"], None]) -> None:
"""(webview: AnkiWebView)""" """(webview: aqt.webview.AnkiWebView)"""
self._hooks.append(cb) self._hooks.append(cb)
def remove(self, cb: Callable[[AnkiWebView], None]) -> None: def remove(self, cb: Callable[["aqt.webview.AnkiWebView"], None]) -> None:
if cb in self._hooks: if cb in self._hooks:
self._hooks.remove(cb) self._hooks.remove(cb)
def count(self) -> int: def count(self) -> int:
return len(self._hooks) return len(self._hooks)
def __call__(self, webview: AnkiWebView) -> None: def __call__(self, webview: aqt.webview.AnkiWebView) -> None:
for hook in self._hooks: for hook in self._hooks:
try: try:
hook(webview) hook(webview)

View File

@ -10,9 +10,7 @@ from typing import Optional
import aqt import aqt
from anki.lang import _ from anki.lang import _
from aqt import gui_hooks from aqt import gui_hooks
from aqt.qt import QUrl
from aqt.sound import av_player from aqt.sound import av_player
from aqt.theme import theme_manager
from aqt.toolbar import BottomBar from aqt.toolbar import BottomBar
from aqt.utils import askUserDialog, openLink, shortcut, tooltip from aqt.utils import askUserDialog, openLink, shortcut, tooltip

View File

@ -598,15 +598,19 @@ body {{ zoom: {zoom}; background: {background}; direction: {lang_dir}; {font} }}
def inject_dynamic_style_and_show(self): def inject_dynamic_style_and_show(self):
"Add dynamic styling, and reveal." "Add dynamic styling, and reveal."
css = self.standard_css() css = self.standard_css()
def after_style(arg): def after_style(arg):
gui_hooks.webview_did_inject_style_into_page(self) gui_hooks.webview_did_inject_style_into_page(self)
self.show() self.show()
self.evalWithCallback( self.evalWithCallback(
f""" f"""
const style = document.createElement('style'); const style = document.createElement('style');
style.innerHTML = `{css}`; style.innerHTML = `{css}`;
document.head.appendChild(style); document.head.appendChild(style);
""", after_style) """,
after_style,
)
def load_ts_page(self, name: str) -> None: def load_ts_page(self, name: str) -> None:
from aqt import mw from aqt import mw

View File

@ -454,7 +454,7 @@ hooks = [
), ),
Hook( Hook(
name="webview_did_inject_style_into_page", name="webview_did_inject_style_into_page",
args=["webview: AnkiWebView"], args=["webview: aqt.webview.AnkiWebView"],
doc='''Called after standard styling is injected into an external doc='''Called after standard styling is injected into an external
html file, such as when loading the new graphs. You can use this hook to html file, such as when loading the new graphs. You can use this hook to
mutate the DOM before the page is revealed. mutate the DOM before the page is revealed.
@ -474,7 +474,8 @@ def mytest(web: AnkiWebView):
) )
gui_hooks.webview_did_inject_style_into_page.append(mytest) gui_hooks.webview_did_inject_style_into_page.append(mytest)
'''), ''',
),
# Main # Main
################### ###################
Hook( Hook(