From a422ddb57b3a0a0c8eefd26c40dc614d52b4d5c3 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 21 Apr 2009 02:16:17 +0900 Subject: [PATCH 01/19] experiment with standalone windows --- ankiqt/config.py | 1 + ankiqt/ui/addcards.py | 6 +++++- ankiqt/ui/cardlist.py | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ankiqt/config.py b/ankiqt/config.py index 2b3e6d26e..90f667a32 100644 --- a/ankiqt/config.py +++ b/ankiqt/config.py @@ -75,6 +75,7 @@ class Config(dict): 'showStudyOptions': False, 'showStudyStats': True, 'showCardTimer': True, + 'standaloneWindows': True, 'extraNewCards': 5, 'randomizeOnCram': True, 'created': time.time(), diff --git a/ankiqt/ui/addcards.py b/ankiqt/ui/addcards.py index 31f98e13c..40497f545 100644 --- a/ankiqt/ui/addcards.py +++ b/ankiqt/ui/addcards.py @@ -22,7 +22,11 @@ class FocusButton(QPushButton): class AddCards(QDialog): def __init__(self, parent): - QDialog.__init__(self, parent, Qt.Window) + if parent.config['standaloneWindows']: + windParent = None + else: + windParent = parent + QDialog.__init__(self, windParent, Qt.Window) self.parent = parent self.config = parent.config self.dialog = ankiqt.forms.addcards.Ui_AddCards() diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index 31327983a..e458b7205 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -278,6 +278,10 @@ class StatusDelegate(QItemDelegate): class EditDeck(QMainWindow): def __init__(self, parent): + if parent.config['standaloneWindows']: + windParent = None + else: + windParent = parent QMainWindow.__init__(self, parent) self.parent = parent self.deck = self.parent.deck From 1fbad4235aed18bab88e31bf03b0f91787978b90 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 21 Apr 2009 02:49:41 +0900 Subject: [PATCH 02/19] protect more timers --- ankiqt/ui/cardlist.py | 2 ++ ankiqt/ui/graphs.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index e458b7205..9a2384a21 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -503,6 +503,8 @@ class EditDeck(QMainWindow): self.updateSearch() def updateSearch(self, force=True): + if self.parent.inDbHandler: + return idx = self.dialog.tableView.currentIndex() row = idx.row() self.model.searchStr = unicode(self.dialog.filterEdit.text()) diff --git a/ankiqt/ui/graphs.py b/ankiqt/ui/graphs.py index dc23a0a3f..66062c0cf 100644 --- a/ankiqt/ui/graphs.py +++ b/ankiqt/ui/graphs.py @@ -42,9 +42,10 @@ class AnkiFigureCanvas (FigureCanvas): class AdjustableFigure(QWidget): - def __init__(self, config, name, figureFunc, choices=None): + def __init__(self, parent, name, figureFunc, choices=None): QWidget.__init__(self) - self.config = config + self.parent = parent + self.config = parent.config self.name = name self.vbox = QVBoxLayout() self.vbox.setSpacing(2) @@ -75,6 +76,8 @@ class AdjustableFigure(QWidget): self.vbox.addLayout(self.hbox) def updateFigure(self): + if self.parent.inDbHandler: + return self.updateTimer = None self.setUpdatesEnabled(False) idx = self.vbox.indexOf(self.figureCanvas) @@ -184,43 +187,43 @@ class GraphWindow(object): self.diag.show() def setupGraphs(self): - nextDue = AdjustableFigure(self.parent.config, 'due', self.dg.nextDue, self.range) + nextDue = AdjustableFigure(self.parent, 'due', self.dg.nextDue, self.range) nextDue.addWidget(QLabel(_("

Due

"))) self.vbox.addWidget(nextDue) self.widgets.append(nextDue) - workload = AdjustableFigure(self.parent.config, 'reps', self.dg.workDone, self.range) + workload = AdjustableFigure(self.parent, 'reps', self.dg.workDone, self.range) workload.addWidget(QLabel(_("

Reps

"))) self.vbox.addWidget(workload) self.widgets.append(workload) - times = AdjustableFigure(self.parent.config, 'times', self.dg.timeSpent, self.range) + times = AdjustableFigure(self.parent, 'times', self.dg.timeSpent, self.range) times.addWidget(QLabel(_("

Review Time

"))) self.vbox.addWidget(times) self.widgets.append(times) - added = AdjustableFigure(self.parent.config, 'added', self.dg.addedRecently, self.range) + added = AdjustableFigure(self.parent, 'added', self.dg.addedRecently, self.range) added.addWidget(QLabel(_("

Added

"))) self.vbox.addWidget(added) self.widgets.append(added) - answered = AdjustableFigure(self.parent.config, 'answered', lambda *args: apply( + answered = AdjustableFigure(self.parent, 'answered', lambda *args: apply( self.dg.addedRecently, args + ('firstAnswered',)), self.range) answered.addWidget(QLabel(_("

First Answered

"))) self.vbox.addWidget(answered) self.widgets.append(answered) - cumDue = AdjustableFigure(self.parent.config, 'cum', self.dg.cumulativeDue, self.range) + cumDue = AdjustableFigure(self.parent, 'cum', self.dg.cumulativeDue, self.range) cumDue.addWidget(QLabel(_("

Cumulative Due

"))) self.vbox.addWidget(cumDue) self.widgets.append(cumDue) - interval = AdjustableFigure(self.parent.config, 'interval', self.dg.intervalPeriod, self.range) + interval = AdjustableFigure(self.parent, 'interval', self.dg.intervalPeriod, self.range) interval.addWidget(QLabel(_("

Intervals

"))) self.vbox.addWidget(interval) self.widgets.append(interval) - eases = AdjustableFigure(self.parent.config, 'eases', self.dg.easeBars) + eases = AdjustableFigure(self.parent, 'eases', self.dg.easeBars) eases.addWidget(QLabel(_("

Eases

"))) self.vbox.addWidget(eases) self.widgets.append(eases) From 9212d8053f988cf66210c8bf261ce338d52999c5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 22 Apr 2009 21:30:01 +0900 Subject: [PATCH 03/19] place no lower limit on number of failed cards --- ankiqt/ui/deckproperties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ankiqt/ui/deckproperties.py b/ankiqt/ui/deckproperties.py index d5cd6ae88..cf779ad22 100644 --- a/ankiqt/ui/deckproperties.py +++ b/ankiqt/ui/deckproperties.py @@ -235,7 +235,7 @@ class DeckProperties(QDialog): v = float(self.dialog.delay2.text()) self.updateField(self.d, 'delay2', v) v = int(self.dialog.failedCardMax.text()) - self.updateField(self.d, 'failedCardMax', max(v, 5)) + self.updateField(self.d, 'failedCardMax', v) except ValueError: pass # hour shift From a05fc37d9433670e0aed906e1a27c092c31ce478 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 22 Apr 2009 22:10:14 +0900 Subject: [PATCH 04/19] check if anki is already open and prompt user --- ankiqt/__init__.py | 3 ++- ankiqt/ui/main.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ankiqt/__init__.py b/ankiqt/__init__.py index 5b08d732a..bcdc8fb83 100644 --- a/ankiqt/__init__.py +++ b/ankiqt/__init__.py @@ -173,7 +173,8 @@ def run(): except (IOError, OSError): pass - app.exec_() + if not mw.abortOpen: + app.exec_() if __name__ == "__main__": run() diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 4c33536d8..36c6363a0 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -33,6 +33,7 @@ class AnkiQt(QMainWindow): QMainWindow.__init__(self) self.errorOccurred = False self.inDbHandler = False + self.abortOpen = False if sys.platform.startswith("darwin"): qt_mac_set_menubar_icons(False) ankiqt.mw = self @@ -631,6 +632,12 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) r = self.loadDeck(path, interactive=False, sync=False) if r: return r + else: + # deck is already open + if not ui.utils.askUser( + _("Anki is already open. Open another copy?")): + self.abortOpen = True + return self.onNew(initial=True) def getDefaultDir(self, save=False): From 93a20e13b6de5ef2338b4ac14f672c277fb50953 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 22 Apr 2009 22:11:01 +0900 Subject: [PATCH 05/19] fix timer hiding, fix session start time being reset --- ankiqt/ui/main.py | 1 - ankiqt/ui/status.py | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 36c6363a0..b72088e94 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1043,7 +1043,6 @@ your deck.""")) def updateStudyStats(self): wasReached = self.deck.sessionLimitReached() - self.deck.sessionStartTime = 0 sessionColour = '%s' cardColour = '%s' if not wasReached: diff --git a/ankiqt/ui/status.py b/ankiqt/ui/status.py index 83b6af118..646df8815 100644 --- a/ankiqt/ui/status.py +++ b/ankiqt/ui/status.py @@ -64,13 +64,16 @@ class StatusView(object): shown = True self.progressBar.setShown(shown) self.retentionBar.setShown(shown) - self.timer.setShown(shown) self.etaText.setShown(shown) self.remText.setShown(shown) self.sep1.setShown(shown) self.sep2.setShown(shown) - self.sep3.setShown(shown) self.statusbar.hideOrShow() + # timer has a separate option + if not self.main.config['showTimer']: + shown = False + self.timer.setShown(shown) + self.sep3.setShown(shown) # Setup and teardown ########################################################################## @@ -130,8 +133,6 @@ class StatusView(object): self.timer.setText("00:00") self.addWidget(self.timer) self.redraw() - if not self.main.config['showTimer']: - self.timer.setShown(False) def addWidget(self, w, stretch=0): self.statusbar.addWidget(w, stretch) From c84f97c33ca008f08d0bc2c50ad59d4e71bde92b Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 22 Apr 2009 22:11:14 +0900 Subject: [PATCH 06/19] Revert "check if anki is already open and prompt user" This reverts commit a05fc37d9433670e0aed906e1a27c092c31ce478. --- ankiqt/__init__.py | 3 +-- ankiqt/ui/main.py | 7 ------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/ankiqt/__init__.py b/ankiqt/__init__.py index bcdc8fb83..5b08d732a 100644 --- a/ankiqt/__init__.py +++ b/ankiqt/__init__.py @@ -173,8 +173,7 @@ def run(): except (IOError, OSError): pass - if not mw.abortOpen: - app.exec_() + app.exec_() if __name__ == "__main__": run() diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index b72088e94..8b1fb6a2f 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -33,7 +33,6 @@ class AnkiQt(QMainWindow): QMainWindow.__init__(self) self.errorOccurred = False self.inDbHandler = False - self.abortOpen = False if sys.platform.startswith("darwin"): qt_mac_set_menubar_icons(False) ankiqt.mw = self @@ -632,12 +631,6 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) r = self.loadDeck(path, interactive=False, sync=False) if r: return r - else: - # deck is already open - if not ui.utils.askUser( - _("Anki is already open. Open another copy?")): - self.abortOpen = True - return self.onNew(initial=True) def getDefaultDir(self, save=False): From 763758d43f6e1a441d6413f7b8a636be6cb046e1 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 00:32:56 +0900 Subject: [PATCH 07/19] rely on setVar() to check if modified --- ankiqt/ui/cardlist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index 9a2384a21..1e7a3f5ca 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -416,8 +416,7 @@ class EditDeck(QMainWindow): self.sortKey = ("field", self.sortFields[idx-9]) self.rebuildSortIndex(self.sortKey) self.sortIndex = idx - if self.deck.getInt('sortIndex') != idx: - self.deck.setVar('sortIndex', idx) + self.deck.setVar('sortIndex', idx) self.model.sortKey = self.sortKey self.model.updateHeader() if refresh: From a3c5caa5441ad5436da4da8eba8e610a7b1c9e5c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 01:33:49 +0900 Subject: [PATCH 08/19] randomize/order when settings changed --- ankiqt/ui/main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 8b1fb6a2f..0313da9c5 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1154,8 +1154,15 @@ day = :d""", d=yesterday) int(self.mainWin.questionLimit.text())) except (ValueError, OverflowError): pass - uf(self.deck, 'newCardOrder', - self.mainWin.newCardOrder.currentIndex()) + ncOrd = self.mainWin.newCardOrder.currentIndex() + if self.deck.newCardOrder != ncOrd: + if self.deck.newCardOrder == 0 and ncOrd != 0: + # random to non-random + self.deck.orderNewCards() + elif self.deck.newCardOrder != 0 and ncOrd == 0: + # non-random to random + self.deck.randomizeNewCards() + uf(self.deck, 'newCardOrder', ncOrd) uf(self.deck, 'newCardSpacing', self.mainWin.newCardScheduling.currentIndex()) uf(self.deck, 'revCardOrder', From 16d03239652cb624d392ebf9b82ef233a70850c0 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 01:58:53 +0900 Subject: [PATCH 09/19] handle randomize progress instead of in libanki --- ankiqt/ui/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 0313da9c5..8e944fcbf 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1158,10 +1158,16 @@ day = :d""", d=yesterday) if self.deck.newCardOrder != ncOrd: if self.deck.newCardOrder == 0 and ncOrd != 0: # random to non-random + self.deck.startProgress() + self.deck.updateProgress(_("Ordering...")) self.deck.orderNewCards() + self.deck.finishProgress() elif self.deck.newCardOrder != 0 and ncOrd == 0: # non-random to random + self.deck.startProgress() + self.deck.updateProgress(_("Randomizing...")) self.deck.randomizeNewCards() + self.deck.finishProgress() uf(self.deck, 'newCardOrder', ncOrd) uf(self.deck, 'newCardSpacing', self.mainWin.newCardScheduling.currentIndex()) From b3ed9613ac25479109fa443353eb63cdc900ab78 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 02:01:58 +0900 Subject: [PATCH 10/19] hide group box after importing --- ankiqt/ui/importing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ankiqt/ui/importing.py b/ankiqt/ui/importing.py index 753b80609..f430c8d08 100644 --- a/ankiqt/ui/importing.py +++ b/ankiqt/ui/importing.py @@ -134,6 +134,7 @@ class ImportDialog(QDialog): txt = ( _("Importing complete. %(num)d facts imported from %(file)s.\n") % {"num": self.importer.total, "file": os.path.basename(self.file)}) + self.dialog.groupBox.setShown(False) if self.importer.log: txt += _("Log of import:\n") + "\n".join(self.importer.log) self.dialog.status.setText(txt) From 5540da95ef2314b0088fc0371b132d2ecdfe6390 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 02:02:47 +0900 Subject: [PATCH 11/19] focus close button after import --- ankiqt/ui/importing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/ankiqt/ui/importing.py b/ankiqt/ui/importing.py index f430c8d08..be620426e 100644 --- a/ankiqt/ui/importing.py +++ b/ankiqt/ui/importing.py @@ -135,6 +135,7 @@ class ImportDialog(QDialog): _("Importing complete. %(num)d facts imported from %(file)s.\n") % {"num": self.importer.total, "file": os.path.basename(self.file)}) self.dialog.groupBox.setShown(False) + self.dialog.buttonBox.button(QDialogButtonBox.Close).setFocus() if self.importer.log: txt += _("Log of import:\n") + "\n".join(self.importer.log) self.dialog.status.setText(txt) From 0a1658de249053e636be8e2df2a1ccb45b2ff695 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 02:08:12 +0900 Subject: [PATCH 12/19] improve sync error message --- ankiqt/ui/sync.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/ankiqt/ui/sync.py b/ankiqt/ui/sync.py index 6ff62a644..45979e105 100644 --- a/ankiqt/ui/sync.py +++ b/ankiqt/ui/sync.py @@ -49,12 +49,11 @@ class Sync(QThread): msg=_("Please double-check your username/password.") elif error.data.get('status') == "oldVersion": msg=_("The sync protocol has changed. Please upgrade.") - else: + elif error.data.get('type') == 'noResponse': msg=_("""\ -Syncing failed. Please try again in a few minutes. -If the problem persists, please report it on the forum. - -Error: %s""" % `getattr(error, 'data')`) +Couldn't contact Anki Online. Please check your internet connection.""") + else: + msg=_("Unknown error: %s" % `getattr(error, 'data')`) return msg def connect(self, *args): From 2ab8b7a57492ee1f4f32c4cc9e91da51e845828c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 02:30:08 +0900 Subject: [PATCH 13/19] generalize tooltips, make sync no contact msg a tooltip --- ankiqt/ui/main.py | 32 +++++++++++++++++++++----------- ankiqt/ui/sync.py | 10 +++++----- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 8e944fcbf..4d6521c36 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -830,14 +830,17 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) self.updateRecentFiles(file) return True - def onUnsavedTimer(self): + def showToolTip(self, msg): + t = QTimer(self) + t.setSingleShot(True) + t.start(200) + self.connect(t, SIGNAL("timeout()"), + lambda msg=msg: self._showToolTip(msg)) + + def _showToolTip(self, msg): QToolTip.showText( - self.mainWin.statusbar.mapToGlobal(QPoint(0, -100)), - _("""\ -

Unsaved Deck

-Careful. You're editing an unsaved Deck.
-Choose File -> Save to start autosaving
-your deck.""")) + self.mainWin.statusbar.mapToGlobal(QPoint(0, -40)), + msg) def save(self, required=False): if not self.deck.path: @@ -845,10 +848,11 @@ your deck.""")) # backed in memory, make sure it's saved return self.onSaveAs() else: - t = QTimer(self) - t.setSingleShot(True) - t.start(200) - self.connect(t, SIGNAL("timeout()"), self.onUnsavedTimer) + self.showToolTip(_("""\ +

