hook for initializing clayout
This commit is contained in:
parent
5c5860eabc
commit
80ba217772
@ -65,6 +65,7 @@ class CardLayout(QDialog):
|
|||||||
v1.addLayout(self.buttons)
|
v1.addLayout(self.buttons)
|
||||||
v1.setContentsMargins(12, 12, 12, 12)
|
v1.setContentsMargins(12, 12, 12, 12)
|
||||||
self.setLayout(v1)
|
self.setLayout(v1)
|
||||||
|
gui_hooks.card_layout_will_show(self)
|
||||||
self.redraw()
|
self.redraw()
|
||||||
restoreGeom(self, "CardLayout")
|
restoreGeom(self, "CardLayout")
|
||||||
self.setWindowModality(Qt.ApplicationModal)
|
self.setWindowModality(Qt.ApplicationModal)
|
||||||
|
@ -328,6 +328,33 @@ class _BrowserWillShowContextMenuHook:
|
|||||||
browser_will_show_context_menu = _BrowserWillShowContextMenuHook()
|
browser_will_show_context_menu = _BrowserWillShowContextMenuHook()
|
||||||
|
|
||||||
|
|
||||||
|
class _CardLayoutWillShowHook:
|
||||||
|
"""Allow to change the display of the card layout. After most values are
|
||||||
|
set and before the window is actually shown."""
|
||||||
|
|
||||||
|
_hooks: List[Callable[["aqt.clayout.CardLayout"], None]] = []
|
||||||
|
|
||||||
|
def append(self, cb: Callable[["aqt.clayout.CardLayout"], None]) -> None:
|
||||||
|
"""(clayout: aqt.clayout.CardLayout)"""
|
||||||
|
self._hooks.append(cb)
|
||||||
|
|
||||||
|
def remove(self, cb: Callable[["aqt.clayout.CardLayout"], None]) -> None:
|
||||||
|
if cb in self._hooks:
|
||||||
|
self._hooks.remove(cb)
|
||||||
|
|
||||||
|
def __call__(self, clayout: aqt.clayout.CardLayout) -> None:
|
||||||
|
for hook in self._hooks:
|
||||||
|
try:
|
||||||
|
hook(clayout)
|
||||||
|
except:
|
||||||
|
# if the hook fails, remove it
|
||||||
|
self._hooks.remove(hook)
|
||||||
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
card_layout_will_show = _CardLayoutWillShowHook()
|
||||||
|
|
||||||
|
|
||||||
class _CardWillShowFilter:
|
class _CardWillShowFilter:
|
||||||
"""Can modify card text before review/preview."""
|
"""Can modify card text before review/preview."""
|
||||||
|
|
||||||
|
@ -114,6 +114,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.",
|
||||||
),
|
),
|
||||||
|
# Card layout
|
||||||
|
###################
|
||||||
|
Hook(
|
||||||
|
name="card_layout_will_show",
|
||||||
|
args=["clayout: aqt.clayout.CardLayout"],
|
||||||
|
doc="""Allow to change the display of the card layout. After most values are
|
||||||
|
set and before the window is actually shown.""",
|
||||||
|
),
|
||||||
# Multiple windows
|
# Multiple windows
|
||||||
###################
|
###################
|
||||||
# reviewer, clayout and browser
|
# reviewer, clayout and browser
|
||||||
|
Loading…
Reference in New Issue
Block a user