|
# Addon "Select_Buttons_Automatically_For_Cloze_Type_Cards.py" |
|
# Amendments by Stefan Zeh to the addon mentioned below. |
|
# 2016-12-07 |
|
# If you have the "type" option in a cloze deletion card, this addon will |
|
# automatically select the "good" button upon hitting <return> if your typedAnswer has been correct (otherwise "bad" is selected). |
|
# It ignores html markup (e.g. color) in the deposited correct answer so it works better than a previous addon (see below "Inspired by.."). |
|
# [I marked feminin answers in red and maskuline answers in blue (e.g. "une table" in red, "un copain" in blue) and the |
|
# addon below did not work any more. This one is ok as it only compares plain text to select the button (or "ease level").] |
|
|
|
# Inspired by |
|
# Select Buttons Automatically If Correct Answer, Wrong Answer or Nothing |
|
# https://ankiweb.net/shared/info/2074758752 |
|
|
|
from aqt import mw |
|
from aqt.reviewer import Reviewer |
|
from aqt.deckconf import DeckConf |
|
from aqt.forms import dconf |
|
from anki.hooks import addHook, wrap |
|
from anki.utils import stripHTML |
|
from PyQt4 import QtGui |
|
from threading import Timer |
|
import re |
|
|
|
def MydefaultEase(self): |
|
ReturnValue = 1; #return "bad" if nothing of below is true |
|
#Compare typedAnswer with deposited answer (typeCorrect). |
|
|
|
#Strip html (e.g. color) of typeCorrect in order to only compare plain text. Otherwise |
|
# a colored word inside the {{cloze:MasculineNounsInBlue}} would be always interpreted as "bad" |
|
if self.typeCorrect == None: #non cloze:type cards will have this variable empty |
|
ReturnValue = None #quit the function with None and omit stripHTML as it would issue error |
|
elif self.typedAnswer == stripHTML(self.mw.col.media.strip(self.typeCorrect)): |
|
if self.mw.col.sched.answerButtons(self.card) == 4: |
|
ReturnValue = 3 #good in case of 4 buttons (bad / hard / good / easy) |
|
elif self.mw.col.sched.answerButtons(self.card) == 3: |
|
ReturnValue = 2 #good in the standard case of 3 buttons (bad / good / easy) |
|
elif self.mw.col.sched.answerButtons(self.card) == 2: |
|
ReturnValue = 2 #good in the standard case of 2 choices (bad / good) |
|
else: |
|
ReturnValue = 1 #bad = repeat in <1 min |
|
return(ReturnValue) |
|
|
|
Reviewer._defaultEase = MydefaultEase |