Unsaved Deck

+Careful. You're editing an unsaved Deck.
+Choose File -> Save to start autosaving
+your deck.""")) return if not self.deck.modifiedSinceSave(): return True @@ -1657,6 +1661,7 @@ it to your friends. onlyMerge, self.sourcesToCheck) self.connect(self.syncThread, SIGNAL("setStatus"), self.setSyncStatus) self.connect(self.syncThread, SIGNAL("showWarning"), self.showSyncWarning) + self.connect(self.syncThread, SIGNAL("noSyncResponse"), self.noSyncResponse) self.connect(self.syncThread, SIGNAL("moveToState"), self.moveToState) self.connect(self.syncThread, SIGNAL("noMatchingDeck"), self.selectSyncDeck) self.connect(self.syncThread, SIGNAL("syncClockOff"), self.syncClockOff) @@ -1731,6 +1736,11 @@ it to your friends. ui.utils.showWarning(text, self) self.setStatus("") + def noSyncResponse(self): + self.showToolTip(_("""\ +

Sync Failed

+Couldn't contact Anki Online. Please check your internet connection.""")) + def openSyncProgress(self): self.syncProgressDialog = QProgressDialog(_("Syncing Media..."), "", 0, 0, self) diff --git a/ankiqt/ui/sync.py b/ankiqt/ui/sync.py index 45979e105..1452bf6c3 100644 --- a/ankiqt/ui/sync.py +++ b/ankiqt/ui/sync.py @@ -36,8 +36,11 @@ class Sync(QThread): self.syncDeck() def error(self, error): - error = self.getErrorMessage(error) - self.emit(SIGNAL("showWarning"), error) + if error.data.get('type') == 'noResponse': + self.emit(SIGNAL("noSyncResponse")) + else: + error = self.getErrorMessage(error) + self.emit(SIGNAL("showWarning"), error) if self.onlyMerge: # new file needs cleaning up self.emit(SIGNAL("cleanNewDeck")) @@ -49,9 +52,6 @@ class Sync(QThread): msg=_("Please double-check your username/password.") elif error.data.get('status') == "oldVersion": msg=_("The sync protocol has changed. Please upgrade.") - elif error.data.get('type') == 'noResponse': - msg=_("""\ -Couldn't contact Anki Online. Please check your internet connection.""") else: msg=_("Unknown error: %s" % `getattr(error, 'data')`) return msg From af2bd520033bd15ac8de9264070bcd6c7de4e4b8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 03:46:22 +0900 Subject: [PATCH 14/19] increase cram randomization speed by a factor of 5, prevent add cards open on cram --- ankiqt/ui/main.py | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 4d6521c36..d85b678e6 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -685,8 +685,7 @@ To upgrade an old deck, download Anki 0.9.8.7.""")) def onClose(self): if self.inMainWindow(): - cramming = self.deck is not None and self.deck.name() == "cram" - self.saveAndClose(hideWelcome=cramming) + self.saveAndClose(hideWelcome=self.isCramming()) if cramming: self.loadRecent(0) else: @@ -1374,6 +1373,9 @@ day = :d""", d=yesterday) ########################################################################## def onAddCard(self): + if self.isCramming(): + ui.utils.showInfo(_("Can't add cards while cramming.")) + return ui.dialogs.get("AddCards", self) def onEditDeck(self): @@ -1437,8 +1439,11 @@ day = :d""", d=yesterday) e.exportInto(path) return (e, path) + def isCramming(self): + return self.deck is not None and self.deck.name() == "cram" + def onCram(self, cardIds=[]): - if self.deck.name() == "cram": + if self.isCramming(): ui.utils.showInfo( _("Already cramming. Please close this deck first.")) return @@ -1458,7 +1463,7 @@ day = :d""", d=yesterday) ui.utils.showInfo(_("No cards matched the provided tags.")) return if self.config['randomizeOnCram']: - n = 5 + n = 3 else: n = 2 p = ui.utils.ProgressWin(self, n, 0, _("Cram")) @@ -1478,22 +1483,11 @@ day = :d""", d=yesterday) self.deck.easyIntervalMax = 0.25 self.deck.newCardOrder = 0 self.deck.syncName = None + p.update() + self.deck.updateDynamicIndices() if self.config['randomizeOnCram']: p.update(_("Randomizing...")) - self.deck.s.statement( - "create temporary table idmap (old, new, primary key (old))") - self.deck.s.statement( - "insert into idmap select id, random() from facts") - self.deck.s.statement( - "update facts set id = (select new from idmap where old = id)") - p.update() - self.deck.s.statement( - "update cards set factId = (select new from idmap where old = factId)") - p.update() - self.deck.s.statement( - "update fields set factId = (select new from idmap where old = factId)") - p.update() - self.deck.updateDynamicIndices() + self.deck.randomizeNewCards() self.reset() p.finish() From 1fe922fed4a32c658db74878a1043bafe7aee65a Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 03:54:28 +0900 Subject: [PATCH 15/19] prevent import in cramming, warn when editing in cramming --- ankiqt/ui/main.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index d85b678e6..9296c1552 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1374,12 +1374,18 @@ day = :d""", d=yesterday) def onAddCard(self): if self.isCramming(): - ui.utils.showInfo(_("Can't add cards while cramming.")) + ui.utils.showInfo(_("""\ +You are currently cramming. Please close this deck first.""")) return ui.dialogs.get("AddCards", self) def onEditDeck(self): ui.dialogs.get("CardList", self) + if self.isCramming(): + self.showToolTip(_("""\ +

