aqt.webview

Contents

aqt.webview#

Attributes#

Classes#

AnkiWebViewKind

Enum registry of all web views managed by Anki

AuthInterceptor

AnkiWebPage

WebContent

Stores all dynamically modified content that a particular web view

AnkiWebView

Module Contents#

aqt.webview.serverbaseurl#
aqt.webview.BridgeCommandHandler#
class aqt.webview.AnkiWebViewKind(*args, **kwds)#

Bases: enum.Enum

Enum registry of all web views managed by Anki

The value of each entry corresponds to the web view’s title.

When introducing a new web view, please add it to the registry below.

DEFAULT = 'default'#
MAIN = 'main webview'#
TOP_TOOLBAR = 'top toolbar'#
BOTTOM_TOOLBAR = 'bottom toolbar'#
DECK_OPTIONS = 'deck options'#
EDITOR = 'editor'#
LEGACY_DECK_STATS = 'legacy deck stats'#
DECK_STATS = 'deck stats'#
PREVIEWER = 'previewer'#
CHANGE_NOTETYPE = 'change notetype'#
CARD_LAYOUT = 'card layout'#
BROWSER_CARD_INFO = 'browser card info'#
IMPORT_CSV = 'csv import'#
EMPTY_CARDS = 'empty cards'#
FIND_DUPLICATES = 'find duplicates'#
FIELDS = 'fields'#
IMPORT_LOG = 'import log'#
IMPORT_ANKI_PACKAGE = 'anki package import'#
class aqt.webview.AuthInterceptor(parent: QObject | None = None, api_enabled: bool = False)#

Bases: QWebEngineUrlRequestInterceptor

interceptRequest(info)#
class aqt.webview.AnkiWebPage(onBridgeCmd: BridgeCommandHandler, kind: AnkiWebViewKind = AnkiWebViewKind.DEFAULT, parent: QObject | None = None)#

Bases: QWebEnginePage

javaScriptConsoleMessage(level: QWebEnginePage.JavaScriptConsoleMessageLevel, msg: str | None, line: int, srcID: str | None) None#
acceptNavigationRequest(url: QUrl, navType: Any, isMainFrame: bool) bool#
javaScriptAlert(frame: Any, text: str | None) None#
javaScriptConfirm(frame: Any, text: str | None) bool#
class aqt.webview.WebContent#

Stores all dynamically modified content that a particular web view will be populated with.

Attributes:

body {str} – HTML body head {str} – HTML head css {List[str]} – List of media server subpaths,

each pointing to a CSS file

js {List[str]} – List of media server subpaths,

each pointing to a JS file

Important Notes:
  • When modifying the attributes specified above, 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_webview_will_set_content(web_content: WebContent, context) -> None:

web_content.body += “<my_html>” web_content.head += “<my_head>”

  • The paths specified in css and js need to be accessible by Anki’s media server. All list members without a specified subpath are assumed to be located under /_anki, which is the media server subpath used for all web assets shipped with Anki.

    Add-ons may expose their own web assets by utilizing aqt.addons.AddonManager.setWebExports(). Web exports registered in this manner may then be accessed under the /_addons subpath.

    E.g., to allow access to a my-addon.js and my-addon.css residing in a “web” subfolder in your add-on package, first register the corresponding web export:

    > from aqt import mw > mw.addonManager.setWebExports(__name__, r”web/.*(css|js)”)

    Then append the subpaths to the corresponding web_content fields within a function subscribing to gui_hooks.webview_will_set_content:

    def on_webview_will_set_content(web_content: WebContent, context) -> None:

    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”)

    Note that ‘/’ will also match the os specific path separator.

body: str = ''#
head: str = ''#
css: list[str] = []#
js: list[str] = []#
class aqt.webview.AnkiWebView(parent: QWidget | None = None, title: str = '', kind: AnkiWebViewKind = AnkiWebViewKind.DEFAULT)#

Bases: QWebEngineView

allow_drops = False#
onBridgeCmd: collections.abc.Callable[[str], Any]#
requiresCol = True#
page() AnkiWebPage#
property kind: AnkiWebViewKind#

Used by add-ons to identify the webview kind

set_title(title: str) None#
disable_zoom() None#
createWindow(windowType: QWebEnginePage.WebWindowType) QWebEngineView#
eventFilter(obj: QObject | None, evt: QEvent | None) bool#
onEsc() None#
onCopy() None#
onCut() None#
onPaste() None#
onMiddleClickPaste() None#
onSelectAll() None#
contextMenuEvent(evt: QContextMenuEvent | None) None#
dropEvent(evt: QDropEvent | None) None#
setHtml(html: str, context: aqt.mediasrv.PageContext | None = None) None#
load_url(url: QUrl) None#
app_zoom_factor() float#
setPlaybackRequiresGesture(value: bool) None#
standard_css() str#
stdHtml(body: str, css: list[str] | None = None, js: list[str] | None = None, head: str = '', context: Any | None = None, default_css: bool = True) None#
classmethod webBundlePath(path: str) str#
bundledScript(fname: str) str#
bundledCSS(fname: str) str#
eval(js: str) None#
evalWithCallback(js: str, cb: collections.abc.Callable | None) None#
defaultOnBridgeCmd(cmd: str) None#
resetHandlers() None#
adjustHeightToFit() None#
set_bridge_command(func: collections.abc.Callable[[str], Any], context: Any) None#

Set a handler for pycmd() messages received from Javascript.

Context is the object calling this routine, eg an instance of aqt.reviewer.Reviewer or aqt.deckbrowser.DeckBrowser.

hide_while_preserving_layout() None#

Hide but keep existing size.

add_dynamic_styling_and_props_then_show() None#

Add dynamic styling, title, set platform-specific body classes and reveal.

load_ts_page(name: str) None#
load_sveltekit_page(path: str) None#
force_load_hack() None#

Force process to initialize. Must be done on Windows prior to changing current working directory.

cleanup() None#
on_theme_did_change() None#
on_body_classes_need_update() None#
get_window_bg_color(night_mode: bool | None = None) QColor#
aqt.webview.StatsWebView#
aqt.webview.LegacyStatsWebView#
aqt.webview.EmptyCardsWebView#
aqt.webview.FindDupesWebView#