add ability to customize leech & suspending per deck

This commit is contained in:
Damien Elmes 2009-06-25 05:24:28 +09:00
parent 33b3c65ad8
commit 0797b4e772
4 changed files with 58 additions and 12 deletions

View file

@ -72,6 +72,9 @@ class DeckProperties(QDialog):
# hour shift
self.dialog.timeOffset.setText(str(
(self.d.utcOffset - time.timezone) / 60.0 / 60.0))
# leeches
self.dialog.suspendLeeches.setChecked(self.d.getBool("suspendLeeches"))
self.dialog.leechFails.setValue(self.d.getInt("leechFails"))
def drawSourcesTable(self):
self.dialog.sourcesTable.clear()
@ -240,6 +243,13 @@ class DeckProperties(QDialog):
self.updateField(self.d, 'failedCardMax', v)
except ValueError:
pass
try:
self.d.setVar("suspendLeeches",
not not self.dialog.suspendLeeches.isChecked())
self.d.setVar("leechFails",
int(self.dialog.leechFails.value()))
except ValueError:
pass
# hour shift
try:
self.updateField(self.d, 'utcOffset',

View file

@ -14,7 +14,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import *
from anki import DeckStorage
from anki.errors import *
from anki.sound import hasSound, playFromText, clearAudioQueue
from anki.sound import hasSound, playFromText, clearAudioQueue, stripSounds
from anki.utils import addTags, deleteTags, parseTags, canonifyTags, stripHTML
from anki.media import rebuildMediaDir, downloadMissing
from anki.db import OperationalError, SessionHelper
@ -119,6 +119,7 @@ class AnkiQt(QMainWindow):
SIGNAL("clicked()"),
self.onClose)
# notices
self.noticeShown = 0
self.mainWin.noticeFrame.setShown(False)
self.connect(self.mainWin.noticeButton, SIGNAL("clicked()"),
lambda: self.mainWin.noticeFrame.setShown(False))
@ -129,9 +130,14 @@ class AnkiQt(QMainWindow):
self.mainWin.noticeButton.setFixedHeight(20)
def setNotice(self, str):
self.noticeShown = time.time()
self.mainWin.noticeLabel.setText(str)
self.mainWin.noticeFrame.setShown(True)
def maybeClearNotice(self):
if time.time() - self.noticeShown > 5:
self.mainWin.noticeFrame.setShown(False)
def setupViews(self):
self.bodyView = ui.view.View(self, self.mainWin.mainText,
self.mainWin.mainTextFrame)
@ -299,6 +305,7 @@ Please do not file a bug report with Anki.<br>""")
elif state == "getQuestion":
# stop anything playing
clearAudioQueue()
self.maybeClearNotice()
if self.deck.isEmpty():
return self.moveToState("deckEmpty")
else:
@ -445,7 +452,8 @@ Please do not file a bug report with Anki.<br>""")
self.moveToState("getQuestion")
def isLeech(self):
return not self.currentCard.successive and self.currentCard.noCount > 15
return (not self.currentCard.successive and
self.currentCard.noCount >= self.deck.getInt('leechFails'))
def handleLeech(self):
self.deck.refresh()
@ -454,13 +462,15 @@ Please do not file a bug report with Anki.<br>""")
self.currentCard.fact.tags = canonifyTags(tags)
self.currentCard.fact.setModified(textChanged=True)
self.deck.updateFactTags([self.currentCard.fact.id])
txt = (_("""\
<b>%s</b>... is a <a href="http://ichi2.net/anki/wiki/Leeches">leech</a>.""")
% stripHTML(stripSounds(self.currentCard.question)).\
replace("\n", " ")[0:30])
if self.deck.getBool('suspendLeeches'):
self.deck.suspendCards([self.currentCard.id])
txt += _(" It has been suspended.")
self.deck.refresh()
self.setNotice(_("""\
<b>%s</b>... is a <a href="http://ichi2.net/anki/wiki/Leeches">leech</a>
and has been suspended.""") %
stripHTML(self.currentCard.question)[0:30].\
replace("\n", " "))
self.setNotice(txt)
def startRefreshTimer(self):
"Update the screen once a minute until next card is displayed."

View file

@ -9,8 +9,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>401</height>
<width>419</width>
<height>457</height>
</rect>
</property>
<property name="windowTitle">
@ -294,7 +294,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QLabel" name="label_27">
<property name="text">
<string>&lt;h1&gt;Advanced Scheduling&lt;/h1&gt;</string>
<string>&lt;h1&gt;Advanced&lt;/h1&gt;</string>
</property>
</widget>
</item>
@ -569,6 +569,30 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>&lt;b&gt;Suspend leeches&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="suspendLeeches">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>&lt;b&gt;Leech failure threshold&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="QSpinBox" name="leechFails"/>
</item>
</layout>
</item>
<item>
@ -626,6 +650,8 @@ p, li { white-space: pre-wrap; }
<tabstop>collapse</tabstop>
<tabstop>failedCardMax</tabstop>
<tabstop>timeOffset</tabstop>
<tabstop>suspendLeeches</tabstop>
<tabstop>leechFails</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>

View file

@ -508,7 +508,7 @@
</font>
</property>
<property name="text">
<string>TextLabel</string>
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>