editor_did_init
That would be useful to add elements in the editor, such as in multi column editor
This commit is contained in:
parent
9dda5cf6ca
commit
f2f92fb0c3
@ -83,6 +83,7 @@ class Editor:
|
||||
self.setupWeb()
|
||||
self.setupShortcuts()
|
||||
self.setupTags()
|
||||
gui_hooks.editor_did_init(self)
|
||||
|
||||
# Initial setup
|
||||
############################################################
|
||||
|
@ -1028,6 +1028,30 @@ class _EditorDidFocusFieldHook:
|
||||
editor_did_focus_field = _EditorDidFocusFieldHook()
|
||||
|
||||
|
||||
class _EditorDidInitHook:
|
||||
_hooks: List[Callable[["aqt.editor.Editor"], None]] = []
|
||||
|
||||
def append(self, cb: Callable[["aqt.editor.Editor"], None]) -> None:
|
||||
"""(editor: aqt.editor.Editor)"""
|
||||
self._hooks.append(cb)
|
||||
|
||||
def remove(self, cb: Callable[["aqt.editor.Editor"], None]) -> None:
|
||||
if cb in self._hooks:
|
||||
self._hooks.remove(cb)
|
||||
|
||||
def __call__(self, editor: aqt.editor.Editor) -> None:
|
||||
for hook in self._hooks:
|
||||
try:
|
||||
hook(editor)
|
||||
except:
|
||||
# if the hook fails, remove it
|
||||
self._hooks.remove(hook)
|
||||
raise
|
||||
|
||||
|
||||
editor_did_init = _EditorDidInitHook()
|
||||
|
||||
|
||||
class _EditorDidInitButtonsHook:
|
||||
_hooks: List[Callable[[List, "aqt.editor.Editor"], None]] = []
|
||||
|
||||
|
@ -497,6 +497,7 @@ def emptyNewCard():
|
||||
name="editor_web_view_did_init",
|
||||
args=["editor_web_view: aqt.editor.EditorWebView"],
|
||||
),
|
||||
Hook(name="editor_did_init", args=["editor: aqt.editor.Editor"],),
|
||||
# Sound/video
|
||||
###################
|
||||
Hook(name="av_player_will_play", args=["tag: anki.sound.AVTag"]),
|
||||
|
Loading…
Reference in New Issue
Block a user