Skip to content

Instantly share code, notes, and snippets.

@balaam
Created August 18, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balaam/d7fb7344ea2eebce21e25772ce3a58c9 to your computer and use it in GitHub Desktop.
Save balaam/d7fb7344ea2eebce21e25772ce3a58c9 to your computer and use it in GitHub Desktop.
# import the main window object (mw) from aqt
# from the anki tutorial: https://apps.ankiweb.net/docs/addons.html
from aqt import mw
# import the "show info" tool from utils.py
from aqt.utils import showInfo, getTag, tooltip
# import all of the Qt GUI library
from aqt.qt import *
from aqt.reviewer import Reviewer
originalShortcutkeys = Reviewer._shortcutKeys
quick_tags = {
'g': {'tags': 'good_candidate', 'suspend': True},
'h': {'suspend': True},
'j': {'delete': True}
}
def addTags(note, tagString):
tagList = mw.col.tags.split(tagString)
for tag in tagList:
note.addTag(tag)
note.flush()
def doTagAction(tagDef):
mw.checkpoint(("Add Tags"))
note = mw.reviewer.card.note()
msg = "Card processed."
if 'tags' in tagDef:
addTags(note, tagDef['tags'])
msg = msg + " Tagged."
if 'suspend' in tagDef and tagDef['suspend']:
mw.col.sched.suspendCards([mw.reviewer.card.id])
mw.reset()
msg = msg + " Suspended."
if 'delete' in tagDef and tagDef['delete']:
mw.col.remCards([mw.reviewer.card.id])
mw.reset()
msg = msg + " Deleted."
tooltip(msg)
def newShortcutHandler(self):
originalList = originalShortcutkeys(self);
originalList.append(("g", lambda: doTagAction({'tags': 'good_candidate', 'suspend': True})))
originalList.append(("h", lambda: doTagAction({'suspend': True})))
originalList.append(("j", lambda: doTagAction({'delete': True})))
return originalList
Reviewer._shortcutKeys = newShortcutHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment