mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22: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):
|
def accept(self):
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
# create downloader thread
|
|
||||||
txt = self.form.code.text().split()
|
# get codes
|
||||||
for x in txt:
|
try:
|
||||||
ret = download(self.mw, x)
|
ids = [int(n) for n in self.form.code.text().split()]
|
||||||
if not ret:
|
except ValueError:
|
||||||
|
showWarning(_("Invalid code."))
|
||||||
return
|
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
|
data, fname = ret
|
||||||
self.mw.addonManager.install(data, fname)
|
self.mw.addonManager.install(data, fname)
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
|
if not errors:
|
||||||
tooltip(_("Download successful. Please restart Anki."), period=3000)
|
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
|
import aqt
|
||||||
|
|
||||||
def download(mw, code):
|
def download(mw, code):
|
||||||
"Download addon/deck from AnkiWeb. On success caller must stop progress diag."
|
"Download addon/deck from AnkiWeb. Caller must start & stop progress diag."
|
||||||
# check code is valid
|
|
||||||
try:
|
|
||||||
code = int(code)
|
|
||||||
except ValueError:
|
|
||||||
showWarning(_("Invalid code."))
|
|
||||||
return
|
|
||||||
# create downloading thread
|
# create downloading thread
|
||||||
thread = Downloader(code)
|
thread = Downloader(code)
|
||||||
def onRecv():
|
def onRecv():
|
||||||
|
@ -30,7 +24,6 @@ def download(mw, code):
|
||||||
pass
|
pass
|
||||||
thread.recv.connect(onRecv)
|
thread.recv.connect(onRecv)
|
||||||
thread.start()
|
thread.start()
|
||||||
mw.progress.start(immediate=True)
|
|
||||||
while not thread.isFinished():
|
while not thread.isFinished():
|
||||||
mw.app.processEvents()
|
mw.app.processEvents()
|
||||||
thread.wait(100)
|
thread.wait(100)
|
||||||
|
@ -38,8 +31,7 @@ def download(mw, code):
|
||||||
# success
|
# success
|
||||||
return thread.data, thread.fname
|
return thread.data, thread.fname
|
||||||
else:
|
else:
|
||||||
mw.progress.finish()
|
return "error", thread.error
|
||||||
showWarning(_("Download failed: %s") % thread.error)
|
|
||||||
|
|
||||||
class Downloader(QThread):
|
class Downloader(QThread):
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<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>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
Loading…
Reference in a new issue