This commit is contained in:
Damien Elmes 2008-11-09 15:48:36 +09:00
parent ca7f27ea93
commit c5a78d8dbc
8 changed files with 30 additions and 59 deletions

View file

@ -364,7 +364,7 @@ class EditDeck(QDialog):
self.setWindowTitle(_("Anki - Edit Items (%(cur)d "
"of %(tot)d cards shown)") %
{"cur": len(self.model.cards),
"tot": self.deck.cardCount()})
"tot": self.deck.cardCount})
def filterTextChanged(self):
interval = 500

View file

@ -257,7 +257,7 @@ class DisplayProperties(QDialog):
else:
setattr(field, type + 'FontColour', None)
field.model.setModified()
self.deck.setModified()
self.deck.flushMod()
self.drawQuestionAndAnswer()
def chooseColour(self, button, type):
@ -268,18 +268,19 @@ class DisplayProperties(QDialog):
self.saveCard()
def drawQuestionAndAnswer(self):
self.deck.flushMod()
f = self.deck.newFact()
f.tags = u""
for field in f.fields:
f[field.name] = field.name
f.model = self.model
c = Card(f, self.card)
t = "<br><center>" + c.htmlQuestion + "</center>"
t = "<br><center>" + c.htmlQuestion() + "</center>"
self.dialog.question.setText(
"<style>\n" + c.css() + "</style>\n" + t)
t = "<br><center>" + c.htmlAnswer + "</center>"
"<style>\n" + self.deck.rebuildCSS() + "</style>\n" + t)
t = "<br><center>" + c.htmlAnswer() + "</center>"
self.dialog.answer.setText(
"<style>\n" + c.css() + "</style>\n" + t)
"<style>\n" + self.deck.rebuildCSS() + "</style>\n" + t)
self.main.updateViews(self.main.state)
def reject(self):

View file

@ -118,6 +118,7 @@ class AnkiQt(QMainWindow):
self.moveToState("initial")
def moveToState(self, state):
t = time.time()
if state == "initial":
# reset current card and load again
self.currentCard = None
@ -150,7 +151,7 @@ class AnkiQt(QMainWindow):
ui.dialogs.closeAll()
elif state == "getQuestion":
self.deck._countsDirty = True
if self.deck.cardCount() == 0:
if self.deck.isEmpty():
return self.moveToState("deckEmpty")
else:
if not self.currentCard:
@ -418,9 +419,9 @@ class AnkiQt(QMainWindow):
except (IOError, ImportError):
return
except DeckWrongFormatError, e:
self.importOldDeck(deckPath)
if not self.deck:
return
ui.utils.showMessage(_(
"Please open this deck with Anki < 0.9.8.7 to upgrade."))
return
except DeckAccessError, e:
if e.data.get('type') == 'inuse':
ui.utils.showWarning(_("Unable to load the same deck twice."))
@ -451,23 +452,6 @@ class AnkiQt(QMainWindow):
return 0
return True
def importOldDeck(self, deckPath):
from anki.importing.anki03 import Anki03Importer
# back up the old file
newPath = re.sub("\.anki$", ".anki-v3", deckPath)
while os.path.exists(newPath):
newPath += "-1"
os.rename(deckPath, newPath)
try:
self.deck = DeckStorage.Deck(deckPath)
imp = Anki03Importer(self.deck, newPath)
imp.doImport()
except DeckWrongFormatError, e:
ui.utils.showWarning(_(
"An error occurred while upgrading:\n%s") % `e.data`)
return
self.rebuildQueue()
def maybeLoadLastDeck(self, args):
"Open the last deck if possible."
# try a command line argument if available
@ -1289,8 +1273,8 @@ class AnkiQt(QMainWindow):
" - %(title)s") % {
"path": deckpath,
"title": title,
"cards": self.deck.cardCount(),
"facts": self.deck.factCount(),
"cards": self.deck.cardCount,
"facts": self.deck.factCount,
}
self.setWindowTitle(title)

View file

@ -340,7 +340,7 @@ class ModelProperties(QDialog):
self.updateField(card, 'questionInAnswer', self.dialog.questionInAnswer.isChecked())
if changed:
# need to generate all question/answers for this card
self.deck.updateCardsFromModel(self.currentCard)
self.deck.updateCardsFromModel(self.m)
self.ignoreCardUpdate = True
self.updateCards()
self.ignoreCardUpdate = False