Cramming

+You are currently cramming. Any edits you make to this deck +will be lost when you close the deck.""")) def onEditCurrent(self): self.moveToState("editCurrentFact") @@ -1415,7 +1421,10 @@ day = :d""", d=yesterday) ########################################################################## def onImport(self): - import ui.importing + if self.isCramming(): + ui.utils.showInfo(_("""\ +You are currently cramming. Please close this deck first.""")) + return if self.deck is None: self.onNew() ui.importing.ImportDialog(self) From ccf96a04e14f737dc12a7b80473072a749a71a13 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 04:17:42 +0900 Subject: [PATCH 16/19] when marking cards, ensure order is correct --- ankiqt/ui/main.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 9296c1552..c68490b30 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -14,7 +14,7 @@ from PyQt4.QtGui import * from anki import DeckStorage from anki.errors import * from anki.sound import hasSound, playFromText, clearAudioQueue -from anki.utils import addTags, deleteTags, parseTags +from anki.utils import addTags, deleteTags, parseTags, canonifyTags from anki.media import rebuildMediaDir from anki.db import OperationalError from anki.stdmodels import BasicModel @@ -1330,11 +1330,11 @@ day = :d""", d=yesterday) def onMark(self, toggled): if self.currentCard.hasTag("Marked"): - self.currentCard.fact.tags = deleteTags( - "Marked", self.currentCard.fact.tags) + self.currentCard.fact.tags = canonifyTags(deleteTags( + "Marked", self.currentCard.fact.tags)) else: - self.currentCard.fact.tags = addTags( - "Marked", self.currentCard.fact.tags) + self.currentCard.fact.tags = canonifyTags(addTags( + "Marked", self.currentCard.fact.tags)) self.currentCard.fact.setModified(textChanged=True) self.deck.updateFactTags([self.currentCard.fact.id]) self.deck.setModified() From 92b19171f774020cffccf6a57b4b4ed0ad89b1f9 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 04:18:03 +0900 Subject: [PATCH 17/19] ensure tag order correct when suspending too --- ankiqt/ui/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index c68490b30..5b03e7c2b 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -1342,7 +1342,8 @@ day = :d""", d=yesterday) def onSuspend(self): undo = _("Suspend") self.deck.setUndoStart(undo) - self.currentCard.fact.tags = addTags("Suspended", self.currentCard.fact.tags) + self.currentCard.fact.tags = canonifyTags( + addTags("Suspended", self.currentCard.fact.tags)) self.currentCard.fact.setModified(textChanged=True) self.deck.updateFactTags([self.currentCard.fact.id]) for card in self.currentCard.fact.cards: From 222e8a93df1b4b8b1558f5f3471b357b7d71a41c Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 04:23:01 +0900 Subject: [PATCH 18/19] add icons to browser and add card dialogs --- designer/addcards.ui | 8 ++++++-- designer/cardlist.ui | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/designer/addcards.ui b/designer/addcards.ui index f1d6dab55..1bb20da65 100644 --- a/designer/addcards.ui +++ b/designer/addcards.ui @@ -12,6 +12,10 @@ Add Items + + + :/icons/list-add.png:/icons/list-add.png + 0 @@ -93,8 +97,8 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal;"> -<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html> +</style></head><body style=" font-family:'Sans Serif'; font-size:8pt; font-weight:400; font-style:normal;"> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Arial';"></p></body></html> diff --git a/designer/cardlist.ui b/designer/cardlist.ui index 4595230cd..4b6f0b41f 100644 --- a/designer/cardlist.ui +++ b/designer/cardlist.ui @@ -12,6 +12,10 @@ Browse Items + + + :/icons/find.png:/icons/find.png + From d9d795af55f2ae8a19f22d5c985e197315f601f7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 Apr 2009 04:23:14 +0900 Subject: [PATCH 19/19] fix windParent in browser --- ankiqt/ui/cardlist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ankiqt/ui/cardlist.py b/ankiqt/ui/cardlist.py index 1e7a3f5ca..0486825b9 100644 --- a/ankiqt/ui/cardlist.py +++ b/ankiqt/ui/cardlist.py @@ -282,7 +282,7 @@ class EditDeck(QMainWindow): windParent = None else: windParent = parent - QMainWindow.__init__(self, parent) + QMainWindow.__init__(self, windParent) self.parent = parent self.deck = self.parent.deck self.config = parent.config