anki/qt/tools/genhooks_gui.py

873 lines
30 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/tools/genhooks.py for more info.
"""
import os
import sys
2020-01-13 05:38:05 +01:00
from hookslib import Hook, write_file
prefix = """\
# This file is automatically generated; edit tools/genhooks_gui.py instead.
# Please import from anki.hooks instead of this file.
2020-03-04 18:11:13 +01:00
from __future__ import annotations
from typing import Any, Callable, List, Sequence, Tuple, Optional, Union
import anki
import aqt
from anki.cards import Card
from anki.decks import DeckDict, DeckConfigDict
from anki.hooks import runFilter, runHook
from anki.models import NoteType
from aqt.qt import QDialog, QEvent, QMenu, QWidget
from aqt.tagedit import TagEdit
"""
2020-01-13 05:38:05 +01:00
# Hook list
######################################################################
hooks = [
2020-01-15 04:03:11 +01:00
# Reviewing
###################
Hook(
name="overview_did_refresh",
args=["overview: aqt.overview.Overview"],
doc="""Allow to update the overview window. E.g. add the deck name in the
title.""",
),
2020-02-17 16:49:21 +01:00
Hook(
name="overview_will_render_content",
args=[
"overview: aqt.overview.Overview",
"content: aqt.overview.OverviewContent",
],
doc="""Used to modify HTML content sections in the overview body
'content' contains the sections of HTML content the overview body
will be updated with.
When modifying the content of a particular section, please make sure your
changes only perform the minimum required edits to make your add-on work.
You should avoid overwriting or interfering with existing data as much
as possible, instead opting to append your own changes, e.g.:
def on_overview_will_render_content(overview, content):
content.table += "\n<div>my html</div>"
""",
),
Hook(
name="reviewer_did_show_question",
args=["card: Card"],
legacy_hook="showQuestion",
legacy_no_args=True,
),
Hook(
name="reviewer_did_show_answer",
args=["card: Card"],
legacy_hook="showAnswer",
legacy_no_args=True,
),
Hook(
name="reviewer_will_init_answer_buttons",
args=[
"buttons_tuple: Tuple[Tuple[int, str], ...]",
"reviewer: aqt.reviewer.Reviewer",
"card: Card",
],
return_type="Tuple[Tuple[int, str], ...]",
doc="""Used to modify list of answer buttons
2020-08-20 16:33:46 +02:00
buttons_tuple is a tuple of buttons, with each button represented by a
tuple containing an int for the button's ease and a string for the
button's label.
2020-08-20 16:33:46 +02:00
Return a tuple of the form ((int, str), ...), e.g.:
((1, "Label1"), (2, "Label2"), ...)
2020-08-20 16:33:46 +02:00
Note: import _ from anki.lang to support translation, using, e.g.,
((1, _("Label1")), ...)
""",
),
Hook(
name="reviewer_will_answer_card",
args=[
"ease_tuple: Tuple[bool, int]",
2020-01-24 15:48:05 +01:00
"reviewer: aqt.reviewer.Reviewer",
"card: Card",
],
return_type="Tuple[bool, int]",
doc="""Used to modify the ease at which a card is rated or to bypass
rating the card completely.
ease_tuple is a tuple consisting of a boolean expressing whether the reviewer
should continue with rating the card, and an integer expressing the ease at
which the card should be rated.
If your code just needs to be notified of the card rating event, you should use
the reviewer_did_answer_card hook instead.""",
),
Hook(
name="reviewer_did_answer_card",
args=["reviewer: aqt.reviewer.Reviewer", "card: Card", "ease: int"],
),
Hook(
name="reviewer_will_show_context_menu",
2020-01-15 04:03:11 +01:00
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="reviewer_will_play_question_sounds",
args=["card: Card", "tags: List[anki.sound.AVTag]"],
2020-07-31 02:06:13 +02:00
doc="""Called before showing the question/front side.
`tags` can be used to inspect and manipulate the sounds
that will be played (if any).
This won't be called when the user manually plays sounds
using `Replay Audio`.
2020-07-31 03:41:49 +02:00
Note that this hook is called even when the `Automatically play audio`
2020-07-31 02:06:13 +02:00
option is unchecked; This is so as to allow playing custom
sounds regardless of that option.""",
),
Hook(
name="reviewer_will_play_answer_sounds",
args=["card: Card", "tags: List[anki.sound.AVTag]"],
2020-07-31 02:06:13 +02:00
doc="""Called before showing the answer/back side.
`tags` can be used to inspect and manipulate the sounds
that will be played (if any).
This won't be called when the user manually plays sounds
using `Replay Audio`.
2020-07-31 03:41:49 +02:00
Note that this hook is called even when the `Automatically play audio`
2020-07-31 02:06:13 +02:00
option is unchecked; This is so as to allow playing custom
sounds regardless of that option.""",
),
2020-03-04 18:11:13 +01:00
# Debug
###################
Hook(
name="debug_console_will_show",
args=["debug_window: QDialog"],
doc="""Allows editing the debug window. E.g. setting a default code, or
previous code.""",
),
2020-03-04 18:20:02 +01:00
Hook(
name="debug_console_did_evaluate_python",
2021-02-02 14:30:53 +01:00
args=["output: str", "query: str", "debug_window: aqt.forms.debug.Ui_Dialog"],
2020-03-04 18:20:02 +01:00
return_type="str",
doc="""Allows processing the debug result. E.g. logging queries and
result, saving last query to display it later...""",
),
2020-02-28 13:34:54 +01:00
# Card layout
###################
Hook(
name="card_layout_will_show",
args=["clayout: aqt.clayout.CardLayout"],
doc="""Allow to change the display of the card layout. After most values are
set and before the window is actually shown.""",
),
# Multiple windows
###################
# reviewer, clayout and browser
2020-01-15 04:03:11 +01:00
Hook(
name="card_will_show",
2020-01-15 04:03:11 +01:00
args=["text: str", "card: Card", "kind: str"],
return_type="str",
legacy_hook="prepareQA",
doc="Can modify card text before review/preview.",
),
2020-02-29 17:01:38 +01:00
# Deck browser
###################
Hook(
name="deck_browser_did_render",
args=["deck_browser: aqt.deckbrowser.DeckBrowser"],
doc="""Allow to update the deck browser window. E.g. change its title.""",
),
Hook(
name="deck_browser_will_render_content",
args=[
"deck_browser: aqt.deckbrowser.DeckBrowser",
"content: aqt.deckbrowser.DeckBrowserContent",
],
doc="""Used to modify HTML content sections in the deck browser body
'content' contains the sections of HTML content the deck browser body
will be updated with.
When modifying the content of a particular section, please make sure your
changes only perform the minimum required edits to make your add-on work.
You should avoid overwriting or interfering with existing data as much
as possible, instead opting to append your own changes, e.g.:
def on_deck_browser_will_render_content(deck_browser, content):
content.stats += "\n<div>my html</div>"
""",
),
# Deck options
###################
Hook(
name="deck_conf_did_setup_ui_form",
args=["deck_conf: aqt.deckconf.DeckConf"],
doc="Allows modifying or adding widgets in the deck options UI form",
),
Hook(
name="deck_conf_will_show",
args=["deck_conf: aqt.deckconf.DeckConf"],
doc="Allows modifying the deck options dialog before it is shown",
),
Hook(
name="deck_conf_did_load_config",
args=[
"deck_conf: aqt.deckconf.DeckConf",
"deck: DeckDict",
"config: DeckConfigDict",
],
doc="Called once widget state has been set from deck config",
),
Hook(
name="deck_conf_will_save_config",
args=[
"deck_conf: aqt.deckconf.DeckConf",
"deck: DeckDict",
"config: DeckConfigDict",
],
doc="Called before widget state is saved to config",
),
Hook(
name="deck_conf_did_add_config",
2020-05-23 11:14:52 +02:00
args=[
"deck_conf: aqt.deckconf.DeckConf",
"deck: DeckDict",
"config: DeckConfigDict",
2020-05-23 11:14:52 +02:00
"new_name: str",
"new_conf_id: int",
],
doc="""Allows modification of a newly created config group
This hook is called after the config group was created, but
before initializing the widget state.
`deck_conf` will point to the old config group, `new_conf_id` will
point to the newly created config group.
Config groups are created as clones of the current one.
""",
),
Hook(
name="deck_conf_will_remove_config",
args=[
"deck_conf: aqt.deckconf.DeckConf",
"deck: DeckDict",
"config: DeckConfigDict",
],
doc="Called before current config group is removed",
),
Hook(
name="deck_conf_will_rename_config",
2020-05-23 11:14:52 +02:00
args=[
"deck_conf: aqt.deckconf.DeckConf",
"deck: DeckDict",
"config: DeckConfigDict",
2020-05-23 11:14:52 +02:00
"new_name: str",
],
doc="Called before config group is renamed",
),
2020-01-15 04:03:11 +01:00
# Browser
###################
Hook(
name="default_search",
args=["current_search: str", "c: Card"],
return_type="str",
doc="Change the default search when the card browser is opened with card `c`.",
),
2020-02-29 17:02:51 +01:00
Hook(name="browser_will_show", args=["browser: aqt.browser.Browser"]),
Hook(
name="browser_menus_did_init",
args=["browser: aqt.browser.Browser"],
legacy_hook="browser.setupMenus",
),
Hook(
name="browser_will_show_context_menu",
args=["browser: aqt.browser.Browser", "menu: QMenu"],
legacy_hook="browser.onContextMenu",
),
Hook(
name="browser_header_will_show_context_menu",
args=["browser: aqt.browser.Browser", "menu: QMenu"],
),
Hook(
name="browser_did_change_row",
args=["browser: aqt.browser.Browser"],
legacy_hook="browser.rowChanged",
),
Hook(
name="browser_will_build_tree",
args=[
"handled: bool",
"tree: aqt.sidebar.SidebarItem",
"stage: aqt.sidebar.SidebarStage",
"browser: aqt.browser.Browser",
],
return_type="bool",
doc="""Used to add or replace items in the browser sidebar tree
'tree' is the root SidebarItem that all other items are added to.
'stage' is an enum describing the different construction stages of
the sidebar tree at which you can interject your changes.
The different values can be inspected by looking at
aqt.sidebar.SidebarStage.
If you want Anki to proceed with the construction of the tree stage
in question after your have performed your changes or additions,
return the 'handled' boolean unchanged.
On the other hand, if you want to prevent Anki from adding its own
items at a particular construction stage (e.g. in case your add-on
implements its own version of that particular stage), return 'True'.
If you return 'True' at SidebarStage.ROOT, the sidebar will not be
populated by any of the other construction stages. For any other stage
the tree construction will just continue as usual.
For example, if your code wishes to replace the tag tree, you could do:
def on_browser_will_build_tree(handled, root, stage, browser):
if stage != SidebarStage.TAGS:
# not at tag tree building stage, pass on
return handled
# your tag tree construction code
# root.addChild(...)
# your code handled tag tree construction, no need for Anki
# or other add-ons to build the tag tree
return True
""",
),
Hook(
name="browser_will_search",
args=["context: aqt.browser.SearchContext"],
doc="""Allows you to modify the search text, or perform your own search.
You can modify context.search to change the text that is sent to the
searching backend.
If you set context.card_ids to a list of ids, the regular search will
not be performed, and the provided ids will be used instead.
Your add-on should check if context.card_ids is not None, and return
without making changes if it has been set.
""",
),
Hook(
name="browser_did_search",
args=["context: aqt.browser.SearchContext"],
doc="""Allows you to modify the list of returned card ids from a search.""",
),
2021-03-23 10:13:52 +01:00
Hook(
name="browser_did_fetch_row",
args=["card_id: int", "row: aqt.browser.CellRow", "columns: Sequence[str]"],
doc="""Allows you to add or modify content to a row in the browser.
You can mutate the row object to change what is displayed. Any columns the
backend did not recognize will be returned as an empty string, and can be
replaced with custom content.
Columns is a list of string values identifying what each column in the row
represents.
""",
),
# Main window states
2020-01-15 04:03:11 +01:00
###################
# these refer to things like deckbrowser, overview and reviewer state,
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",
args=["state: str", "shortcuts: List[Tuple[str, Callable]]"],
),
# UI state/refreshing
###################
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.",
),
Hook(
name="state_did_reset",
legacy_hook="reset",
2021-03-14 10:54:15 +01:00
doc="""Legacy 'reset' hook. Called by mw.reset() and mw.perform_op() to redraw the UI.
New code should use `operation_did_execute` instead.
""",
),
Hook(
name="operation_did_execute",
args=[
undoable ops now return changes directly; add new *_ops.py files - Introduced a new transact() method that wraps the return value in a separate struct that describes the changes that were made. - Changes are now gathered from the undo log, so we don't need to guess at what was changed - eg if update_note() is called with identical note contents, no changes are returned. Card changes will only be set if cards were actually generated by the update_note() call, and tag will only be set if a new tag was added. - mw.perform_op() has been updated to expect the op to return the changes, or a structure with the changes in it, and it will use them to fire the change hook, instead of fetching the changes from undo_status(), so there is no risk of race conditions. - the various calls to mw.perform_op() have been split into separate files like card_ops.py. Aside from making the code cleaner, this works around a rather annoying issue with mypy. Because we run it with no_strict_optional, mypy is happy to accept an operation that returns None, despite the type signature saying it requires changes to be returned. Turning no_strict_optional on for the whole codebase is not practical at the moment, but we can enable it for individual files. Still todo: - The cursor keeps moving back to the start of a field when typing - we need to ignore the refresh hook when we are the initiator. - The busy cursor icon should probably be delayed a few hundreds ms. - Still need to think about a nicer way of handling saveNow() - op_made_changes(), op_affects_study_queue() might be better embedded as properties in the object instead
2021-03-16 05:26:42 +01:00
"changes: anki.collection.OpChanges",
],
doc="""Called after an operation completes.
2021-03-14 10:54:15 +01:00
Changes can be inspected to determine whether the UI needs updating.
2021-03-18 01:54:02 +01:00
This will also be called when the legacy mw.reset() is used.
2021-03-14 10:54:15 +01:00
""",
),
Hook(
name="focus_did_change",
args=[
"new: Optional[QWidget]",
"old: Optional[QWidget]",
],
doc="""Called each time the focus changes. Can be used to defer updates from
`operation_did_execute` until a window is brought to the front.""",
),
2021-03-18 01:54:02 +01:00
Hook(
name="backend_will_block",
doc="""Called before one or more operations are executed with mw.perform_op().
Subscribers can use this to set a flag to avoid DB queries until the operation
completes, as doing so will freeze the UI until the long-running operation
completes.
""",
),
Hook(
name="backend_did_block",
doc="""Called after one or more operations are executed with mw.perform_op().
Called regardless of the success of individual operations, and only called when
there are no outstanding ops.
""",
),
# Webview
###################
Hook(
name="webview_did_receive_js_message",
args=["handled: Tuple[bool, Any]", "message: str", "context: Any"],
return_type="Tuple[bool, Any]",
doc="""Used to handle pycmd() messages sent from Javascript.
Message is the string passed to pycmd().
For messages you don't want to handle, return 'handled' unchanged.
If you handle a message and don't want it passed to the original
bridge command handler, return (True, None).
If you want to pass a value to pycmd's result callback, you can
return it with (True, some_value).
Context is the instance that was passed to set_bridge_command().
It can be inspected to check which screen this hook is firing
in, and to get a reference to the screen. For example, if your
code wishes to function only in the review screen, you could do:
if not isinstance(context, aqt.reviewer.Reviewer):
# not reviewer, pass on message
return handled
if message == "my-mark-action":
# our message, call onMark() on the reviewer instance
context.onMark()
# and don't pass message to other handlers
return (True, None)
else:
# some other command, pass it on
return handled
""",
),
Hook(
name="webview_will_set_content",
2020-08-31 05:29:28 +02:00
args=[
"web_content: aqt.webview.WebContent",
"context: Optional[Any]",
],
doc="""Used to modify web content before it is rendered.
Web_content contains the HTML, JS, and CSS the web view will be
populated with.
Context is the instance that was passed to stdHtml().
It can be inspected to check which screen this hook is firing
in, and to get a reference to the screen. For example, if your
code wishes to function only in the review screen, you could do:
def on_webview_will_set_content(web_content: WebContent, context):
if not isinstance(context, aqt.reviewer.Reviewer):
# not reviewer, do not modify content
return
# reviewer, perform changes to content
context: aqt.reviewer.Reviewer
addon_package = mw.addonManager.addonFromModule(__name__)
web_content.css.append(
f"/_addons/{addon_package}/web/my-addon.css")
web_content.js.append(
f"/_addons/{addon_package}/web/my-addon.js")
web_content.head += "<script>console.log('my-addon')</script>"
web_content.body += "<div id='my-addon'></div>"
""",
),
Hook(
name="webview_will_show_context_menu",
args=["webview: aqt.webview.AnkiWebView", "menu: QMenu"],
legacy_hook="AnkiWebView.contextMenuEvent",
),
Hook(
name="webview_did_inject_style_into_page",
2020-08-29 14:00:28 +02:00
args=["webview: aqt.webview.AnkiWebView"],
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
mutate the DOM before the page is revealed.
For example:
def mytest(web: AnkiWebView):
page = os.path.basename(web.page().url().path())
if page != "graphs.html":
return
web.eval(
"""
div = document.createElement("div");
div.innerHTML = 'hello';
document.body.appendChild(div);
"""
)
gui_hooks.webview_did_inject_style_into_page.append(mytest)
2020-08-29 14:00:28 +02:00
''',
),
2020-01-15 04:03:11 +01:00
# Main
###################
Hook(
name="main_window_did_init",
doc="""Executed after the main window is fully initialized
A sample use case for this hook would be to delay actions until Anki objects
like the profile or collection are fully initialized. In contrast to
`profile_did_open`, this hook will only fire once per Anki session and
is thus suitable for single-shot subscribers.
""",
),
Hook(
2020-08-16 18:33:33 +02:00
name="main_window_should_require_reset",
args=[
"will_reset: bool",
"reason: Union[aqt.main.ResetReason, str]",
"context: Optional[Any]",
],
return_type="bool",
doc="""Executed before the main window will require a reset
2020-08-16 18:33:33 +02:00
This hook can be used to change the behavior of the main window,
when other dialogs, like the AddCards or Browser, require a reset
from the main window.
2020-08-16 18:33:33 +02:00
If you decide to use this hook, make you sure you check the reason for the reset.
Some reasons require more attention than others, and skipping important ones might
put the main window into an invalid state (e.g. display a deleted note).
""",
),
2020-03-20 11:59:59 +01:00
Hook(name="backup_did_complete"),
Hook(
name="profile_did_open",
legacy_hook="profileLoaded",
doc="""Executed whenever a user profile has been opened
Please note that this hook will also be called on profile switches, so if you
are looking to simply delay an add-on action in a single-shot manner,
`main_window_did_init` is likely the more suitable choice.
""",
),
2020-01-15 04:03:11 +01:00
Hook(name="profile_will_close", legacy_hook="unloadProfile"),
Hook(
name="collection_did_load",
args=["col: anki.collection.Collection"],
2020-01-15 04:03:11 +01:00
legacy_hook="colLoading",
),
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(
name="style_did_init",
args=["style: str"],
return_type="str",
legacy_hook="setupStyle",
),
Hook(
name="top_toolbar_did_init_links",
args=["links: List[str]", "top_toolbar: aqt.toolbar.Toolbar"],
doc="""Used to modify or add links in the top toolbar of Anki's main window
'links' is a list of HTML link elements. Add-ons can generate their own links
by using aqt.toolbar.Toolbar.create_link. Links created in that way can then be
appended to the link list, e.g.:
def on_top_toolbar_did_init_links(links, toolbar):
my_link = toolbar.create_link(...)
links.append(my_link)
""",
),
Hook(
name="top_toolbar_did_redraw",
args=["top_toolbar: aqt.toolbar.Toolbar"],
doc="""Executed when the top toolbar is redrawn""",
),
Hook(
2020-08-31 05:29:28 +02:00
name="media_sync_did_progress",
args=["entry: aqt.mediasync.LogEntryWithTime"],
),
Hook(name="media_sync_did_start_or_stop", args=["running: bool"]),
Hook(
2020-05-20 05:39:21 +02:00
name="empty_cards_will_show",
args=["diag: aqt.emptycards.EmptyCardsDialog"],
doc="""Allows changing the list of cards to delete.""",
),
Hook(name="sync_will_start", args=[]),
Hook(
name="sync_did_finish",
args=[],
doc="""Executes after the sync of the collection concluded.
Note that the media sync did not necessarily finish at this point.""",
),
2020-11-09 10:45:14 +01:00
Hook(name="media_check_will_start", args=[]),
2020-01-15 04:03:11 +01:00
# Adding cards
###################
Hook(
name="add_cards_will_show_history_menu",
args=["addcards: aqt.addcards.AddCards", "menu: QMenu"],
legacy_hook="AddCards.onHistory",
),
2020-08-31 05:29:28 +02:00
Hook(
name="add_cards_did_init",
args=["addcards: aqt.addcards.AddCards"],
),
Hook(
name="add_cards_did_add_note",
args=["note: anki.notes.Note"],
legacy_hook="AddCards.noteAdded",
),
Hook(
2020-03-20 11:59:59 +01:00
name="add_cards_will_add_note",
args=["problem: Optional[str]", "note: anki.notes.Note"],
return_type="Optional[str]",
doc="""Decides whether the note should be added to the collection or
not. It is assumed to come from the addCards window.
reason_to_already_reject is the first reason to reject that
was found, or None. If your filter wants to reject, it should
replace return the reason to reject. Otherwise return the
input.""",
),
Hook(
name="addcards_will_add_history_entry",
args=["line: str", "note: anki.notes.Note"],
return_type="str",
doc="""Allows changing the history line in the add-card window.""",
),
2020-01-15 04:03:11 +01:00
# Editing
###################
Hook(
name="editor_did_init_left_buttons",
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
),
Hook(
name="editor_did_init_buttons",
2020-08-11 22:56:58 +02:00
args=["buttons: List[str]", "editor: aqt.editor.Editor"],
),
Hook(
name="editor_did_init_shortcuts",
args=["shortcuts: List[Tuple]", "editor: aqt.editor.Editor"],
legacy_hook="setupEditorShortcuts",
),
Hook(
name="editor_will_show_context_menu",
args=["editor_webview: aqt.editor.EditorWebView", "menu: QMenu"],
legacy_hook="EditorWebView.contextMenuEvent",
),
Hook(
name="editor_did_fire_typing_timer",
args=["note: anki.notes.Note"],
legacy_hook="editTimer",
),
Hook(
name="editor_did_focus_field",
args=["note: anki.notes.Note", "current_field_idx: int"],
legacy_hook="editFocusGained",
),
Hook(
name="editor_did_unfocus_field",
args=["changed: bool", "note: anki.notes.Note", "current_field_idx: int"],
return_type="bool",
legacy_hook="editFocusLost",
),
Hook(
name="editor_did_load_note",
args=["editor: aqt.editor.Editor"],
legacy_hook="loadNote",
),
Hook(
name="editor_did_update_tags",
args=["note: anki.notes.Note"],
legacy_hook="tagsUpdated",
),
2020-08-08 23:14:55 +02:00
Hook(
name="editor_will_munge_html",
args=["txt: str", "editor: aqt.editor.Editor"],
return_type="str",
doc="""Allows manipulating the text that will be saved by the editor""",
),
Hook(
name="editor_will_use_font_for_field",
args=["font: str"],
return_type="str",
legacy_hook="mungeEditingFontName",
),
Hook(
name="editor_web_view_did_init",
args=["editor_web_view: aqt.editor.EditorWebView"],
),
2020-08-31 05:29:28 +02:00
Hook(
name="editor_did_init",
args=["editor: aqt.editor.Editor"],
),
Hook(
name="editor_will_load_note",
args=["js: str", "note: anki.notes.Note", "editor: aqt.editor.Editor"],
return_type="str",
doc="""Allows changing the javascript commands to load note before
executing it and do change in the QT editor.""",
),
# Tag
###################
2020-04-01 09:13:08 +02:00
Hook(name="tag_editor_did_process_key", args=["tag_edit: TagEdit", "evt: QEvent"]),
# Sound/video
###################
Hook(name="av_player_will_play", args=["tag: anki.sound.AVTag"]),
2020-01-22 05:39:18 +01:00
Hook(
name="av_player_did_begin_playing",
args=["player: aqt.sound.Player", "tag: anki.sound.AVTag"],
),
Hook(name="av_player_did_end_playing", args=["player: aqt.sound.Player"]),
2020-03-02 00:54:58 +01:00
# Addon
###################
Hook(
name="addon_config_editor_will_display_json",
args=["text: str"],
return_type="str",
doc="""Allows changing the text of the json configuration before actually
displaying it to the user. For example, you can replace "\\\\n" by
some actual new line. Then you can replace the new lines by "\\\\n"
while reading the file and let the user uses real new line in
string instead of its encoding.""",
),
2020-03-02 01:09:52 +01:00
Hook(
name="addon_config_editor_will_save_json",
args=["text: str"],
return_type="str",
doc="""Allows changing the text of the json configuration that was
received from the user before actually reading it. For
example, you can replace new line in strings by some "\\\\n".""",
),
2020-03-06 21:04:51 +01:00
Hook(
name="addons_dialog_will_show",
args=["dialog: aqt.addons.AddonsDialog"],
doc="""Allows changing the add-on dialog before it is shown. E.g. add
buttons.""",
),
2020-03-06 22:21:42 +01:00
Hook(
name="addons_dialog_did_change_selected_addon",
args=["dialog: aqt.addons.AddonsDialog", "add_on: aqt.addons.AddonMeta"],
doc="""Allows doing an action when a single add-on is selected.""",
),
# Model
###################
Hook(
name="models_advanced_will_show",
args=["advanced: QDialog"],
),
2020-08-31 05:29:28 +02:00
Hook(
2020-08-31 13:35:01 +02:00
name="models_did_init_buttons",
args=[
"buttons: List[Tuple[str, Callable[[], None]]]",
"models: aqt.models.Models",
],
return_type="List[Tuple[str, Callable[[], None]]]",
2020-08-31 13:35:01 +02:00
doc="""Allows adding buttons to the Model dialog""",
2020-08-31 05:29:28 +02:00
),
# Fields
###################
Hook(
name="fields_did_rename_field",
2020-10-12 04:37:51 +02:00
args=[
"dialog: aqt.fields.FieldDialog",
"field: anki.models.Field",
"old_name: str",
],
),
Hook(
name="fields_did_delete_field",
args=["dialog: aqt.fields.FieldDialog", "field: anki.models.Field"],
),
# Stats
###################
Hook(
name="stats_dialog_will_show",
args=["dialog: aqt.stats.NewDeckStats"],
doc="""Allows changing the stats dialog before it is shown.""",
),
Hook(
name="stats_dialog_old_will_show",
args=["dialog: aqt.stats.DeckStats"],
doc="""Allows changing the old stats dialog before it is shown.""",
),
2020-01-15 04:03:11 +01:00
# Other
###################
Hook(
name="current_note_type_did_change",
2020-08-11 22:56:58 +02:00
args=["notetype: NoteType"],
2020-01-15 04:03:11 +01:00
legacy_hook="currentModelChanged",
legacy_no_args=True,
),
Hook(name="sidebar_should_refresh_decks"),
Hook(name="sidebar_should_refresh_notetypes"),
2020-01-15 04:03:11 +01:00
Hook(
name="deck_browser_will_show_options_menu",
2020-01-15 04:03:11 +01:00
args=["menu: QMenu", "deck_id: int"],
legacy_hook="showDeckOptions",
),
2020-01-13 05:38:05 +01:00
]
suffix = ""
2020-01-13 05:38:05 +01:00
if __name__ == "__main__":
path = sys.argv[1]
write_file(path, hooks, prefix, suffix)