diff --git a/qt/tools/genhooks_gui.py b/qt/tools/genhooks_gui.py index b43660a03..bc31dc2d4 100644 --- a/qt/tools/genhooks_gui.py +++ b/qt/tools/genhooks_gui.py @@ -116,8 +116,8 @@ hooks = [ return_type="tuple[tuple[int, str], ...]", doc="""Used to modify list of answer buttons - 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 + 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. Return a tuple of the form ((int, str), ...), e.g.: @@ -137,11 +137,11 @@ hooks = [ return_type="tuple[bool, Literal[1, 2, 3, 4]]", 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.""", ), @@ -262,15 +262,15 @@ hooks = [ "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
my html
" """, @@ -352,7 +352,7 @@ hooks = [ "deck_options: aqt.deckoptions.DeckOptionsDialog", ], doc="""Can be used to inject extra options into the config screen. - + See the example add-ons at: https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_svelte https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_raw_html @@ -432,36 +432,36 @@ hooks = [ ], 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.browser.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 @@ -471,13 +471,13 @@ hooks = [ 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.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.ids is not None, and return without making changes if it has been set. @@ -499,11 +499,11 @@ hooks = [ "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. """, @@ -512,7 +512,7 @@ hooks = [ name="browser_did_fetch_columns", args=["columns: dict[str, aqt.browser.Column]"], doc="""Allows you to add custom columns to the browser. - + columns is a dictionary of data objects. You can add an entry with a custom column to describe how it should be displayed in the browser or modify existing entries. @@ -571,7 +571,7 @@ hooks = [ name="state_did_reset", legacy_hook="reset", doc="""Legacy 'reset' hook. Called by mw.reset() and CollectionOp() to redraw the UI. - + New code should use `operation_did_execute` instead. """, ), @@ -580,7 +580,7 @@ hooks = [ args=["changes: anki.collection.OpChanges", "handler: object | None"], doc="""Called after an operation completes. Changes can be inspected to determine whether the UI needs updating. - + This will also be called when the legacy mw.reset() is used. """, ), @@ -596,7 +596,7 @@ hooks = [ Hook( name="backend_will_block", doc="""Called before one or more DB tasks are run in the background. - + 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. @@ -624,17 +624,17 @@ hooks = [ 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 @@ -643,7 +643,7 @@ hooks = [ 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() @@ -671,17 +671,17 @@ hooks = [ 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( @@ -708,7 +708,7 @@ For example: def mytest(web: AnkiWebView): page = os.path.basename(web.page().url().path()) if page != "graphs.html": - return + return web.eval( """ div = document.createElement("div"); @@ -725,7 +725,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) 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 @@ -755,7 +755,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) 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. @@ -789,7 +789,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) 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.: @@ -870,11 +870,11 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) ], return_type="aqt.import_export.exporting.ExportOptions", doc="""Called before collection and deck exports. - + Allows add-ons to be notified of impending deck exports and potentially modify the export options. To perform the export unaltered, please return `export_options` as is, e.g.: - + def on_exporter_will_export(export_options: ExportOptions, exporter: Exporter): if not isinstance(exporter, ApkgExporter): return export_options @@ -983,7 +983,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest) Hook( name="add_cards_did_change_deck", args=["new_deck_id: int"], - doc="""Executed after the user selects a new different deck when + doc="""Executed after the user selects a new different deck when adding cards.""", ), # Editing