Skip to content

Instantly share code, notes, and snippets.

@balaam
Created December 16, 2017 10:41
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/5e03065b4ec0dcda60fab7aa1a45229f to your computer and use it in GitHub Desktop.
Save balaam/5e03065b4ec0dcda60fab7aa1a45229f to your computer and use it in GitHub Desktop.
My horrible hacking of the quick tag anki plugin
# Quick Tagging is an anki2 addon for quickly adding tags while reviewing
# Copyright 2012 Cayenne Boyer
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# CONFIGURATION OPTIONS
# Change this to change what keybinding opens the add tags dialog
tag_shortcut = 't'
quick_tags = {
# Add lines here to create shortcuts that add specified tags
# Examples (remove the leading #):
# Keybinding to add a named tag:
#'j': {'tags': 'hard'},
# Add multiple tags by seperating them with spaces:
#'k': {'tags': 'hard marked'},
# Bury by adding a True bury element:
#'l': {'tags': 'needs_elaboration', bury: True},
'g': {'tags': 'good_candidate', 'suspend': True},
'h': {'suspend': True},
'j': {'delete': True}
} # end quick_tags
# END CONFIGURATION OPTIONS
from aqt import mw
from aqt.utils import getTag, tooltip
from aqt.reviewer import Reviewer
# add space separated tags to a note
def addTags(note, tagString):
# add tags to card
tagList = mw.col.tags.split(tagString)
for tag in tagList:
note.addTag(tag)
note.flush()
# prompt for tags and add the results to a note
def promptAndAddTags(note):
# prompt for new tags
prompt = _("Enter tags to add:")
(tagString, r) = getTag(mw, mw.col, prompt)
# don't do anything if we didn't get anything
if not r:
return
# otherwise, add the given tags:
addTags(note, tagString)
tooltip('Added tag(s) "%s"' % tagString)
# replace _keyHandler in reviewer.py to add a keybinding
def newKeyHandler(self, evt):
key = unicode(evt.text())
note = mw.reviewer.card.note()
if key == tag_shortcut:
mw.checkpoint(_("Add Tags"))
promptAndAddTags(note)
elif key in quick_tags:
if 'bury' in quick_tags[key] and quick_tags[key]['bury']:
mw.checkpoint("Add Tags and Bury")
addTags(note, quick_tags[key]['tags'])
mw.col.sched.buryNote(note.id)
mw.reset()
tooltip('Added tag(s) "%s" and buried note'
% quick_tags[key]['tags'])
elif ('delete' in quick_tags[key] and quick_tags[key]['delete']):
mw.checkpoint("delete")
mw.col.remCards([mw.reviewer.card.id])
mw.reset()
tooltip('Deleted')
elif (not 'tags' in quick_tags[key]) and ('suspend' in quick_tags[key] and quick_tags[key]['suspend']):
mw.checkpoint("suspend")
mw.col.sched.suspendCards([mw.reviewer.card.id])
mw.reset()
tooltip('Suspended')
else:
mw.checkpoint(_("Add Tags"))
addTags(note, quick_tags[key]['tags'])
tip = 'Added tag(s) "%s"' % quick_tags[key]['tags']
if ('suspend' in quick_tags[key] and quick_tags[key]['suspend']):
mw.col.sched.suspendCards([mw.reviewer.card.id])
mw.reset()
tip = tip + " and suspended."
tooltip(tip)
else:
origKeyHandler(self, evt)
origKeyHandler = Reviewer._keyHandler
Reviewer._keyHandler = newKeyHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment