Merge pull request #506 from Arthur-Milchior/editor_web_view_did_init

Hook editor_web_view_did_init
This commit is contained in:
Damien Elmes 2020-03-17 20:53:20 +10:00 committed by GitHub
commit acd3eb9058
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View file

@ -954,6 +954,7 @@ class EditorWebView(AnkiWebView):
self._markInternal = False
clip = self.editor.mw.app.clipboard()
clip.dataChanged.connect(self._onClipboardChange)
gui_hooks.editor_web_view_did_init(self)
def _onClipboardChange(self):
if self._markInternal:

View file

@ -1036,6 +1036,30 @@ class _EditorDidUpdateTagsHook:
editor_did_update_tags = _EditorDidUpdateTagsHook()
class _EditorWebViewDidInitHook:
_hooks: List[Callable[["aqt.editor.EditorWebView"], None]] = []
def append(self, cb: Callable[["aqt.editor.EditorWebView"], None]) -> None:
"""(editor_web_view: aqt.editor.EditorWebView)"""
self._hooks.append(cb)
def remove(self, cb: Callable[["aqt.editor.EditorWebView"], None]) -> None:
if cb in self._hooks:
self._hooks.remove(cb)
def __call__(self, editor_web_view: aqt.editor.EditorWebView) -> None:
for hook in self._hooks:
try:
hook(editor_web_view)
except:
# if the hook fails, remove it
self._hooks.remove(hook)
raise
editor_web_view_did_init = _EditorWebViewDidInitHook()
class _EditorWillShowContextMenuHook:
_hooks: List[Callable[["aqt.editor.EditorWebView", QMenu], None]] = []

View file

@ -460,6 +460,10 @@ def emptyNewCard():
return_type="str",
legacy_hook="mungeEditingFontName",
),
Hook(
name="editor_web_view_did_init",
args=["editor_web_view: aqt.editor.EditorWebView"],
),
# Sound/video
###################
Hook(name="av_player_will_play", args=["tag: anki.sound.AVTag"]),