2020-01-13 04:57:51 +01:00
|
|
|
# Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
|
|
|
|
"""
|
|
|
|
Generate code for hook handling, and insert it into anki/hooks.py.
|
|
|
|
|
|
|
|
To add a new hook:
|
|
|
|
- update the hooks list below
|
|
|
|
- run 'make develop'
|
|
|
|
- send a pull request that includes the changes to this file and hooks.py
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2020-01-15 00:11:20 +01:00
|
|
|
from hookslib import Hook, update_file
|
2020-01-13 04:57:51 +01:00
|
|
|
|
2020-01-13 08:59:52 +01:00
|
|
|
# Hook/filter list
|
2020-01-13 04:57:51 +01:00
|
|
|
######################################################################
|
|
|
|
|
|
|
|
hooks = [
|
2020-01-15 07:43:22 +01:00
|
|
|
Hook(name="card_did_leech", args=["card: Card"], legacy_hook="leech"),
|
|
|
|
Hook(name="card_odue_was_invalid"),
|
|
|
|
Hook(name="schema_will_change", args=["proceed: bool"], return_type="bool"),
|
2020-01-13 08:59:52 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="notes_will_be_deleted",
|
2020-01-13 08:59:52 +01:00
|
|
|
args=["col: anki.storage._Collection", "ids: List[int]"],
|
|
|
|
legacy_hook="remNotes",
|
|
|
|
),
|
2020-01-13 09:37:08 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="deck_added",
|
2020-01-13 09:37:08 +01:00
|
|
|
args=["deck: Dict[str, Any]"],
|
|
|
|
legacy_hook="newDeck",
|
|
|
|
legacy_no_args=True,
|
|
|
|
),
|
2020-01-15 07:43:22 +01:00
|
|
|
Hook(name="media_files_did_export", args=["count: int"]),
|
2020-01-13 08:59:52 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="exporters_list_created",
|
2020-01-13 08:59:52 +01:00
|
|
|
args=["exporters: List[Tuple[str, Any]]"],
|
|
|
|
legacy_hook="exportersList",
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="search_terms_prepared",
|
2020-01-13 08:59:52 +01:00
|
|
|
args=["searches: Dict[str, Callable]"],
|
|
|
|
legacy_hook="search",
|
|
|
|
),
|
2020-01-13 09:37:08 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="note_type_added",
|
2020-01-13 09:37:08 +01:00
|
|
|
args=["notetype: Dict[str, Any]"],
|
|
|
|
legacy_hook="newModel",
|
|
|
|
legacy_no_args=True,
|
|
|
|
),
|
2020-01-15 07:43:22 +01:00
|
|
|
Hook(name="sync_stage_did_change", args=["stage: str"], legacy_hook="sync"),
|
|
|
|
Hook(name="sync_progress_did_change", args=["msg: str"], legacy_hook="syncMsg"),
|
2020-01-13 09:37:08 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="tag_added", args=["tag: str"], legacy_hook="newTag", legacy_no_args=True,
|
2020-01-13 09:37:08 +01:00
|
|
|
),
|
2020-01-13 08:59:52 +01:00
|
|
|
Hook(
|
2020-01-15 08:45:35 +01:00
|
|
|
name="field_filter",
|
2020-01-13 08:59:52 +01:00
|
|
|
args=[
|
|
|
|
"field_text: str",
|
|
|
|
"field_name: str",
|
|
|
|
"filter_name: str",
|
2020-01-17 00:30:42 +01:00
|
|
|
"ctx: TemplateRenderContext",
|
2020-01-13 08:59:52 +01:00
|
|
|
],
|
|
|
|
return_type="str",
|
2020-01-17 00:30:42 +01:00
|
|
|
doc="""Allows you to define custom {{filters:..}}
|
|
|
|
|
|
|
|
Your add-on can check filter_name to decide whether it should modify
|
|
|
|
field_text or not before returning it.""",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="card_did_render",
|
|
|
|
args=["text: Tuple[str, str]", "ctx: TemplateRenderContext",],
|
|
|
|
return_type="Tuple[str, str]",
|
|
|
|
doc="Can modify the resulting text after rendering completes.",
|
2020-01-13 08:59:52 +01:00
|
|
|
),
|
2020-01-13 04:57:51 +01:00
|
|
|
]
|
|
|
|
|
2020-01-13 05:38:05 +01:00
|
|
|
if __name__ == "__main__":
|
|
|
|
path = os.path.join(os.path.dirname(__file__), "..", "anki", "hooks.py")
|
|
|
|
update_file(path, hooks)
|