From ad159aec8618c16b0c8cf1c2b9c817823a5a9832 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 16 Jan 2009 19:42:04 +0900 Subject: [PATCH] progress for import, export, everything else --- ankiqt/ui/exporting.py | 1 + ankiqt/ui/importing.py | 7 +------ ankiqt/ui/main.py | 21 ++++++++++++++++++++- ankiqt/ui/utils.py | 22 +++++++++++++++------- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/ankiqt/ui/exporting.py b/ankiqt/ui/exporting.py index 491be878f..873bda842 100644 --- a/ankiqt/ui/exporting.py +++ b/ankiqt/ui/exporting.py @@ -52,6 +52,7 @@ class ExportDialog(QDialog): def accept(self): file = ui.utils.getSaveFile(self, _("Choose file to export to"), "export", self.exporter.key, self.exporter.ext) + self.hide() if file: self.exporter.includeSchedulingInfo = ( self.dialog.includeScheduling.isChecked()) diff --git a/ankiqt/ui/importing.py b/ankiqt/ui/importing.py index d3c57a53b..c252f0470 100644 --- a/ankiqt/ui/importing.py +++ b/ankiqt/ui/importing.py @@ -106,13 +106,8 @@ class ImportDialog(QDialog): self.maybePreview() def doImport(self): - self.dialog.status.setText(_("Importing. Anki will freeze for a while..")) + self.dialog.status.setText(_("Importing...")) t = time.time() - while self.parent.app.hasPendingEvents(): - self.parent.app.processEvents() - if time.time() - t > 1: - # windows sometimes has pending events permanently? - break self.importer.mapping = self.mapping self.importer.tagsToAdd = unicode(self.tags.text()) self.importer.tagDuplicates = self.dialog.tagDuplicates.isChecked() diff --git a/ankiqt/ui/main.py b/ankiqt/ui/main.py index 0ebeb90d4..677c0e610 100644 --- a/ankiqt/ui/main.py +++ b/ankiqt/ui/main.py @@ -56,6 +56,7 @@ class AnkiQt(QMainWindow): self.setupButtons() self.setupAnchors() self.setupToolbar() + self.setupProgressInfo() self.show() if sys.platform.startswith("darwin"): self.setUnifiedTitleAndToolBarOnMac(True) @@ -1407,7 +1408,6 @@ day = :d""", d=yesterday) p.update() self.deck.s.statement( "update fields set factId = (select new from idmap where old = factId)") - p.update() self.reset() p.finish() @@ -1929,6 +1929,25 @@ day = :d""", d=yesterday) if self.state != "showQuestion": playFromText(self.currentCard.answer) + # Progress info + ########################################################################## + + def setupProgressInfo(self): + addHook("startProgress", self.onStartProgress) + addHook("updateProgress", self.onUpdateProgress) + addHook("finishProgress", self.onFinishProgress) + + def onStartProgress(self, title, min, max): + self.progressWin = ui.utils.ProgressWin(self.app.activeWindow() or self, + title, min, max) + + def onUpdateProgress(self, label=None, value=None): + self.progressWin.update(label, value) + + def onFinishProgress(self): + self.progressWin.finish() + self.progressWin = None + # Advanced features ########################################################################## diff --git a/ankiqt/ui/utils.py b/ankiqt/ui/utils.py index 37f0829be..99f455518 100644 --- a/ankiqt/ui/utils.py +++ b/ankiqt/ui/utils.py @@ -8,7 +8,7 @@ from anki.sound import playFromText, stripSounds from anki.latex import renderLatex, stripLatex from ankiqt import ui -import re, os, sys, urllib +import re, os, sys, urllib, time import ankiqt def openLink(link): @@ -197,19 +197,27 @@ class ProgressWin(object): self.diag.setMinimumDuration(0) self.diag.show() self.counter = min - self.app = QApplication.instance() - self.app.processEvents() self.min = min self.max = max + self.lastTime = time.time() + self.app = QApplication.instance() + self.app.processEvents() - def update(self, label=None, val=None): + def update(self, label=None, value=None): + self.app.processEvents() + print self.min, self.counter, self.max, label, time.time() - self.lastTime + self.lastTime = time.time() if label: self.diag.setLabelText(label) - if val is None: - val = self.counter + if value is None: + value = self.counter self.counter += 1 - self.diag.setValue(val) + else: + self.counter = value + 1 + self.diag.setValue(value) self.app.processEvents() def finish(self): + self.diag.setValue(self.max) + self.app.processEvents() self.diag.cancel()