mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
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:
parent
f483753b6c
commit
b58c082e29
3 changed files with 24 additions and 19 deletions
|
@ -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:
|
||||
|
||||
# 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()
|
||||
if not errors:
|
||||
tooltip(_("Download successful. Please restart Anki."), period=3000)
|
||||
else:
|
||||
showWarning("\n".join(errors))
|
||||
|
|
|
@ -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):
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>To browse add-ons, please click the browse button below.<br><br>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.<br><br>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>
|
||||
|
|
Loading…
Reference in a new issue