mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
hook debug_will_show_hook
This commit is contained in:
parent
4290bc81eb
commit
3319b114de
3 changed files with 38 additions and 1 deletions
|
@ -13,7 +13,7 @@ import anki
|
||||||
import aqt
|
import aqt
|
||||||
from anki.cards import Card
|
from anki.cards import Card
|
||||||
from anki.hooks import runFilter, runHook
|
from anki.hooks import runFilter, runHook
|
||||||
from aqt.qt import QMenu
|
from aqt.qt import QDialog, QMenu
|
||||||
|
|
||||||
# New hook/filter handling
|
# New hook/filter handling
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
@ -520,6 +520,33 @@ class _CurrentNoteTypeDidChangeHook:
|
||||||
current_note_type_did_change = _CurrentNoteTypeDidChangeHook()
|
current_note_type_did_change = _CurrentNoteTypeDidChangeHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _DebugConsoleWillShowHook:
|
||||||
|
"""Allows editing the debug window. E.g. setting a default code, or
|
||||||
|
previous code."""
|
||||||
|
|
||||||
|
_hooks: List[Callable[[QDialog], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[[QDialog], None]) -> None:
|
||||||
|
"""(debug_window: QDialog)"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[[QDialog], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def __call__(self, debug_window: QDialog) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook(debug_window)
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
debug_console_will_show = _DebugConsoleWillShowHook()
|
||||||
|
|
||||||
|
|
||||||
class _DeckBrowserDidRenderHook:
|
class _DeckBrowserDidRenderHook:
|
||||||
"""Allow to update the deck browser window. E.g. change its title."""
|
"""Allow to update the deck browser window. E.g. change its title."""
|
||||||
|
|
||||||
|
|
|
@ -1342,6 +1342,7 @@ will be lost. Continue?"""
|
||||||
s.activated.connect(frm.log.clear)
|
s.activated.connect(frm.log.clear)
|
||||||
s = self.debugDiagShort = QShortcut(QKeySequence("ctrl+shift+l"), d)
|
s = self.debugDiagShort = QShortcut(QKeySequence("ctrl+shift+l"), d)
|
||||||
s.activated.connect(frm.text.clear)
|
s.activated.connect(frm.text.clear)
|
||||||
|
gui_hooks.debug_console_will_show(d)
|
||||||
d.show()
|
d.show()
|
||||||
|
|
||||||
def _captureOutput(self, on):
|
def _captureOutput(self, on):
|
||||||
|
|
|
@ -11,6 +11,7 @@ import sys
|
||||||
pylib = os.path.join(os.path.dirname(__file__), "..", "..", "pylib")
|
pylib = os.path.join(os.path.dirname(__file__), "..", "..", "pylib")
|
||||||
sys.path.append(pylib)
|
sys.path.append(pylib)
|
||||||
|
|
||||||
|
|
||||||
from tools.hookslib import Hook, update_file
|
from tools.hookslib import Hook, update_file
|
||||||
|
|
||||||
# Hook list
|
# Hook list
|
||||||
|
@ -89,6 +90,14 @@ hooks = [
|
||||||
legacy_hook="reviewCleanup",
|
legacy_hook="reviewCleanup",
|
||||||
doc="Called before Anki transitions from the review screen to another screen.",
|
doc="Called before Anki transitions from the review screen to another screen.",
|
||||||
),
|
),
|
||||||
|
# Debug
|
||||||
|
###################
|
||||||
|
Hook(
|
||||||
|
name="debug_console_will_show",
|
||||||
|
args=["debug_window: QDialog"],
|
||||||
|
doc="""Allows editing the debug window. E.g. setting a default code, or
|
||||||
|
previous code.""",
|
||||||
|
),
|
||||||
# Card layout
|
# Card layout
|
||||||
###################
|
###################
|
||||||
Hook(
|
Hook(
|
||||||
|
|
Loading…
Reference in a new issue