Created
January 14, 2019 10:09
-
-
Save askoufis/d888076f39dd568f80f3dfe72becd090 to your computer and use it in GitHub Desktop.
Anki 2.1 tag toggler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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