View file

@ -164,17 +164,15 @@ class StatusView(object):
stats['successive1'] = '<font color=#000000>%s</font>' % stats['successive']
stats['new1'] = '<font color=#0000ff>%s</font>' % stats['new']
self.remText.setText(remStr % stats)
stats['suspended'] = self.main.deck.suspendedCardCount()
stats['spaced'] = self.main.deck.spacedCardCount()
stats['new2'] = self.main.deck.newCardCount()
stats['new2'] = self.main.deck.newCount
self.remText.setToolTip(_(
"<h1>Remaining cards</h1>"
"<p/>There are <b>%(failed)d</b> failed cards due soon.<br>"
"There are <b>%(successive)d</b> cards awaiting review.<br>"
"There are <b>%(new)d</b> new cards due today.<br><br>"
"There are <b>%(new2)d</b> new cards in total.<br>"
"There are <b>%(spaced)d</b> spaced cards.<br>"
"There are <b>%(suspended)d</b> suspended cards.") % stats)
"There are <b>%(spaced)d</b> spaced cards.<br>") % stats)
# eta
self.etaText.setText(_("ETA: <b>%(timeLeft)s</b>") % stats)
# retention & progress bars

View file

@ -23,7 +23,7 @@ class LatestVersionFinder(QThread):
self.config = main.config
# calculate stats before we start a new thread
if self.main.deck != None:
deckSize = self.main.deck.cardCount()
deckSize = self.main.deck.cardCount
stats = anki.stats.globalStats(self.main.deck)
deckRecall = "%0.2f" % (
(stats.matureEase3 + stats.matureEase4) /
@ -33,7 +33,7 @@ class LatestVersionFinder(QThread):
stats.matureEase3 +
stats.matureEase4 + 0.000001) * 100)
pending = "(%d, %d)" % (self.main.deck.seenCardCount(),
self.main.deck.newCardCount())
self.main.deck.newCount)
ct = self.main.deck.created
if ct:
ol = anki.lang.getLang()

View file

@ -48,7 +48,7 @@ class View(object):
self.clearWindow()
self.setBackgroundColour()
self.maybeHelp()
if self.main.deck.cardCount():
if not self.main.deck.isEmpty():
if not self.main.lastCard or (
not self.main.config['showLastCardContent'] and
not self.main.config['showLastCardInterval']):
@ -70,8 +70,9 @@ class View(object):
def addStyles(self):
# card styles
s = "<style>\n"
if self.main.currentCard:
s += self.main.currentCard.css()
t = time.time()
if self.main.deck:
s += self.main.deck.css
# last card
for base in ("lastCard", "interface"):
family = self.main.config[base + "FontFamily"]
@ -112,7 +113,7 @@ class View(object):
def drawQuestion(self, nosound=False):
"Show the question."
q = self.main.currentCard.htmlQuestion
q = self.main.currentCard.htmlQuestion()
q = renderLatex(self.main.deck, q)
self.write(stripSounds(q))
if self.state != self.oldState and not nosound:
@ -120,7 +121,7 @@ class View(object):
def drawAnswer(self):
"Show the answer."
a = self.main.currentCard.htmlAnswer
a = self.main.currentCard.htmlAnswer()
a = renderLatex(self.main.deck, a)
self.write(stripSounds(a))
if self.state != self.oldState:

View file

@ -8,8 +8,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>710</width>
<height>655</height>
<width>414</width>
<height>434</height>
</rect>
</property>
<property name="windowTitle" >
@ -42,12 +42,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize" >
<size>
<width>400</width>
<height>0</height>
</size>
</property>
<property name="title" >
<string>&amp;Search</string>
</property>
@ -66,14 +60,7 @@
</widget>
</item>
<item>
<widget class="QComboBox" name="tagList" >
<property name="minimumSize" >
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
<widget class="QComboBox" name="tagList" />
</item>
</layout>
</widget>
@ -111,7 +98,7 @@
<item>
<widget class="QPushButton" name="factsButton" >
<property name="text" >
<string>Facts..</string>
<string/>
</property>
<property name="icon" >
<iconset resource="../icons.qrc" >
@ -125,7 +112,7 @@
<item>
<widget class="QPushButton" name="cardsButton" >
<property name="text" >
<string>Cards..</string>
<string/>
</property>
<property name="icon" >
<iconset resource="../icons.qrc" >