Skip to content

Instantly share code, notes, and snippets.

@askoufis
Created January 14, 2019 10:09
Show Gist options
  • Save askoufis/d888076f39dd568f80f3dfe72becd090 to your computer and use it in GitHub Desktop.
Save askoufis/d888076f39dd568f80f3dfe72becd090 to your computer and use it in GitHub Desktop.
Anki 2.1 tag toggler
from aqt import mw
from aqt.reviewer import Reviewer
class TagTogglerReviewer(Reviewer):
# Keep Python from complaining that self.shortcuts doesn't exist.
shortcuts = []
def __init__(self, mw):
super().__init__(mw)
# Reviewer's default shortcuts, plus our own
self.shortcuts = super()._shortcutKeys() + [
("h", lambda: self._toggleTag("blah")),
]
def _shortcutKeys(self):
"""
Return our shortcuts rather than the default ones.
"""
return self.shortcuts
def _toggleTag(self, tag):
"""
Our own custom tag toggler
"""
f = self.card.note()
if f.hasTag(tag):
f.delTag(tag)
else:
f.addTag(tag)
f.flush()
# Use our modified Reviewer rather than the default one.
mw.reviewer = TagTogglerReviewer(mw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment