Anki/qt/aqt/operations/note.py
Damien Elmes f6ec5928ae allow ops to pass metadata into perform_op()
Instances can pass handled_by=self to more easily ignore events they
initiate.

Fixes ugly refresh when expanding/collapsing decks, but we're still
refreshing the card/notes area unnecessarily in that case.
2021-04-05 13:43:09 +10:00

38 lines
1,019 B
Python

# Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from __future__ import annotations
from typing import Optional, Sequence
from anki.decks import DeckId
from anki.notes import Note, NoteId
from aqt import AnkiQt
from aqt.main import PerformOpOptionalSuccessCallback
from aqt.operations import OpMeta
def add_note(
*,
mw: AnkiQt,
note: Note,
target_deck_id: DeckId,
success: PerformOpOptionalSuccessCallback = None,
) -> None:
mw.perform_op(lambda: mw.col.add_note(note, target_deck_id), success=success)
def update_note(*, mw: AnkiQt, note: Note, handled_by: Optional[object]) -> None:
mw.perform_op(
lambda: mw.col.update_note(note),
meta=OpMeta(handled_by=handled_by),
)
def remove_notes(
*,
mw: AnkiQt,
note_ids: Sequence[NoteId],
success: PerformOpOptionalSuccessCallback = None,
) -> None:
mw.perform_op(lambda: mw.col.remove_notes(note_ids), success=success)