anki/qt/aqt/gui_hooks.py

120 lines
3.0 KiB
Python
Raw Normal View History

2020-01-13 05:38:05 +01:00
# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
"""
See pylib/anki/hooks.py
"""
from __future__ import annotations
from typing import Any, Callable, Dict, List # pylint: disable=unused-import
from anki.cards import Card
2020-01-13 05:38:05 +01:00
from anki.hooks import runFilter, runHook # pylint: disable=unused-import
# New hook/filter handling
##############################################################################
# The code in this section is automatically generated - any edits you make
# will be lost. To add new hooks, see ../tools/genhooks.py
#
# @@AUTOGEN@@
class MpvIdleHook:
_hooks: List[Callable[[], None]] = []
def append(self, cb: Callable[[], None]) -> None:
"""()"""
self._hooks.append(cb)
def remove(self, cb: Callable[[], None]) -> None:
self._hooks.remove(cb)
def __call__(self) -> None:
for hook in self._hooks:
try:
hook()
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
mpv_idle_hook = MpvIdleHook()
class MpvWillPlayHook:
_hooks: List[Callable[[str], None]] = []
def append(self, cb: Callable[[str], None]) -> None:
"""(file: str)"""
self._hooks.append(cb)
def remove(self, cb: Callable[[str], None]) -> None:
self._hooks.remove(cb)
def __call__(self, file: str) -> None:
for hook in self._hooks:
try:
hook(file)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
# legacy support
runHook("mpvWillPlay", file)
mpv_will_play_hook = MpvWillPlayHook()
class ReviewerShowingAnswerHook:
_hooks: List[Callable[[Card], None]] = []
def append(self, cb: Callable[[Card], None]) -> None:
"""(card: Card)"""
self._hooks.append(cb)
def remove(self, cb: Callable[[Card], None]) -> None:
self._hooks.remove(cb)
def __call__(self, card: Card) -> None:
for hook in self._hooks:
try:
hook(card)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
# legacy support
runHook("showAnswer")
reviewer_showing_answer_hook = ReviewerShowingAnswerHook()
class ReviewerShowingQuestionHook:
_hooks: List[Callable[[Card], None]] = []
def append(self, cb: Callable[[Card], None]) -> None:
"""(card: Card)"""
self._hooks.append(cb)
def remove(self, cb: Callable[[Card], None]) -> None:
self._hooks.remove(cb)
def __call__(self, card: Card) -> None:
for hook in self._hooks:
try:
hook(card)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
# legacy support
runHook("showQuestion")
reviewer_showing_question_hook = ReviewerShowingQuestionHook()
2020-01-13 05:38:05 +01:00
# @@AUTOGEN@@