mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Trimmed whitespaces on qt/tools/genhooks_gui.py
This commit is contained in:
parent
77bba533ea
commit
c32f14f7cb
1 changed files with 43 additions and 43 deletions
|
@ -116,8 +116,8 @@ hooks = [
|
||||||
return_type="tuple[tuple[int, str], ...]",
|
return_type="tuple[tuple[int, str], ...]",
|
||||||
doc="""Used to modify list of answer buttons
|
doc="""Used to modify list of answer buttons
|
||||||
|
|
||||||
buttons_tuple is a tuple of buttons, with each button represented by a
|
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
|
tuple containing an int for the button's ease and a string for the
|
||||||
button's label.
|
button's label.
|
||||||
|
|
||||||
Return a tuple of the form ((int, str), ...), e.g.:
|
Return a tuple of the form ((int, str), ...), e.g.:
|
||||||
|
@ -137,11 +137,11 @@ hooks = [
|
||||||
return_type="tuple[bool, Literal[1, 2, 3, 4]]",
|
return_type="tuple[bool, Literal[1, 2, 3, 4]]",
|
||||||
doc="""Used to modify the ease at which a card is rated or to bypass
|
doc="""Used to modify the ease at which a card is rated or to bypass
|
||||||
rating the card completely.
|
rating the card completely.
|
||||||
|
|
||||||
ease_tuple is a tuple consisting of a boolean expressing whether the reviewer
|
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
|
should continue with rating the card, and an integer expressing the ease at
|
||||||
which the card should be rated.
|
which the card should be rated.
|
||||||
|
|
||||||
If your code just needs to be notified of the card rating event, you should use
|
If your code just needs to be notified of the card rating event, you should use
|
||||||
the reviewer_did_answer_card hook instead.""",
|
the reviewer_did_answer_card hook instead.""",
|
||||||
),
|
),
|
||||||
|
@ -262,15 +262,15 @@ hooks = [
|
||||||
"content: aqt.deckbrowser.DeckBrowserContent",
|
"content: aqt.deckbrowser.DeckBrowserContent",
|
||||||
],
|
],
|
||||||
doc="""Used to modify HTML content sections in the deck browser body
|
doc="""Used to modify HTML content sections in the deck browser body
|
||||||
|
|
||||||
'content' contains the sections of HTML content the deck browser body
|
'content' contains the sections of HTML content the deck browser body
|
||||||
will be updated with.
|
will be updated with.
|
||||||
|
|
||||||
When modifying the content of a particular section, please make sure your
|
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.
|
changes only perform the minimum required edits to make your add-on work.
|
||||||
You should avoid overwriting or interfering with existing data as much
|
You should avoid overwriting or interfering with existing data as much
|
||||||
as possible, instead opting to append your own changes, e.g.:
|
as possible, instead opting to append your own changes, e.g.:
|
||||||
|
|
||||||
def on_deck_browser_will_render_content(deck_browser, content):
|
def on_deck_browser_will_render_content(deck_browser, content):
|
||||||
content.stats += "\\n<div>my html</div>"
|
content.stats += "\\n<div>my html</div>"
|
||||||
""",
|
""",
|
||||||
|
@ -352,7 +352,7 @@ hooks = [
|
||||||
"deck_options: aqt.deckoptions.DeckOptionsDialog",
|
"deck_options: aqt.deckoptions.DeckOptionsDialog",
|
||||||
],
|
],
|
||||||
doc="""Can be used to inject extra options into the config screen.
|
doc="""Can be used to inject extra options into the config screen.
|
||||||
|
|
||||||
See the example add-ons at:
|
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_svelte
|
||||||
https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_raw_html
|
https://github.com/ankitects/anki-addons/tree/main/demos/deckoptions_raw_html
|
||||||
|
@ -432,36 +432,36 @@ hooks = [
|
||||||
],
|
],
|
||||||
return_type="bool",
|
return_type="bool",
|
||||||
doc="""Used to add or replace items in the browser sidebar tree
|
doc="""Used to add or replace items in the browser sidebar tree
|
||||||
|
|
||||||
'tree' is the root SidebarItem that all other items are added to.
|
'tree' is the root SidebarItem that all other items are added to.
|
||||||
|
|
||||||
'stage' is an enum describing the different construction stages of
|
'stage' is an enum describing the different construction stages of
|
||||||
the sidebar tree at which you can interject your changes.
|
the sidebar tree at which you can interject your changes.
|
||||||
The different values can be inspected by looking at
|
The different values can be inspected by looking at
|
||||||
aqt.browser.SidebarStage.
|
aqt.browser.SidebarStage.
|
||||||
|
|
||||||
If you want Anki to proceed with the construction of the tree stage
|
If you want Anki to proceed with the construction of the tree stage
|
||||||
in question after your have performed your changes or additions,
|
in question after your have performed your changes or additions,
|
||||||
return the 'handled' boolean unchanged.
|
return the 'handled' boolean unchanged.
|
||||||
|
|
||||||
On the other hand, if you want to prevent Anki from adding its own
|
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
|
items at a particular construction stage (e.g. in case your add-on
|
||||||
implements its own version of that particular stage), return 'True'.
|
implements its own version of that particular stage), return 'True'.
|
||||||
|
|
||||||
If you return 'True' at SidebarStage.ROOT, the sidebar will not be
|
If you return 'True' at SidebarStage.ROOT, the sidebar will not be
|
||||||
populated by any of the other construction stages. For any other stage
|
populated by any of the other construction stages. For any other stage
|
||||||
the tree construction will just continue as usual.
|
the tree construction will just continue as usual.
|
||||||
|
|
||||||
For example, if your code wishes to replace the tag tree, you could do:
|
For example, if your code wishes to replace the tag tree, you could do:
|
||||||
|
|
||||||
def on_browser_will_build_tree(handled, root, stage, browser):
|
def on_browser_will_build_tree(handled, root, stage, browser):
|
||||||
if stage != SidebarStage.TAGS:
|
if stage != SidebarStage.TAGS:
|
||||||
# not at tag tree building stage, pass on
|
# not at tag tree building stage, pass on
|
||||||
return handled
|
return handled
|
||||||
|
|
||||||
# your tag tree construction code
|
# your tag tree construction code
|
||||||
# root.addChild(...)
|
# root.addChild(...)
|
||||||
|
|
||||||
# your code handled tag tree construction, no need for Anki
|
# your code handled tag tree construction, no need for Anki
|
||||||
# or other add-ons to build the tag tree
|
# or other add-ons to build the tag tree
|
||||||
return True
|
return True
|
||||||
|
@ -471,13 +471,13 @@ hooks = [
|
||||||
name="browser_will_search",
|
name="browser_will_search",
|
||||||
args=["context: aqt.browser.SearchContext"],
|
args=["context: aqt.browser.SearchContext"],
|
||||||
doc="""Allows you to modify the search text, or perform your own search.
|
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
|
You can modify context.search to change the text that is sent to the
|
||||||
searching backend.
|
searching backend.
|
||||||
|
|
||||||
If you set context.ids to a list of ids, the regular search will
|
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.
|
not be performed, and the provided ids will be used instead.
|
||||||
|
|
||||||
Your add-on should check if context.ids is not None, and return
|
Your add-on should check if context.ids is not None, and return
|
||||||
without making changes if it has been set.
|
without making changes if it has been set.
|
||||||
|
|
||||||
|
@ -499,11 +499,11 @@ hooks = [
|
||||||
"columns: Sequence[str]",
|
"columns: Sequence[str]",
|
||||||
],
|
],
|
||||||
doc="""Allows you to add or modify content to a row in the browser.
|
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
|
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
|
backend did not recognize will be returned as an empty string, and can be
|
||||||
replaced with custom content.
|
replaced with custom content.
|
||||||
|
|
||||||
Columns is a list of string values identifying what each column in the row
|
Columns is a list of string values identifying what each column in the row
|
||||||
represents.
|
represents.
|
||||||
""",
|
""",
|
||||||
|
@ -512,7 +512,7 @@ hooks = [
|
||||||
name="browser_did_fetch_columns",
|
name="browser_did_fetch_columns",
|
||||||
args=["columns: dict[str, aqt.browser.Column]"],
|
args=["columns: dict[str, aqt.browser.Column]"],
|
||||||
doc="""Allows you to add custom columns to the browser.
|
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
|
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
|
column to describe how it should be displayed in the browser or modify
|
||||||
existing entries.
|
existing entries.
|
||||||
|
@ -571,7 +571,7 @@ hooks = [
|
||||||
name="state_did_reset",
|
name="state_did_reset",
|
||||||
legacy_hook="reset",
|
legacy_hook="reset",
|
||||||
doc="""Legacy 'reset' hook. Called by mw.reset() and CollectionOp() to redraw the UI.
|
doc="""Legacy 'reset' hook. Called by mw.reset() and CollectionOp() to redraw the UI.
|
||||||
|
|
||||||
New code should use `operation_did_execute` instead.
|
New code should use `operation_did_execute` instead.
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
|
@ -580,7 +580,7 @@ hooks = [
|
||||||
args=["changes: anki.collection.OpChanges", "handler: object | None"],
|
args=["changes: anki.collection.OpChanges", "handler: object | None"],
|
||||||
doc="""Called after an operation completes.
|
doc="""Called after an operation completes.
|
||||||
Changes can be inspected to determine whether the UI needs updating.
|
Changes can be inspected to determine whether the UI needs updating.
|
||||||
|
|
||||||
This will also be called when the legacy mw.reset() is used.
|
This will also be called when the legacy mw.reset() is used.
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
|
@ -596,7 +596,7 @@ hooks = [
|
||||||
Hook(
|
Hook(
|
||||||
name="backend_will_block",
|
name="backend_will_block",
|
||||||
doc="""Called before one or more DB tasks are run in the background.
|
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
|
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, as doing so will freeze the UI until the long-running operation
|
||||||
completes.
|
completes.
|
||||||
|
@ -624,17 +624,17 @@ hooks = [
|
||||||
args=["handled: tuple[bool, Any]", "message: str", "context: Any"],
|
args=["handled: tuple[bool, Any]", "message: str", "context: Any"],
|
||||||
return_type="tuple[bool, Any]",
|
return_type="tuple[bool, Any]",
|
||||||
doc="""Used to handle pycmd() messages sent from Javascript.
|
doc="""Used to handle pycmd() messages sent from Javascript.
|
||||||
|
|
||||||
Message is the string passed to pycmd().
|
Message is the string passed to pycmd().
|
||||||
|
|
||||||
For messages you don't want to handle, return 'handled' unchanged.
|
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
|
If you handle a message and don't want it passed to the original
|
||||||
bridge command handler, return (True, None).
|
bridge command handler, return (True, None).
|
||||||
|
|
||||||
If you want to pass a value to pycmd's result callback, you can
|
If you want to pass a value to pycmd's result callback, you can
|
||||||
return it with (True, some_value).
|
return it with (True, some_value).
|
||||||
|
|
||||||
Context is the instance that was passed to set_bridge_command().
|
Context is the instance that was passed to set_bridge_command().
|
||||||
It can be inspected to check which screen this hook is firing
|
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
|
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):
|
if not isinstance(context, aqt.reviewer.Reviewer):
|
||||||
# not reviewer, pass on message
|
# not reviewer, pass on message
|
||||||
return handled
|
return handled
|
||||||
|
|
||||||
if message == "my-mark-action":
|
if message == "my-mark-action":
|
||||||
# our message, call onMark() on the reviewer instance
|
# our message, call onMark() on the reviewer instance
|
||||||
context.onMark()
|
context.onMark()
|
||||||
|
@ -671,17 +671,17 @@ hooks = [
|
||||||
code wishes to function only in the review screen, you could do:
|
code wishes to function only in the review screen, you could do:
|
||||||
|
|
||||||
def on_webview_will_set_content(web_content: WebContent, context):
|
def on_webview_will_set_content(web_content: WebContent, context):
|
||||||
|
|
||||||
if not isinstance(context, aqt.reviewer.Reviewer):
|
if not isinstance(context, aqt.reviewer.Reviewer):
|
||||||
# not reviewer, do not modify content
|
# not reviewer, do not modify content
|
||||||
return
|
return
|
||||||
|
|
||||||
# reviewer, perform changes to content
|
# reviewer, perform changes to content
|
||||||
|
|
||||||
context: aqt.reviewer.Reviewer
|
context: aqt.reviewer.Reviewer
|
||||||
|
|
||||||
addon_package = mw.addonManager.addonFromModule(__name__)
|
addon_package = mw.addonManager.addonFromModule(__name__)
|
||||||
|
|
||||||
web_content.css.append(
|
web_content.css.append(
|
||||||
f"/_addons/{addon_package}/web/my-addon.css")
|
f"/_addons/{addon_package}/web/my-addon.css")
|
||||||
web_content.js.append(
|
web_content.js.append(
|
||||||
|
@ -708,7 +708,7 @@ For example:
|
||||||
def mytest(web: AnkiWebView):
|
def mytest(web: AnkiWebView):
|
||||||
page = os.path.basename(web.page().url().path())
|
page = os.path.basename(web.page().url().path())
|
||||||
if page != "graphs.html":
|
if page != "graphs.html":
|
||||||
return
|
return
|
||||||
web.eval(
|
web.eval(
|
||||||
"""
|
"""
|
||||||
div = document.createElement("div");
|
div = document.createElement("div");
|
||||||
|
@ -725,7 +725,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
Hook(
|
Hook(
|
||||||
name="main_window_did_init",
|
name="main_window_did_init",
|
||||||
doc="""Executed after the main window is fully initialized
|
doc="""Executed after the main window is fully initialized
|
||||||
|
|
||||||
A sample use case for this hook would be to delay actions until Anki objects
|
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
|
like the profile or collection are fully initialized. In contrast to
|
||||||
`profile_did_open`, this hook will only fire once per Anki session and
|
`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",
|
name="profile_did_open",
|
||||||
legacy_hook="profileLoaded",
|
legacy_hook="profileLoaded",
|
||||||
doc="""Executed whenever a user profile has been opened
|
doc="""Executed whenever a user profile has been opened
|
||||||
|
|
||||||
Please note that this hook will also be called on profile switches, so if you
|
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,
|
are looking to simply delay an add-on action in a single-shot manner,
|
||||||
`main_window_did_init` is likely the more suitable choice.
|
`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",
|
name="top_toolbar_did_init_links",
|
||||||
args=["links: list[str]", "top_toolbar: aqt.toolbar.Toolbar"],
|
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
|
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
|
'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
|
by using aqt.toolbar.Toolbar.create_link. Links created in that way can then be
|
||||||
appended to the link list, e.g.:
|
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",
|
return_type="aqt.import_export.exporting.ExportOptions",
|
||||||
doc="""Called before collection and deck exports.
|
doc="""Called before collection and deck exports.
|
||||||
|
|
||||||
Allows add-ons to be notified of impending deck exports and potentially
|
Allows add-ons to be notified of impending deck exports and potentially
|
||||||
modify the export options. To perform the export unaltered, please return
|
modify the export options. To perform the export unaltered, please return
|
||||||
`export_options` as is, e.g.:
|
`export_options` as is, e.g.:
|
||||||
|
|
||||||
def on_exporter_will_export(export_options: ExportOptions, exporter: Exporter):
|
def on_exporter_will_export(export_options: ExportOptions, exporter: Exporter):
|
||||||
if not isinstance(exporter, ApkgExporter):
|
if not isinstance(exporter, ApkgExporter):
|
||||||
return export_options
|
return export_options
|
||||||
|
@ -983,7 +983,7 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
|
||||||
Hook(
|
Hook(
|
||||||
name="add_cards_did_change_deck",
|
name="add_cards_did_change_deck",
|
||||||
args=["new_deck_id: int"],
|
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.""",
|
adding cards.""",
|
||||||
),
|
),
|
||||||
# Editing
|
# Editing
|
||||||
|
|
Loading…
Reference in a new issue