mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
hook add_card_did_init
This commit is contained in:
parent
b5f0f459ce
commit
657fa9758b
3 changed files with 26 additions and 0 deletions
|
@ -46,6 +46,7 @@ class AddCards(QDialog):
|
|||
gui_hooks.state_did_reset.append(self.onReset)
|
||||
gui_hooks.current_note_type_did_change.append(self.onModelChange)
|
||||
addCloseShortcut(self)
|
||||
gui_hooks.add_cards_did_init(self)
|
||||
self.show()
|
||||
|
||||
def setupEditor(self) -> None:
|
||||
|
|
|
@ -50,6 +50,30 @@ class _AddCardsDidAddNoteHook:
|
|||
add_cards_did_add_note = _AddCardsDidAddNoteHook()
|
||||
|
||||
|
||||
class _AddCardsDidInitHook:
|
||||
_hooks: List[Callable[["aqt.addcards.AddCards"], None]] = []
|
||||
|
||||
def append(self, cb: Callable[["aqt.addcards.AddCards"], None]) -> None:
|
||||
"""(addcards: aqt.addcards.AddCards)"""
|
||||
self._hooks.append(cb)
|
||||
|
||||
def remove(self, cb: Callable[["aqt.addcards.AddCards"], None]) -> None:
|
||||
if cb in self._hooks:
|
||||
self._hooks.remove(cb)
|
||||
|
||||
def __call__(self, addcards: aqt.addcards.AddCards) -> None:
|
||||
for hook in self._hooks:
|
||||
try:
|
||||
hook(addcards)
|
||||
except:
|
||||
# if the hook fails, remove it
|
||||
self._hooks.remove(hook)
|
||||
raise
|
||||
|
||||
|
||||
add_cards_did_init = _AddCardsDidInitHook()
|
||||
|
||||
|
||||
class _AddCardsWillAddNoteFilter:
|
||||
"""Decides whether the note should be added to the collection or
|
||||
not. It is assumed to come from the addCards window.
|
||||
|
|
|
@ -432,6 +432,7 @@ def emptyNewCard():
|
|||
args=["addcards: aqt.addcards.AddCards", "menu: QMenu"],
|
||||
legacy_hook="AddCards.onHistory",
|
||||
),
|
||||
Hook(name="add_cards_did_init", args=["addcards: aqt.addcards.AddCards"],),
|
||||
Hook(
|
||||
name="add_cards_did_add_note",
|
||||
args=["note: anki.notes.Note"],
|
||||
|
|
Loading…
Reference in a new issue