editor_did_init

That would be useful to add elements in the editor, such as in multi
column editor
This commit is contained in:
Arthur Milchior 2020-03-22 17:15:47 +01:00
parent 9dda5cf6ca
commit f2f92fb0c3
3 changed files with 26 additions and 0 deletions

View File

@ -83,6 +83,7 @@ class Editor:
self.setupWeb()
self.setupShortcuts()
self.setupTags()
gui_hooks.editor_did_init(self)
# Initial setup
############################################################

View File

@ -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]] = []

View File

@ -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"]),