本文整理汇总了Python中anki.hooks.wrap方法的典型用法代码示例。如果您正苦于以下问题:Python hooks.wrap方法的具体用法?Python hooks.wrap怎么用?Python hooks.wrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类anki.hooks
的用法示例。
在下文中一共展示了hooks.wrap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initializeLinks
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def initializeLinks():
Overview._linkHandler = wrap(Overview._linkHandler, heatmapLinkHandler, "around")
DeckBrowser._linkHandler = wrap(
DeckBrowser._linkHandler, heatmapLinkHandler, "around"
)
DeckStats._linkHandler = heatmapLinkHandler
try:
from aqt.gui_hooks import browser_will_search
browser_will_search.append(on_browser_will_search)
except (ImportError, ModuleNotFoundError):
from anki.find import Finder
Finder.findRevlogEntries = findRevlogEntries
Finder.__init__ = wrap(Finder.__init__, addFinders, "after")
示例2: _setupAddonMenus20
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def _setupAddonMenus20(self):
from anki.hooks import wrap
from aqt.addons import AddonManager
from ..gui.dialog_configeditor import ConfigEditor
from ..consts import ADDON
from ..platform import PATH_ADDONS
def onEdit(mgr, file_path, _old):
entry_point = os.path.join(
PATH_ADDONS, ADDON.NAME + ".py")
if not file_path == entry_point:
return _old(mgr, file_path)
if self.conf_action:
self.conf_action()
elif "local" in self._config:
ConfigEditor(self, self.mw)
else:
return _old(mgr, file_path)
AddonManager.onEdit = wrap(AddonManager.onEdit, onEdit, "around")
# Local storage
######################################################################
示例3: _ensureSaveBeforeConfigGUILoaded
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def _ensureSaveBeforeConfigGUILoaded(self) -> None:
"""ugly workaround, drop as soon as possible"""
if checkVersion(ANKI.VERSION, "2.1.17"):
self._mw.addonManager.setConfigAction(
self._namespace, self._saveBeforeConfigLoaded
)
return
from anki.hooks import wrap
from aqt.addons import AddonsDialog
def wrappedOnConfig(addonsDialog: AddonsDialog, *args, **kwargs):
"""Save before config editor is invoked"""
addon = addonsDialog.onlyOneSelected()
if not addon or addon != self._namespace:
return
self.save()
AddonsDialog.onConfig = wrap(AddonsDialog.onConfig, wrappedOnConfig, "before")
示例4: _setupAddonMenus20
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def _setupAddonMenus20(self):
from anki.hooks import wrap
from aqt.addons import AddonManager
from ..gui.dialog_configeditor import ConfigEditor
from ..consts import ADDON
from ..platform import DIRECTORY_ADDONS
def onEdit(mgr, file_path, _old):
entry_point = os.path.join(
DIRECTORY_ADDONS, ADDON.NAME + ".py")
if not file_path == entry_point:
return _old(mgr, file_path)
if self.conf_action:
self.conf_action()
elif "local" in self._config:
ConfigEditor(self, self.mw)
else:
return _old(mgr, file_path)
AddonManager.onEdit = wrap(AddonManager.onEdit, onEdit, "around")
# Local storage
######################################################################
示例5: onInsertCloze
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def onInsertCloze(self, _old):
"""Handles cloze-wraps when the add-on model is active"""
if not checkModel(self.note.model(), fields=False, notify=False):
return _old(self)
# find the highest existing cloze
highest = 0
for name, val in self.note.items():
m = re.findall("\[\[oc(\d+)::", val)
if m:
highest = max(highest, sorted([int(x) for x in m])[-1])
# reuse last?
if not self.mw.app.keyboardModifiers() & Qt.AltModifier:
highest += 1
# must start at 1
highest = max(1, highest)
self.web.eval("wrap('[[oc%d::', ']]');" % highest)
示例6: initializeEditor
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def initializeEditor():
# Editor widget
Editor.onCloze = wrap(Editor.onCloze, onInsertCloze, "around")
Editor.onOlClozeButton = onOlClozeButton
Editor.onOlOptionsButton = onOlOptionsButton
Editor.onInsertMultipleClozes = onInsertMultipleClozes
Editor.onRemoveClozes = onRemoveClozes
if ANKI20:
addHook("setupEditorButtons", onSetupEditorButtons20)
else:
addHook("setupEditorButtons", onSetupEditorButtons21)
# AddCard / EditCurrent windows
AddCards.addNote = wrap(AddCards.addNote, onAddNote, "around")
if ANKI20:
AddCards.addCards = wrap(AddCards.addCards, onAddCards, "around")
EditCurrent.onSave = wrap(EditCurrent.onSave, onEditCurrent, "around")
else:
# always use the methods that are fired on editor save:
AddCards._addCards = wrap(AddCards._addCards, onAddCards, "around")
EditCurrent._saveAndClose = wrap(EditCurrent._saveAndClose,
onEditCurrent, "around")
示例7: load
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def load():
ruby.install()
chinese.install()
addHook('profileLoaded', load_menu)
addHook('profileLoaded', add_models)
addHook('loadNote', append_tone_styling)
addHook('unloadProfile', config.save)
addHook('unloadProfile', dictionary.conn.close)
addHook('unloadProfile', unload_menu)
CollectionStats.todayStats = wrap(
CollectionStats.todayStats, todayStats, 'around'
)
EditManager()
示例8: patch_config
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def patch_config():
from aqt.clayout import CardLayout
from .config import add_maobi_button
CardLayout.setupButtons = wrap(CardLayout.setupButtons, add_maobi_button)
示例9: initializeViews
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def initializeViews():
try:
from aqt.gui_hooks import (
deck_browser_will_render_content,
overview_will_render_content,
)
deck_browser_will_render_content.append(on_deckbrowser_will_render_content)
overview_will_render_content.append(on_overview_will_render_content)
except (ImportError, ModuleNotFoundError):
Overview._body = ov_body
Overview._renderPage = overviewRenderPage
DeckBrowser._renderStats = wrap(
DeckBrowser._renderStats, deckbrowserRenderStats, "around"
)
# TODO: Submit Anki PR to add hook to CollectionStats.report
CollectionStats.dueGraph = wrap(
CollectionStats.dueGraph, collectionStatsDueGraph, "around"
)
DeckStats.__init__ = wrap(DeckStats.__init__, deckStatsInit21, "after")
DeckStats.reject = wrap(DeckStats.reject, deckStatsReject)
# Initially set up hotkey:
# TODO: Migrate to config.json storage, so that profile hook is not required
try:
from aqt.gui_hooks import profile_did_open
profile_did_open.append(initializeHotkey)
except (ImportError, ModuleNotFoundError):
addHook("profileLoaded", initializeHotkey)
# Update hotkey on config save:
addHook("config_saved_heatmap", initializeHotkey)
示例10: customize_addcards
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def customize_addcards():
AddCards.setupButtons = wrap(
AddCards.setupButtons, add_query_button, "before")
示例11: profileLoaded
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def profileLoaded():
"""Support for Advanced Previewer"""
try:
from advanced_previewer.previewer import Previewer
except ImportError:
return
Previewer.linkHandler = wrap(
Previewer.linkHandler, linkHandler, "around")
addHook("previewerMungeQA", linkInserter)
示例12: onProfileLoaded
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def onProfileLoaded():
"""
Apply modifications to Browser and Previewer
Needs to be run after all other add-ons have been loaded
"""
Browser.onTagMove = onTagMove
Browser.switchToSidebarItem = switchToSidebarItem
Browser.setFilter = wrap(Browser.setFilter, onSetFilter, "around")
Previewer.setupHotkeys = wrap(Previewer.setupHotkeys, onSetupHotkeys, "after")
示例13: profileLoaded
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def profileLoaded():
# add menu entry
mw.addonManager.rebuildAddonsMenu = wrap(mw.addonManager.rebuildAddonsMenu,
siblingMenu)
mw.addonManager.rebuildAddonsMenu()
# add scheduler
anki.sched.Scheduler._adjRevIvl = wrap(anki.sched.Scheduler._adjRevIvl,
siblingIvl, "around")
# --- Hooks: ---
示例14: pasteWithoutLinebreaks
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def pasteWithoutLinebreaks(self):
"""Remove linebreaks from clipboard and paste"""
mime = self.web.mungeClip(mode=QClipboard.Clipboard)
html = mime.html()
text = mime.text()
if not(text or html):
return
if html:
content = re.sub(re_lb_open, " ", html)
content = re.sub(re_lb_close, "", content)
else:
if PRESERVE_PARAGRAPHS:
# remove EOL hyphens:
content = re.sub(r"-\n(?!\n)", "", text)
# skip ends of sentences:
content = re.sub(r"(?<!\.|\!|\:)\n(?!\n)", " ", content)
# strip extraneous linebreaks while rejoining with <br> tags
content = "<br />".join(i.strip() for i in content.split("\n"))
else:
content = content.replace("\n", " ")
self.web.eval("""
var pasteHTML = function(html) {
setFormat("inserthtml", html);
};
var filterHTML = function(html) {
// wrap it in <top> as we aren't allowed to change top level elements
var top = $.parseHTML("<ankitop>" + html + "</ankitop>")[0];
filterNode(top);
var outHtml = top.innerHTML;
// get rid of nbsp
outHtml = outHtml.replace(/ /ig, " ");
return outHtml;
};
pasteHTML(%s);
""" % json.dumps(content))
if TOOLTIP:
tooltip("Pasting without linebreaks", period=500)
示例15: initializeReviewer
# 需要导入模块: from anki import hooks [as 别名]
# 或者: from anki.hooks import wrap [as 别名]
def initializeReviewer():
if ANKI20:
Reviewer._keyHandler = wrap(
Reviewer._keyHandler, newKeyHandler20, "before")
else:
Reviewer._shortcutKeys = wrap(Reviewer._shortcutKeys, onShortcutKeys21,
"around")