aqt.editor

Contents

aqt.editor#

Attributes#

Classes#

EditorMode

Create a collection of name/value pairs.

EditorState

Current input state of the editing UI.

Editor

The screen that embeds an editing widget should listen for changes via

EditorWebView

Functions#

fontMungeHack(→ str)

munge_html(→ str)

remove_null_bytes(→ str)

reverse_url_quoting(→ str)

set_cloze_button(→ None)

set_image_occlusion_button(→ None)

Module Contents#

aqt.editor.pics = ('jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG', 'gif', 'GIF', 'svg', 'SVG', 'webp', 'WEBP', 'ico',...#
aqt.editor.audio = ('3gp', '3GP', 'aac', 'AAC', 'avi', 'AVI', 'flac', 'FLAC', 'flv', 'FLV', 'm4a', 'M4A', 'mkv',...#
class aqt.editor.EditorMode(*args, **kwds)#

Bases: 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.

ADD_CARDS = 0#
EDIT_CURRENT = 1#
BROWSER = 2#
class aqt.editor.EditorState(*args, **kwds)#

Bases: enum.Enum

Current input state of the editing UI.

INITIAL = -1#
FIELDS = 0#
IO_PICKER = 1#
IO_MASKS = 2#
IO_FIELDS = 3#
class aqt.editor.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.

mw#
widget#
parentWindow#
note: anki.notes.Note | None = None#
addMode#
editorMode#
currentField: int | None = None#
last_field_index: int | None = None#
orig_note_id: anki.notes.NoteId | None = None#
card: anki.cards.Card | None = None#
state: EditorState#
last_io_image_path: str | None = None#
setupOuter() None#
add_webview() None#
setupWeb() None#
resourceToData(path: str) str#

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

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

setupShortcuts() None#
setupColourPalette() None#
onFields() None#
onCardLayout() None#
onBridgeCmd(cmd: str) Any#
mungeHTML(txt: str) str#
signal_state_change(new_state: EditorState, old_state: EditorState) None#
set_note(note: anki.notes.Note | None, hide: bool = True, focusTo: int | None = None) None#

Make NOTE the current note.

loadNoteKeepingFocus() None#
loadNote(focusTo: int | None = None) None#
fonts() list[tuple[str, int, bool]]#
call_after_note_saved(callback: collections.abc.Callable, keepFocus: bool = False) None#

Save unsaved edits then call callback().

saveNow#
checkValid#
showDupes() None#
fieldsAreBlank(previousNote: anki.notes.Note | None = None) bool#
cleanup() None#
setNote#
setupTags() None#
updateTags() None#
on_tag_focus_lost() None#
blur_tags_if_focused() None#
hideCompleters() None#
onFocusTags() None#
saveAddModeVars() None#
saveTags#
onAddMedia() None#

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

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.

resolve_media(path: str) None#

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

onRecSound() None#
urlToFile(url: str, allowed_suffixes: Iterable[str] = pics + audio) str | None#
isURL(s: str) bool#
inlinedImageToFilename(txt: str) str#
removeTags = ['script', 'iframe', 'object', 'style']#
doPaste(html: str, internal: bool, extended: bool = False) None#
doDrop(html: str, internal: bool, extended: bool, cursor_pos: QPoint) None#
onPaste() None#
onCutOrCopy() None#
current_notetype_is_image_occlusion() bool#
setup_mask_editor(image_path: str) None#
select_image_and_occlude() None#

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

extract_img_path_from_html(html: str) str | None#
select_image_from_clipboard_and_occlude() None#

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

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.

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

reset_image_occlusion() None#
update_occlusions_field() None#
onHtmlEdit() None#
toggleBold() None#
toggleItalic() None#
toggleUnderline() None#
toggleSuper() None#
toggleSub() None#
removeFormat() None#
onCloze() None#
setupForegroundButton() None#
onForeground() None#
onChangeCol() None#
onColourChanged() None#
onAdvanced() None#
insertLatex() None#
insertLatexEqn() None#
insertLatexMathEnv() None#
insertMathjaxInline() None#
insertMathjaxBlock() None#
insertMathjaxChemistry() None#
toggleMathjax() None#
toggleShrinkImages() None#
toggleCloseHTMLTags() None#
setTagsCollapsed(collapsed: bool) None#
note_type() anki.models.NotetypeDict#
class aqt.editor.EditorWebView(parent: QWidget, editor: Editor)#

Bases: aqt.webview.AnkiWebView

editor#
user_cut_or_copied() None#
onCut() None#
onCopy() None#
on_copy_image() None#
onPaste() None#
onMiddleClickPaste() None#
dragEnterEvent(evt: QDragEnterEvent | None) None#
dropEvent(evt: QDropEvent | None) None#
contextMenuEvent(evt: QContextMenuEvent | None) None#
aqt.editor.fontMungeHack(font: str) str#
aqt.editor.munge_html(txt: str, editor: Editor) str#
aqt.editor.remove_null_bytes(txt: str, editor: Editor) str#
aqt.editor.reverse_url_quoting(txt: str, editor: Editor) str#
aqt.editor.set_cloze_button(editor: Editor) None#
aqt.editor.set_image_occlusion_button(editor: Editor) None#