mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Merge pull request #682 from glutanimate/add-top-toolbar-did-redraw-hook
Add top_toolbar_did_redraw hook
This commit is contained in:
commit
c34a99871b
3 changed files with 35 additions and 0 deletions
|
@ -2437,6 +2437,35 @@ class _TopToolbarDidInitLinksHook:
|
||||||
top_toolbar_did_init_links = _TopToolbarDidInitLinksHook()
|
top_toolbar_did_init_links = _TopToolbarDidInitLinksHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _TopToolbarDidRedrawHook:
|
||||||
|
"""Executed when the top toolbar is redrawn"""
|
||||||
|
|
||||||
|
_hooks: List[Callable[["aqt.toolbar.Toolbar"], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[["aqt.toolbar.Toolbar"], None]) -> None:
|
||||||
|
"""(top_toolbar: aqt.toolbar.Toolbar)"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[["aqt.toolbar.Toolbar"], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def count(self) -> int:
|
||||||
|
return len(self._hooks)
|
||||||
|
|
||||||
|
def __call__(self, top_toolbar: aqt.toolbar.Toolbar) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook(top_toolbar)
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
top_toolbar_did_redraw = _TopToolbarDidRedrawHook()
|
||||||
|
|
||||||
|
|
||||||
class _UndoStateDidChangeHook:
|
class _UndoStateDidChangeHook:
|
||||||
_hooks: List[Callable[[bool], None]] = []
|
_hooks: List[Callable[[bool], None]] = []
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Toolbar:
|
||||||
def redraw(self) -> None:
|
def redraw(self) -> None:
|
||||||
self.set_sync_active(self.mw.media_syncer.is_syncing())
|
self.set_sync_active(self.mw.media_syncer.is_syncing())
|
||||||
self.update_sync_status()
|
self.update_sync_status()
|
||||||
|
gui_hooks.top_toolbar_did_redraw(self)
|
||||||
|
|
||||||
# Available links
|
# Available links
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -451,6 +451,11 @@ hooks = [
|
||||||
links.append(my_link)
|
links.append(my_link)
|
||||||
""",
|
""",
|
||||||
),
|
),
|
||||||
|
Hook(
|
||||||
|
name="top_toolbar_did_redraw",
|
||||||
|
args=["top_toolbar: aqt.toolbar.Toolbar"],
|
||||||
|
doc="""Executed when the top toolbar is redrawn""",
|
||||||
|
),
|
||||||
Hook(
|
Hook(
|
||||||
name="media_sync_did_progress", args=["entry: aqt.mediasync.LogEntryWithTime"],
|
name="media_sync_did_progress", args=["entry: aqt.mediasync.LogEntryWithTime"],
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue