mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
improve error checking for type in answer
This commit is contained in:
parent
84293c9d7a
commit
e21efd4802
1 changed files with 9 additions and 4 deletions
|
@ -150,17 +150,22 @@ class View(object):
|
||||||
cor = stripHTML(self.main.currentCard.answer)
|
cor = stripHTML(self.main.currentCard.answer)
|
||||||
given = unicode(self.main.mainWin.typeAnswerField.text())
|
given = unicode(self.main.mainWin.typeAnswerField.text())
|
||||||
res = []
|
res = []
|
||||||
|
if len(given) < len(cor):
|
||||||
|
given += " " * (len(cor) - len(given))
|
||||||
|
sz = self.main.currentCard.cardModel.answerFontSize
|
||||||
|
ok = "background: #00FF00; color: #000; font-size: %dpx" % sz
|
||||||
|
bad = "background: #FF0000; color: #000; font-size: %dpx;" % sz
|
||||||
for (i, c) in enumerate(given):
|
for (i, c) in enumerate(given):
|
||||||
try:
|
try:
|
||||||
yes = c == cor[i]
|
yes = c == cor[i]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
yes = False
|
yes = False
|
||||||
if yes:
|
if yes:
|
||||||
res.append("<span style='color: #007700'>%s</span>" % c)
|
res.append(
|
||||||
|
"<span style='%s'>%s</span>" % (ok, c))
|
||||||
else:
|
else:
|
||||||
res.append("<span style='color: #770000'>%s</span>" % c)
|
res.append("<span style='%s'>%s</span>" % (bad, c))
|
||||||
a += "<div>" + (_("You typed:<br><b>") +
|
a += "<br>" + "".join(res) + ""
|
||||||
"".join(res)) + "</b></div>"
|
|
||||||
self.write(self.center('<span id=answer />' +
|
self.write(self.center('<span id=answer />' +
|
||||||
self.mungeQA(self.main.deck, a)))
|
self.mungeQA(self.main.deck, a)))
|
||||||
if self.state != self.oldState:
|
if self.state != self.oldState:
|
||||||
|
|
Loading…
Reference in a new issue