mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
handle card answering
This commit is contained in:
parent
8b537977a4
commit
b6844ba817
2 changed files with 96 additions and 106 deletions
20
aqt/main.py
20
aqt/main.py
|
@ -364,26 +364,6 @@ Please do not file a bug report with Anki.<br>""")
|
||||||
# return self.moveToState("saveEdit")
|
# return self.moveToState("saveEdit")
|
||||||
# evt.ignore()
|
# evt.ignore()
|
||||||
|
|
||||||
def cardAnswered(self, quality):
|
|
||||||
"Reschedule current card and move back to getQuestion state."
|
|
||||||
if self.state != "showAnswer":
|
|
||||||
return
|
|
||||||
# force refresh of card then remove from session as we update in pure sql
|
|
||||||
self.deck.db.refresh(self.currentCard)
|
|
||||||
self.deck.db.refresh(self.currentCard.fact)
|
|
||||||
self.deck.db.refresh(self.currentCard.cardModel)
|
|
||||||
self.deck.db.expunge(self.currentCard)
|
|
||||||
# answer
|
|
||||||
self.deck.answerCard(self.currentCard, quality)
|
|
||||||
self.lastQuality = quality
|
|
||||||
self.lastCard = self.currentCard
|
|
||||||
self.currentCard = None
|
|
||||||
if self.config['saveAfterAnswer']:
|
|
||||||
num = self.config['saveAfterAnswerNum']
|
|
||||||
if self.deck.repsToday % num == 0:
|
|
||||||
self.save()
|
|
||||||
self.moveToState("getQuestion")
|
|
||||||
|
|
||||||
def onCardAnsweredHook(self, cardId, isLeech):
|
def onCardAnsweredHook(self, cardId, isLeech):
|
||||||
if not isLeech:
|
if not isLeech:
|
||||||
self.setNotice()
|
self.setNotice()
|
||||||
|
|
182
aqt/reviewer.py
182
aqt/reviewer.py
|
@ -59,64 +59,6 @@ class Reviewer(object):
|
||||||
self.state != "getQuestion"))
|
self.state != "getQuestion"))
|
||||||
self.form.actionRepeatAudio.setEnabled(snd)
|
self.form.actionRepeatAudio.setEnabled(snd)
|
||||||
|
|
||||||
# HTML helpers
|
|
||||||
##########################################################################
|
|
||||||
|
|
||||||
_css = """
|
|
||||||
a.ansbut {
|
|
||||||
bottom: 1em;
|
|
||||||
height: 40px;
|
|
||||||
left: 50%;
|
|
||||||
margin-left: -125px;
|
|
||||||
position: fixed;
|
|
||||||
width: 250px;
|
|
||||||
font-size: 100%;
|
|
||||||
}
|
|
||||||
a.ansbut:focus {
|
|
||||||
background: #c7c7c7;
|
|
||||||
}
|
|
||||||
div.ansbut {
|
|
||||||
position: relative; top: 25%;
|
|
||||||
}
|
|
||||||
|
|
||||||
#easebuts {
|
|
||||||
bottom: 1em;
|
|
||||||
height: 55px;
|
|
||||||
left: 50%;
|
|
||||||
margin-left: -200px;
|
|
||||||
position: fixed;
|
|
||||||
width: 400px;
|
|
||||||
font-size: 100%;
|
|
||||||
visibility: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.easebut {
|
|
||||||
width: 60px;
|
|
||||||
font-size: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.time {
|
|
||||||
background: #eee;
|
|
||||||
padding: 5px;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div#filler {
|
|
||||||
height: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.q { margin-bottom: 1em; }
|
|
||||||
.a { margin-top: 1em; }
|
|
||||||
.inv { visibility: hidden; }
|
|
||||||
"""
|
|
||||||
|
|
||||||
def _styles(self):
|
|
||||||
css = self.mw.sharedCSS
|
|
||||||
css += self.card.model().css
|
|
||||||
css += self._css
|
|
||||||
css = runFilter("addStyles", css)
|
|
||||||
return css
|
|
||||||
|
|
||||||
# Showing the question (and preparing answer)
|
# Showing the question (and preparing answer)
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
@ -193,20 +135,29 @@ $(".ansbut").focus();
|
||||||
buf += self._answerButtons()
|
buf += self._answerButtons()
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
def _defaultEase(self):
|
||||||
|
if self.card.queue == 2:
|
||||||
|
return 3
|
||||||
|
else:
|
||||||
|
return 2
|
||||||
|
|
||||||
def _answerButtons(self):
|
def _answerButtons(self):
|
||||||
if self.card.queue == 2:
|
if self.card.queue == 2:
|
||||||
labels = (_("Again"), _("Hard"), _("Good"), _("Easy"))
|
labels = (_("Again"), _("Hard"), _("Good"), _("Easy"))
|
||||||
green = 2
|
|
||||||
else:
|
else:
|
||||||
labels = (_("Again"), _("Good"), _("Easy"))
|
labels = (_("Again"), _("Good"), _("Easy"))
|
||||||
green = 1
|
|
||||||
times = []
|
times = []
|
||||||
buttons = []
|
buttons = []
|
||||||
|
default = self._defaultEase()
|
||||||
def but(label, i):
|
def but(label, i):
|
||||||
|
if i == default:
|
||||||
|
extra=" id=defease"
|
||||||
|
else:
|
||||||
|
extra = ""
|
||||||
return '''
|
return '''
|
||||||
<a class="but easebut" href=ease%d>%s</a>''' % (i, label)
|
<a %s class="but easebut" href=ease%d>%s</a>''' % (extra, i, label)
|
||||||
for i in range(0, len(labels)):
|
for i in range(0, len(labels)):
|
||||||
times.append(self._buttonTime(i, green))
|
times.append(self._buttonTime(i, default-1))
|
||||||
buttons.append(but(labels[i], i+1))
|
buttons.append(but(labels[i], i+1))
|
||||||
buf = ("<table><tr><td align=center>" +
|
buf = ("<table><tr><td align=center>" +
|
||||||
"</td><td align=center>".join(times) + "</td></tr>")
|
"</td><td align=center>".join(times) + "</td></tr>")
|
||||||
|
@ -226,52 +177,111 @@ $(".ansbut").focus();
|
||||||
txt = '<span class=time>%s</span>' % txt
|
txt = '<span class=time>%s</span>' % txt
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
# Answering a card
|
||||||
|
############################################################
|
||||||
|
|
||||||
|
def _answerCard(self, ease):
|
||||||
|
"Reschedule card and show next."
|
||||||
|
self.mw.deck.sched.answerCard(self.card, ease)
|
||||||
|
print "fixme: save"
|
||||||
|
self._getCard()
|
||||||
|
|
||||||
# Handlers
|
# Handlers
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
def _keyHandler(self, evt):
|
def _keyHandler(self, evt):
|
||||||
if self.state == "question":
|
if self.state == "question":
|
||||||
|
show = False
|
||||||
if evt.key() in (Qt.Key_Enter,
|
if evt.key() in (Qt.Key_Enter,
|
||||||
Qt.Key_Return):
|
Qt.Key_Return):
|
||||||
evt.accept()
|
evt.accept()
|
||||||
return self.web.eval("showans();")
|
show = True
|
||||||
elif evt.key() == Qt.Key_Space and not self.typeAns():
|
elif evt.key() == Qt.Key_Space and not self.typeAns():
|
||||||
evt.accept()
|
evt.accept()
|
||||||
|
show = True
|
||||||
|
if show:
|
||||||
|
self._showAnswer()
|
||||||
return self.web.eval("showans();")
|
return self.web.eval("showans();")
|
||||||
elif self.state == "answer":
|
elif self.state == "answer":
|
||||||
# if evt.key() == Qt.Key_Space:
|
if evt.key() in (Qt.Key_Enter,
|
||||||
# key = str(self.defaultEaseButton())
|
Qt.Key_Return,
|
||||||
# else:
|
Qt.Key_Space):
|
||||||
# key = unicode(evt.text())
|
self._answerCard(self._defaultEase())
|
||||||
# if key and key >= "1" and key <= "4":
|
evt.accept()
|
||||||
# # user entered a quality setting
|
return
|
||||||
# num=int(key)
|
else:
|
||||||
# evt.accept()
|
key = unicode(evt.text())
|
||||||
# return getattr(self.form, "easeButton%d" %
|
if key and key >= "1" and key <= "4":
|
||||||
# num).animateClick()
|
key=int(key)
|
||||||
pass
|
if self.card.queue == 2 or key < 4:
|
||||||
|
evt.accept()
|
||||||
|
return self._answerCard(key)
|
||||||
evt.ignore()
|
evt.ignore()
|
||||||
|
|
||||||
def _linkHandler(self, url):
|
def _linkHandler(self, url):
|
||||||
print "link", url
|
print "link", url
|
||||||
if url == "ans":
|
if url == "ans":
|
||||||
self._showAnswer()
|
self._showAnswer()
|
||||||
|
elif url.startswith("ease"):
|
||||||
|
self._answerCard(int(url[4:]))
|
||||||
|
|
||||||
# Font properties & output
|
# CSS
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
def write(self, text):
|
_css = """
|
||||||
if type(text) != types.UnicodeType:
|
a.ansbut {
|
||||||
text = unicode(text, "utf-8")
|
bottom: 1em;
|
||||||
self.buffer += text
|
height: 40px;
|
||||||
|
left: 50%;
|
||||||
|
margin-left: -125px;
|
||||||
|
position: fixed;
|
||||||
|
width: 250px;
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
a.ansbut:focus {
|
||||||
|
background: #c7c7c7;
|
||||||
|
}
|
||||||
|
div.ansbut {
|
||||||
|
position: relative; top: 25%;
|
||||||
|
}
|
||||||
|
|
||||||
def center(self, str, height=40):
|
#easebuts {
|
||||||
if not self.main.config['splitQA']:
|
bottom: 1em;
|
||||||
return "<center>" + str + "</center>"
|
height: 55px;
|
||||||
return '''\
|
left: 50%;
|
||||||
<center><div style="display: table; height: %s%%; width:100%%; overflow: hidden;">\
|
margin-left: -200px;
|
||||||
<div style="display: table-cell; vertical-align: middle;">\
|
position: fixed;
|
||||||
<div style="">%s</div></div></div></center>''' % (height, str)
|
width: 400px;
|
||||||
|
font-size: 100%;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.easebut {
|
||||||
|
width: 60px;
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time {
|
||||||
|
background: #eee;
|
||||||
|
padding: 5px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div#filler {
|
||||||
|
height: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.q { margin-bottom: 1em; }
|
||||||
|
.a { margin-top: 1em; }
|
||||||
|
.inv { visibility: hidden; }
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _styles(self):
|
||||||
|
css = self.mw.sharedCSS
|
||||||
|
css += self.card.model().css
|
||||||
|
css += self._css
|
||||||
|
css = runFilter("addStyles", css)
|
||||||
|
return css
|
||||||
|
|
||||||
# Type in the answer
|
# Type in the answer
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
Loading…
Reference in a new issue