aqt.webview
===========

.. py:module:: aqt.webview


Attributes
----------

.. autoapisummary::

   aqt.webview.serverbaseurl
   aqt.webview.BridgeCommandHandler
   aqt.webview.StatsWebView
   aqt.webview.LegacyStatsWebView
   aqt.webview.EmptyCardsWebView
   aqt.webview.FindDupesWebView


Classes
-------

.. autoapisummary::

   aqt.webview.AnkiWebViewKind
   aqt.webview.AuthInterceptor
   aqt.webview.AnkiWebPage
   aqt.webview.WebContent
   aqt.webview.AnkiWebView


Module Contents
---------------

.. py:data:: serverbaseurl

.. py:data:: BridgeCommandHandler

.. py:class:: AnkiWebViewKind(*args, **kwds)

   Bases: :py:obj:`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.


   .. py:attribute:: DEFAULT
      :value: 'default'



   .. py:attribute:: MAIN
      :value: 'main webview'



   .. py:attribute:: TOP_TOOLBAR
      :value: 'top toolbar'



   .. py:attribute:: BOTTOM_TOOLBAR
      :value: 'bottom toolbar'



   .. py:attribute:: DECK_OPTIONS
      :value: 'deck options'



   .. py:attribute:: EDITOR
      :value: 'editor'



   .. py:attribute:: LEGACY_DECK_STATS
      :value: 'legacy deck stats'



   .. py:attribute:: DECK_STATS
      :value: 'deck stats'



   .. py:attribute:: PREVIEWER
      :value: 'previewer'



   .. py:attribute:: CHANGE_NOTETYPE
      :value: 'change notetype'



   .. py:attribute:: CARD_LAYOUT
      :value: 'card layout'



   .. py:attribute:: BROWSER_CARD_INFO
      :value: 'browser card info'



   .. py:attribute:: IMPORT_CSV
      :value: 'csv import'



   .. py:attribute:: EMPTY_CARDS
      :value: 'empty cards'



   .. py:attribute:: FIND_DUPLICATES
      :value: 'find duplicates'



   .. py:attribute:: FIELDS
      :value: 'fields'



   .. py:attribute:: IMPORT_LOG
      :value: 'import log'



   .. py:attribute:: IMPORT_ANKI_PACKAGE
      :value: 'anki package import'



.. py:class:: AuthInterceptor(parent: QObject | None = None, api_enabled: bool = False)

   Bases: :py:obj:`QWebEngineUrlRequestInterceptor`


   .. py:method:: interceptRequest(info)


.. py:class:: AnkiWebPage(onBridgeCmd: BridgeCommandHandler, kind: AnkiWebViewKind = AnkiWebViewKind.DEFAULT, parent: QObject | None = None)

   Bases: :py:obj:`QWebEnginePage`


   .. py:attribute:: open_links_externally
      :value: True



   .. py:method:: javaScriptConsoleMessage(level: QWebEnginePage.JavaScriptConsoleMessageLevel, msg: str | None, line: int, srcID: str | None) -> None


   .. py:method:: acceptNavigationRequest(url: QUrl, navType: Any, isMainFrame: bool) -> bool


   .. py:method:: javaScriptAlert(frame: Any, text: str | None) -> None


   .. py:method:: javaScriptConfirm(frame: Any, text: str | None) -> bool


.. py:class:: 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.


   .. py:attribute:: body
      :type:  str
      :value: ''



   .. py:attribute:: head
      :type:  str
      :value: ''



   .. py:attribute:: css
      :type:  list[str]
      :value: []



   .. py:attribute:: js
      :type:  list[str]
      :value: []



.. py:class:: AnkiWebView(parent: QWidget | None = None, title: str = '', kind: AnkiWebViewKind = AnkiWebViewKind.DEFAULT)

   Bases: :py:obj:`QWebEngineView`


   .. py:attribute:: allow_drops
      :value: False



   .. py:attribute:: onBridgeCmd
      :type:  collections.abc.Callable[[str], Any]


   .. py:attribute:: requiresCol
      :value: True



   .. py:method:: page() -> AnkiWebPage


   .. py:property:: kind
      :type: AnkiWebViewKind


      Used by add-ons to identify the webview kind



   .. py:method:: set_title(title: str) -> None


   .. py:method:: disable_zoom() -> None


   .. py:method:: createWindow(windowType: QWebEnginePage.WebWindowType) -> QWebEngineView


   .. py:method:: eventFilter(obj: QObject | None, evt: QEvent | None) -> bool


   .. py:method:: set_open_links_externally(enable: bool) -> None


   .. py:method:: onEsc() -> None


   .. py:method:: onCopy() -> None


   .. py:method:: onCut() -> None


   .. py:method:: onPaste() -> None


   .. py:method:: onMiddleClickPaste() -> None


   .. py:method:: onSelectAll() -> None


   .. py:method:: contextMenuEvent(evt: QContextMenuEvent | None) -> None


   .. py:method:: dropEvent(evt: QDropEvent | None) -> None


   .. py:method:: setHtml(html: str, context: aqt.mediasrv.PageContext | None = None) -> None


   .. py:method:: load_url(url: QUrl) -> None


   .. py:method:: app_zoom_factor() -> float


   .. py:method:: setPlaybackRequiresGesture(value: bool) -> None


   .. py:method:: standard_css() -> str


   .. py:method:: stdHtml(body: str, css: list[str] | None = None, js: list[str] | None = None, head: str = '', context: Any | None = None, default_css: bool = True) -> None


   .. py:method:: webBundlePath(path: str) -> str
      :classmethod:



   .. py:method:: bundledScript(fname: str) -> str


   .. py:method:: bundledCSS(fname: str) -> str


   .. py:method:: eval(js: str) -> None


   .. py:method:: evalWithCallback(js: str, cb: collections.abc.Callable | None) -> None


   .. py:method:: defaultOnBridgeCmd(cmd: str) -> None


   .. py:method:: resetHandlers() -> None


   .. py:method:: adjustHeightToFit() -> None


   .. py:method:: 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.



   .. py:method:: hide_while_preserving_layout() -> None

      Hide but keep existing size.



   .. py:method:: add_dynamic_styling_and_props_then_show() -> None

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



   .. py:method:: load_ts_page(name: str) -> None


   .. py:method:: load_sveltekit_page(path: str) -> None


   .. py:method:: force_load_hack() -> None

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



   .. py:method:: cleanup() -> None


   .. py:method:: on_theme_did_change() -> None


   .. py:method:: on_body_classes_need_update() -> None


   .. py:method:: get_window_bg_color(night_mode: bool | None = None) -> QColor


.. py:data:: StatsWebView

.. py:data:: LegacyStatsWebView

.. py:data:: EmptyCardsWebView

.. py:data:: FindDupesWebView

