aqt.editor
==========

.. py:module:: aqt.editor


Attributes
----------

.. autoapisummary::

   aqt.editor.pics
   aqt.editor.audio


Classes
-------

.. autoapisummary::

   aqt.editor.EditorMode
   aqt.editor.EditorState
   aqt.editor.Editor
   aqt.editor.EditorWebView


Functions
---------

.. autoapisummary::

   aqt.editor.fontMungeHack
   aqt.editor.munge_html
   aqt.editor.remove_null_bytes
   aqt.editor.reverse_url_quoting
   aqt.editor.set_cloze_button
   aqt.editor.set_image_occlusion_button


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

.. py:data:: pics
   :value: ('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF', 'svg', 'SVG', 'webp', 'WEBP', 'ico',...


.. py:data:: audio
   :value: ('3gp', '3GP', 'aac', 'AAC', 'avi', 'AVI', 'flac', 'FLAC', 'flv', 'FLV', 'm4a', 'M4A', 'mkv',...


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

   Bases: :py:obj:`enum.Enum`


   Create a collection of name/value pairs.

   Example enumeration:

   >>> class Color(Enum):
   ...     RED = 1
   ...     BLUE = 2
   ...     GREEN = 3

   Access them by:

   - attribute access:

     >>> Color.RED
     <Color.RED: 1>

   - value lookup:

     >>> Color(1)
     <Color.RED: 1>

   - name lookup:

     >>> Color['RED']
     <Color.RED: 1>

   Enumerations can be iterated over, and know how many members they have:

   >>> len(Color)
   3

   >>> list(Color)
   [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

   Methods can be added to enumerations, and members can have their own
   attributes -- see the documentation for details.


   .. py:attribute:: ADD_CARDS
      :value: 0



   .. py:attribute:: EDIT_CURRENT
      :value: 1



   .. py:attribute:: BROWSER
      :value: 2



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

   Bases: :py:obj:`enum.Enum`


   Current input state of the editing UI.


   .. py:attribute:: INITIAL
      :value: -1



   .. py:attribute:: FIELDS
      :value: 0



   .. py:attribute:: IO_PICKER
      :value: 1



   .. py:attribute:: IO_MASKS
      :value: 2



   .. py:attribute:: IO_FIELDS
      :value: 3



.. py:class:: Editor(mw: aqt.AnkiQt, widget: QWidget, parentWindow: QWidget, addMode: bool | None = None, *, editor_mode: EditorMode = EditorMode.EDIT_CURRENT)

   The screen that embeds an editing widget should listen for changes via
   the `operation_did_execute` hook, and call set_note() when the editor needs
   redrawing.

   The editor will cause that hook to be fired when it saves changes. To avoid
   an unwanted refresh, the parent widget should check if handler
   corresponds to this editor instance, and ignore the change if it does.


   .. py:attribute:: mw


   .. py:attribute:: widget


   .. py:attribute:: parentWindow


   .. py:attribute:: note
      :type:  anki.notes.Note | None
      :value: None



   .. py:attribute:: addMode


   .. py:attribute:: editorMode


   .. py:attribute:: currentField
      :type:  int | None
      :value: None



   .. py:attribute:: last_field_index
      :type:  int | None
      :value: None



   .. py:attribute:: orig_note_id
      :type:  anki.notes.NoteId | None
      :value: None



   .. py:attribute:: card
      :type:  anki.cards.Card | None
      :value: None



   .. py:attribute:: state
      :type:  EditorState


   .. py:attribute:: last_io_image_path
      :type:  str | None
      :value: None



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


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


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


   .. py:method:: resourceToData(path: str) -> str

      Convert a file (specified by a path) into a data URI.



   .. py:method:: addButton(icon: str | None, cmd: str, func: collections.abc.Callable[[Editor], None], tip: str = '', label: str = '', id: str | None = None, toggleable: bool = False, keys: str | None = None, disables: bool = True, rightside: bool = True) -> str

      Assign func to bridge cmd, register shortcut, return button



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


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


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


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


   .. py:method:: onBridgeCmd(cmd: str) -> Any


   .. py:method:: mungeHTML(txt: str) -> str


   .. py:method:: signal_state_change(new_state: EditorState, old_state: EditorState) -> None


   .. py:method:: set_note(note: anki.notes.Note | None, hide: bool = True, focusTo: int | None = None) -> None

      Make NOTE the current note.



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


   .. py:method:: loadNote(focusTo: int | None = None) -> None


   .. py:method:: fonts() -> list[tuple[str, int, bool]]


   .. py:method:: call_after_note_saved(callback: collections.abc.Callable, keepFocus: bool = False) -> None

      Save unsaved edits then call callback().



   .. py:attribute:: saveNow


   .. py:attribute:: checkValid


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


   .. py:method:: fieldsAreBlank(previousNote: anki.notes.Note | None = None) -> bool


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


   .. py:attribute:: setNote


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


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


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


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


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


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


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


   .. py:attribute:: saveTags


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

      Show a file selection screen, then add the selected media.
      This expects initial setup to have been done by TemplateButtons.svelte.



   .. py:method:: addMedia(path: str, canDelete: bool = False) -> None

      Legacy routine used by add-ons to add a media file and update the current field.
      canDelete is ignored.



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

      Finish inserting media into a field.
      This expects initial setup to have been done by TemplateButtons.svelte.



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


   .. py:method:: urlToLink(url: str, allowed_suffixes: Iterable[str] = ()) -> str


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


   .. py:method:: urlToFile(url: str, allowed_suffixes: Iterable[str] = pics + audio) -> str | None


   .. py:method:: isURL(s: str) -> bool


   .. py:method:: inlinedImageToFilename(txt: str) -> str


   .. py:method:: inlinedImageToLink(src: str) -> str


   .. py:attribute:: removeTags
      :value: ['script', 'iframe', 'object', 'style']



   .. py:method:: doPaste(html: str, internal: bool, extended: bool = False) -> None


   .. py:method:: doDrop(html: str, internal: bool, extended: bool, cursor_pos: QPoint) -> None


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


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


   .. py:method:: current_notetype_is_image_occlusion() -> bool


   .. py:method:: setup_mask_editor(image_path: str) -> None


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

      Show a file selection screen, then get selected image path.



   .. py:method:: extract_img_path_from_html(html: str) -> str | None


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

      Set up the mask editor for the image in the clipboard.



   .. py:method:: setup_mask_editor_for_new_note(image_path: str, notetype_id: anki.models.NotetypeId | int = 0)

      Set-up IO mask editor for adding new notes
      Presupposes that active editor notetype is an image occlusion notetype
      Args:
          image_path: Absolute path to image.
          notetype_id: ID of note type to use. Provided ID must belong to an
            image occlusion notetype. Set this to 0 to auto-select the first
            found image occlusion notetype in the user's collection.



   .. py:method:: setup_mask_editor_for_existing_note(note_id: anki.notes.NoteId, image_path: str | None = None)

      Set-up IO mask editor for editing existing notes
      Presupposes that active editor notetype is an image occlusion notetype
      Args:
          note_id: ID of note to edit.
          image_path: (Optional) Absolute path to image that should replace current
            image



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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


   .. py:method:: setTagsCollapsed(collapsed: bool) -> None


   .. py:method:: note_type() -> anki.models.NotetypeDict


.. py:class:: EditorWebView(parent: QWidget, editor: Editor)

   Bases: :py:obj:`aqt.webview.AnkiWebView`


   .. py:attribute:: editor


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


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


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


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


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


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


   .. py:method:: dragEnterEvent(evt: QDragEnterEvent | None) -> None


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


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


.. py:function:: fontMungeHack(font: str) -> str

.. py:function:: munge_html(txt: str, editor: Editor) -> str

.. py:function:: remove_null_bytes(txt: str, editor: Editor) -> str

.. py:function:: reverse_url_quoting(txt: str, editor: Editor) -> str

.. py:function:: set_cloze_button(editor: Editor) -> None

.. py:function:: set_image_occlusion_button(editor: Editor) -> None

