From e21efd4802c416cd49c64e3631295859247ddd4a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 5 Jan 2009 15:49:19 +0900 Subject: [PATCH] improve error checking for type in answer --- ankiqt/ui/view.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ankiqt/ui/view.py b/ankiqt/ui/view.py index 5adea5c21..d4dab5e5e 100644 --- a/ankiqt/ui/view.py +++ b/ankiqt/ui/view.py @@ -150,17 +150,22 @@ class View(object): cor = stripHTML(self.main.currentCard.answer) given = unicode(self.main.mainWin.typeAnswerField.text()) 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): try: yes = c == cor[i] except IndexError: yes = False if yes: - res.append("%s" % c) + res.append( + "%s" % (ok, c)) else: - res.append("%s" % c) - a += "
" + (_("You typed:
") + - "".join(res)) + "
" + res.append("%s" % (bad, c)) + a += "
" + "".join(res) + "" self.write(self.center('' + self.mungeQA(self.main.deck, a))) if self.state != self.oldState: