fix progress bar getting stuck on image paste

This commit is contained in:
Damien Elmes 2020-05-20 16:12:41 +10:00
parent 6ae55a7a77
commit eb0c9f6e0a

View File

@ -804,6 +804,7 @@ to a cloze type first, via Edit>Change Note Type."""
# fetch it into a temporary folder # fetch it into a temporary folder
self.mw.progress.start(immediate=not local, parent=self.parentWindow) self.mw.progress.start(immediate=not local, parent=self.parentWindow)
ct = None ct = None
error_msg: Optional[str] = None
try: try:
if local: if local:
req = urllib.request.Request( req = urllib.request.Request(
@ -816,18 +817,17 @@ to a cloze type first, via Edit>Change Note Type."""
reqs.timeout = 30 reqs.timeout = 30
r = reqs.get(url) r = reqs.get(url)
if r.status_code != 200: if r.status_code != 200:
showWarning(_("Unexpected response code: %s") % r.status_code) error_msg = _("Unexpected response code: %s") % r.status_code
return return
filecontents = r.content filecontents = r.content
ct = r.headers.get("content-type") ct = r.headers.get("content-type")
except urllib.error.URLError as e: except (urllib.error.URLError, requests.exceptions.RequestException) as e:
showWarning(_("An error occurred while opening %s") % e) error_msg = _("An error occurred while opening %s") % e
return
except requests.exceptions.RequestException as e:
showWarning(_("An error occurred while opening %s") % e)
return return
finally: finally:
self.mw.progress.finish() self.mw.progress.finish()
if error_msg:
showWarning(error_msg)
# strip off any query string # strip off any query string
url = re.sub(r"\?.*?$", "", url) url = re.sub(r"\?.*?$", "", url)
fname = os.path.basename(urllib.parse.unquote(url)) fname = os.path.basename(urllib.parse.unquote(url))