tweaks to add-on downloading

- avoid opening and closing multiple progress dialogs
- report errors at the end; download what we can
- update dialog text
This commit is contained in:
Damien Elmes 2017-02-15 15:55:20 +10:00
parent f483753b6c
commit b58c082e29
3 changed files with 24 additions and 19 deletions

View file

@ -164,13 +164,26 @@ class GetAddons(QDialog):
def accept(self):
QDialog.accept(self)
# create downloader thread
txt = self.form.code.text().split()
for x in txt:
ret = download(self.mw, x)
if not ret:
return
# get codes
try:
ids = [int(n) for n in self.form.code.text().split()]
except ValueError:
showWarning(_("Invalid code."))
return
errors = []
self.mw.progress.start(immediate=True)
for n in ids:
ret = download(self.mw, n)
if ret[0] == "error":
errors.append(_("Error downloading %(id)s: %(error)s") % dict(id=n, error=ret[1]))
continue
data, fname = ret
self.mw.addonManager.install(data, fname)
self.mw.progress.finish()
tooltip(_("Download successful. Please restart Anki."), period=3000)
self.mw.progress.finish()
if not errors:
tooltip(_("Download successful. Please restart Anki."), period=3000)
else:
showWarning("\n".join(errors))

View file

@ -10,13 +10,7 @@ from anki.hooks import addHook, remHook
import aqt
def download(mw, code):
"Download addon/deck from AnkiWeb. On success caller must stop progress diag."
# check code is valid
try:
code = int(code)
except ValueError:
showWarning(_("Invalid code."))
return
"Download addon/deck from AnkiWeb. Caller must start & stop progress diag."
# create downloading thread
thread = Downloader(code)
def onRecv():
@ -30,7 +24,6 @@ def download(mw, code):
pass
thread.recv.connect(onRecv)
thread.start()
mw.progress.start(immediate=True)
while not thread.isFinished():
mw.app.processEvents()
thread.wait(100)
@ -38,8 +31,7 @@ def download(mw, code):
# success
return thread.data, thread.fname
else:
mw.progress.finish()
showWarning(_("Download failed: %s") % thread.error)
return "error", thread.error
class Downloader(QThread):

View file

@ -17,7 +17,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>To browse add-ons, please click the browse button below.&lt;br&gt;&lt;br&gt;When you've found an add-on you like, please paste its code below.</string>
<string>To browse add-ons, please click the browse button below.&lt;br&gt;&lt;br&gt;When you've found an add-on you like, please paste its code below. You can paste multiple codes, separated by spaces.</string>
</property>
<property name="wordWrap">
<bool>true</bool>