mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
progress for import, export, everything else
This commit is contained in:
parent
2e2e756436
commit
ad159aec86
4 changed files with 37 additions and 14 deletions
|
@ -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())
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
##########################################################################
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue