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
|
|
|
|
|
2020-01-13 09:37:08 +01:00
|
|
|
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@@
|
|
|
|
|
2020-01-13 09:37:08 +01:00
|
|
|
|
2020-01-13 23:54:07 +01:00
|
|
|
class MpvIdleHook:
|
|
|
|
_hooks: List[Callable[[], None]] = []
|
2020-01-13 09:37:08 +01:00
|
|
|
|
2020-01-13 23:54:07 +01:00
|
|
|
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@@
|