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/tools/genhooks.py for more info.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2020-01-15 00:11:20 +01:00
|
|
|
import sys
|
2020-01-13 05:38:05 +01:00
|
|
|
|
2020-01-15 00:11:20 +01:00
|
|
|
pylib = os.path.join(os.path.dirname(__file__), "..", "..", "pylib")
|
|
|
|
sys.path.append(pylib)
|
|
|
|
|
|
|
|
from tools.hookslib import Hook, update_file
|
2020-01-13 05:38:05 +01:00
|
|
|
|
|
|
|
# Hook list
|
|
|
|
######################################################################
|
|
|
|
|
|
|
|
hooks = [
|
2020-01-15 04:03:11 +01:00
|
|
|
# Reviewing
|
|
|
|
###################
|
2020-01-13 09:37:08 +01:00
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="reviewer_question_did_show",
|
2020-01-13 09:37:08 +01:00
|
|
|
args=["card: Card"],
|
|
|
|
legacy_hook="showQuestion",
|
|
|
|
legacy_no_args=True,
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="reviewer_answer_did_show",
|
2020-01-13 09:37:08 +01:00
|
|
|
args=["card: Card"],
|
|
|
|
legacy_hook="showAnswer",
|
|
|
|
legacy_no_args=True,
|
|
|
|
),
|
2020-01-14 23:53:57 +01:00
|
|
|
Hook(
|
2020-01-15 04:03:11 +01:00
|
|
|
name="reviewer_context_menu_will_show",
|
|
|
|
args=["reviewer: aqt.reviewer.Reviewer", "menu: QMenu"],
|
|
|
|
legacy_hook="Reviewer.contextMenuEvent",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="reviewer_will_end",
|
|
|
|
legacy_hook="reviewCleanup",
|
|
|
|
doc="Called before Anki transitions from the review screen to another screen.",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="card_text",
|
|
|
|
args=["text: str", "card: Card", "kind: str"],
|
|
|
|
return_type="str",
|
|
|
|
legacy_hook="prepareQA",
|
|
|
|
doc="Can modify card text before review/preview.",
|
2020-01-14 23:53:57 +01:00
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# Browser
|
|
|
|
###################
|
2020-01-14 23:53:57 +01:00
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="browser_menus_did_setup",
|
2020-01-14 23:53:57 +01:00
|
|
|
args=["browser: aqt.browser.Browser"],
|
|
|
|
legacy_hook="browser.setupMenus",
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="browser_context_menu_will_show",
|
2020-01-14 23:53:57 +01:00
|
|
|
args=["browser: aqt.browser.Browser", "menu: QMenu"],
|
|
|
|
legacy_hook="browser.onContextMenu",
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="browser_row_did_change",
|
2020-01-14 23:53:57 +01:00
|
|
|
args=["browser: aqt.browser.Browser"],
|
|
|
|
legacy_hook="browser.rowChanged",
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 03:16:54 +01:00
|
|
|
name="webview_context_menu_will_show",
|
2020-01-14 23:53:57 +01:00
|
|
|
args=["webview: aqt.webview.AnkiWebView", "menu: QMenu"],
|
|
|
|
legacy_hook="AnkiWebView.contextMenuEvent",
|
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# States
|
|
|
|
###################
|
2020-01-15 03:16:54 +01:00
|
|
|
Hook(
|
|
|
|
name="state_will_change",
|
|
|
|
args=["new_state: str", "old_state: str"],
|
|
|
|
legacy_hook="beforeStateChange",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="state_did_change",
|
|
|
|
args=["new_state: str", "old_state: str"],
|
|
|
|
legacy_hook="afterStateChange",
|
|
|
|
),
|
|
|
|
# different sig to original
|
|
|
|
Hook(
|
|
|
|
name="state_shortcuts_will_change",
|
2020-01-15 03:46:53 +01:00
|
|
|
args=["state: str", "shortcuts: List[Tuple[str, Callable]]"],
|
2020-01-15 03:16:54 +01:00
|
|
|
),
|
2020-01-15 03:46:53 +01:00
|
|
|
Hook(
|
|
|
|
name="state_did_revert",
|
|
|
|
args=["action: str"],
|
|
|
|
legacy_hook="revertedState",
|
|
|
|
doc="Called when user used the undo option to restore to an earlier database state.",
|
|
|
|
),
|
2020-01-15 03:16:54 +01:00
|
|
|
Hook(
|
|
|
|
name="state_did_reset",
|
|
|
|
legacy_hook="reset",
|
|
|
|
doc="Called when the interface needs to be redisplayed after non-trivial changes have been made.",
|
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# Main
|
|
|
|
###################
|
|
|
|
Hook(name="profile_did_open", legacy_hook="profileLoaded"),
|
|
|
|
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
|
|
|
|
Hook(
|
|
|
|
name="collection_did_load",
|
|
|
|
args=["col: anki.storage._Collection"],
|
|
|
|
legacy_hook="colLoading",
|
|
|
|
),
|
2020-01-15 03:16:54 +01:00
|
|
|
Hook(
|
|
|
|
name="undo_state_did_change", args=["can_undo: bool"], legacy_hook="undoState"
|
|
|
|
),
|
|
|
|
Hook(name="review_did_undo", args=["card_id: int"], legacy_hook="revertedCard"),
|
|
|
|
Hook(
|
2020-01-15 03:46:53 +01:00
|
|
|
name="style_did_setup",
|
2020-01-15 03:16:54 +01:00
|
|
|
args=["style: str"],
|
|
|
|
return_type="str",
|
|
|
|
legacy_hook="setupStyle",
|
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# Adding cards
|
|
|
|
###################
|
2020-01-15 03:16:54 +01:00
|
|
|
Hook(
|
|
|
|
name="add_cards_history_menu_will_show",
|
|
|
|
args=["addcards: aqt.addcards.AddCards", "menu: QMenu"],
|
|
|
|
legacy_hook="AddCards.onHistory",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="add_cards_note_did_add",
|
|
|
|
args=["note: anki.notes.Note"],
|
|
|
|
legacy_hook="AddCards.noteAdded",
|
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# Editing
|
|
|
|
###################
|
2020-01-15 03:16:54 +01:00
|
|
|
Hook(
|
|
|
|
name="editor_buttons_did_setup",
|
|
|
|
args=["buttons: List", "editor: aqt.editor.Editor"],
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_shortcuts_did_setup",
|
|
|
|
args=["shortcuts: List[Tuple]", "editor: aqt.editor.Editor"],
|
|
|
|
legacy_hook="setupEditorShortcuts",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_context_menu_will_show",
|
|
|
|
args=["editor_webview: aqt.editor.EditorWebView", "menu: QMenu"],
|
|
|
|
legacy_hook="EditorWebView.contextMenuEvent",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_typing_timer_did_fire",
|
|
|
|
args=["note: anki.notes.Note"],
|
|
|
|
legacy_hook="editTimer",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_field_did_gain_focus",
|
|
|
|
args=["note: anki.notes.Note", "current_field_idx: int"],
|
|
|
|
legacy_hook="editFocusGained",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_field_did_lose_focus",
|
|
|
|
args=["changed: bool", "note: anki.notes.Note", "current_field_idx: int"],
|
|
|
|
return_type="bool",
|
|
|
|
legacy_hook="editFocusLost",
|
|
|
|
),
|
|
|
|
Hook(
|
2020-01-15 03:46:53 +01:00
|
|
|
name="editor_note_did_load",
|
2020-01-15 03:16:54 +01:00
|
|
|
args=["editor: aqt.editor.Editor"],
|
|
|
|
legacy_hook="loadNote",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_tags_did_update",
|
|
|
|
args=["note: anki.notes.Note"],
|
|
|
|
legacy_hook="tagsUpdated",
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="editor_font_for_field",
|
|
|
|
args=["font: str"],
|
|
|
|
return_type="str",
|
|
|
|
legacy_hook="mungeEditingFontName",
|
|
|
|
),
|
2020-01-15 04:03:11 +01:00
|
|
|
# Other
|
|
|
|
###################
|
|
|
|
Hook(name="mpv_did_idle"),
|
|
|
|
Hook(name="mpv_will_play", args=["file: str"], legacy_hook="mpvWillPlay"),
|
|
|
|
Hook(
|
|
|
|
name="current_note_type_did_change",
|
|
|
|
args=["notetype: Dict[str, Any]"],
|
|
|
|
legacy_hook="currentModelChanged",
|
|
|
|
legacy_no_args=True,
|
|
|
|
),
|
|
|
|
Hook(
|
|
|
|
name="deck_browser_options_menu_will_show",
|
|
|
|
args=["menu: QMenu", "deck_id: int"],
|
|
|
|
legacy_hook="showDeckOptions",
|
|
|
|
),
|
2020-01-13 05:38:05 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
path = os.path.join(os.path.dirname(__file__), "..", "aqt", "gui_hooks.py")
|
|
|
|
update_file(path, hooks)
|