From c5a78d8dbccccff3957b23a6649783eaacba0949 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 9 Nov 2008 15:48:36 +0900 Subject: [PATCH] dev wip --- ankiqt/ui/cardlist.py | 2 +- ankiqt/ui/displayproperties.py | 11 ++++++----- ankiqt/ui/main.py | 30 +++++++----------------------- ankiqt/ui/modelproperties.py | 2 +- ankiqt/ui/status.py | 6 ++---- ankiqt/ui/update.py | 4 ++-- ankiqt/ui/view.py | 11 ++++++----- designer/cardlist.ui | 23 +++++------------------ 8 files changed, 30 insertions(+), 59 deletions(-) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index 4db624c38..915a3551a 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -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 diff --git a/ankiqt/ui/displayproperties.py b/ankiqt/ui/displayproperties.py index 2a5ab1a60..14a62e925 100644 --- a/ankiqt/ui/displayproperties.py +++ b/ankiqt/ui/displayproperties.py @@ -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 = "
" + c.htmlQuestion + "
" + t = "
" + c.htmlQuestion() + "
" self.dialog.question.setText( - "\n" + t) - t = "
" + c.htmlAnswer + "
" + "\n" + t) + t = "
" + c.htmlAnswer() + "
" self.dialog.answer.setText( - "\n" + t) + "\n" + t) self.main.updateViews(self.main.state) def reject(self): diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index a7d98f69e..4e3e1ee34 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -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) diff --git a/ankiqt/ui/modelproperties.py b/ankiqt/ui/modelproperties.py index af7c1c1a0..4db5ea048 100644 --- a/ankiqt/ui/modelproperties.py +++ b/ankiqt/ui/modelproperties.py @@ -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 diff --git a/ankiqt/ui/status.py b/ankiqt/ui/status.py index 1a957c98a..0b120cf64 100644 --- a/ankiqt/ui/status.py +++ b/ankiqt/ui/status.py @@ -164,17 +164,15 @@ class StatusView(object): stats['successive1'] = '%s' % stats['successive'] stats['new1'] = '%s' % 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(_( "

Remaining cards

" "

There are %(failed)d failed cards due soon.
" "There are %(successive)d cards awaiting review.
" "There are %(new)d new cards due today.

" "There are %(new2)d new cards in total.
" - "There are %(spaced)d spaced cards.
" - "There are %(suspended)d suspended cards.") % stats) + "There are %(spaced)d spaced cards.
") % stats) # eta self.etaText.setText(_("ETA: %(timeLeft)s") % stats) # retention & progress bars diff --git a/ankiqt/ui/update.py b/ankiqt/ui/update.py index 858d3b6de..fa0203d1d 100644 --- a/ankiqt/ui/update.py +++ b/ankiqt/ui/update.py @@ -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() diff --git a/ankiqt/ui/view.py b/ankiqt/ui/view.py index d17452370..4ba8b1a6c 100644 --- a/ankiqt/ui/view.py +++ b/ankiqt/ui/view.py @@ -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 = "