mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
move leech detection into libanki
This commit is contained in:
parent
cf1b0e45f0
commit
a932f059e6
1 changed files with 5 additions and 26 deletions
|
@ -127,6 +127,7 @@ class AnkiQt(QMainWindow):
|
||||||
elif sys.platform.startswith("darwin"):
|
elif sys.platform.startswith("darwin"):
|
||||||
self.mainWin.noticeButton.setFixedWidth(20)
|
self.mainWin.noticeButton.setFixedWidth(20)
|
||||||
self.mainWin.noticeButton.setFixedHeight(20)
|
self.mainWin.noticeButton.setFixedHeight(20)
|
||||||
|
addHook("cardAnswered", self.onCardAnsweredHook)
|
||||||
|
|
||||||
def setNotice(self, str=""):
|
def setNotice(self, str=""):
|
||||||
if str:
|
if str:
|
||||||
|
@ -434,10 +435,6 @@ Please do not file a bug report with Anki.<br>""")
|
||||||
self.deck.s.expunge(self.currentCard)
|
self.deck.s.expunge(self.currentCard)
|
||||||
# answer
|
# answer
|
||||||
self.deck.answerCard(self.currentCard, quality)
|
self.deck.answerCard(self.currentCard, quality)
|
||||||
if self.isLeech():
|
|
||||||
self.handleLeech()
|
|
||||||
else:
|
|
||||||
self.setNotice()
|
|
||||||
self.lastScheduledTime = anki.utils.fmtTimeSpan(
|
self.lastScheduledTime = anki.utils.fmtTimeSpan(
|
||||||
self.currentCard.due - time.time())
|
self.currentCard.due - time.time())
|
||||||
self.lastQuality = quality
|
self.lastQuality = quality
|
||||||
|
@ -450,34 +447,16 @@ Please do not file a bug report with Anki.<br>""")
|
||||||
self.save()
|
self.save()
|
||||||
self.moveToState("getQuestion")
|
self.moveToState("getQuestion")
|
||||||
|
|
||||||
def isLeech(self):
|
def onCardAnsweredHook(self, card, isLeech):
|
||||||
no = self.currentCard.noCount
|
if not isLeech:
|
||||||
fmax = self.deck.getInt('leechFails')
|
self.setNotice()
|
||||||
if not fmax:
|
|
||||||
return
|
return
|
||||||
return (
|
|
||||||
# failed
|
|
||||||
not self.currentCard.successive and
|
|
||||||
# greater than fail threshold
|
|
||||||
no >= fmax and
|
|
||||||
# at least threshold/2 reps since last time
|
|
||||||
(fmax - no) % (max(fmax/2, 1)) == 0)
|
|
||||||
|
|
||||||
def handleLeech(self):
|
|
||||||
self.deck.refresh()
|
|
||||||
tags = self.currentCard.fact.tags
|
|
||||||
tags = addTags("Leech", tags)
|
|
||||||
self.currentCard.fact.tags = canonifyTags(tags)
|
|
||||||
self.currentCard.fact.setModified(textChanged=True)
|
|
||||||
self.deck.updateFactTags([self.currentCard.fact.id])
|
|
||||||
txt = (_("""\
|
txt = (_("""\
|
||||||
<b>%s</b>... is a <a href="http://ichi2.net/anki/wiki/Leeches">leech</a>.""")
|
<b>%s</b>... is a <a href="http://ichi2.net/anki/wiki/Leeches">leech</a>.""")
|
||||||
% stripHTML(stripSounds(self.currentCard.question)).\
|
% stripHTML(stripSounds(self.currentCard.question)).\
|
||||||
replace("\n", " ")[0:30])
|
replace("\n", " ")[0:30])
|
||||||
if self.deck.getBool('suspendLeeches'):
|
if isLeech:
|
||||||
self.deck.suspendCards([self.currentCard.id])
|
|
||||||
txt += _(" It has been suspended.")
|
txt += _(" It has been suspended.")
|
||||||
self.deck.refresh()
|
|
||||||
self.setNotice(txt)
|
self.setNotice(txt)
|
||||||
|
|
||||||
def startRefreshTimer(self):
|
def startRefreshTimer(self):
|
||||||
|
|
Loading…
Reference in a new issue