add leech detection, message window on sync failure

This commit is contained in:
Damien Elmes 2009-06-16 02:06:06 +09:00
parent d3fb52199a
commit 32639bcbd5
3 changed files with 1495 additions and 265 deletions

View file

@ -15,7 +15,7 @@ from PyQt4.QtGui import *
from anki import DeckStorage from anki import DeckStorage
from anki.errors import * from anki.errors import *
from anki.sound import hasSound, playFromText, clearAudioQueue from anki.sound import hasSound, playFromText, clearAudioQueue
from anki.utils import addTags, deleteTags, parseTags, canonifyTags from anki.utils import addTags, deleteTags, parseTags, canonifyTags, stripHTML
from anki.media import rebuildMediaDir from anki.media import rebuildMediaDir
from anki.db import OperationalError, SessionHelper from anki.db import OperationalError, SessionHelper
from anki.stdmodels import BasicModel from anki.stdmodels import BasicModel
@ -115,6 +115,14 @@ class AnkiQt(QMainWindow):
self.connect(self.mainWin.reviewEarlyButton, self.connect(self.mainWin.reviewEarlyButton,
SIGNAL("clicked()"), SIGNAL("clicked()"),
self.onReviewEarly) self.onReviewEarly)
# notices
self.mainWin.noticeFrame.setShown(False)
self.connect(self.mainWin.noticeButton, SIGNAL("clicked()"),
lambda: self.mainWin.noticeFrame.setShown(False))
def setNotice(self, str):
self.mainWin.noticeLabel.setText(str)
self.mainWin.noticeFrame.setShown(True)
def setupViews(self): def setupViews(self):
self.bodyView = ui.view.View(self, self.mainWin.mainText, self.bodyView = ui.view.View(self, self.mainWin.mainText,
@ -414,6 +422,8 @@ 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.currentCard.reps > 15 and self.currentCard.successive == 0:
self.handleLeech()
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
@ -426,6 +436,21 @@ Please do not file a bug report with Anki.<br>""")
self.save() self.save()
self.moveToState("getQuestion") self.moveToState("getQuestion")
def handleLeech(self):
self.deck.refresh()
tags = self.currentCard.fact.tags
tags = addTags("Suspended", tags)
tags = addTags("Leech", tags)
self.currentCard.fact.tags = canonifyTags(tags)
self.currentCard.fact.setModified(textChanged=True)
self.deck.updateFactTags([self.currentCard.fact.id])
for card in self.currentCard.fact.cards:
self.deck.updatePriority(card)
self.deck.refresh()
self.setNotice(_("""\
%s... was a <a href="http://ichi2.net/anki/wiki/Leeches">leech</a>.""") %
stripHTML(self.currentCard.question)[0:30])
def startRefreshTimer(self): def startRefreshTimer(self):
"Update the screen once a minute until next card is displayed." "Update the screen once a minute until next card is displayed."
if getattr(self, 'refreshTimer', None): if getattr(self, 'refreshTimer', None):
@ -2079,15 +2104,10 @@ it to your friends.
setCurrentIndex(1) setCurrentIndex(1)
def noSyncResponse(self): def noSyncResponse(self):
msg = _("""\ msg = _("Sync Failed. Please check your internet connection.")
<h1>Sync Failed</h1>
Couldn't contact Anki Online. Please check your internet connection.""")
if self.config['proxyHost']: if self.config['proxyHost']:
msg += _(" Also check your proxy settings.") msg += _(" (and proxy settings)")
if self.config['syncInMsgBox']: self.setNotice(msg)
ui.utils.showWarning(msg)
else:
self.showToolTip(msg)
def openSyncProgress(self): def openSyncProgress(self):
self.syncProgressDialog = QProgressDialog(_("Syncing Media..."), self.syncProgressDialog = QProgressDialog(_("Syncing Media..."),

View file

@ -304,4 +304,3 @@ You should aim to answer each question within<br>
def setTimer(self, txt): def setTimer(self, txt):
self.timer.setText("<qt>" + txt + "&nbsp;") self.timer.setText("<qt>" + txt + "&nbsp;")

File diff suppressed because it is too large Load diff