From eb0c9f6e0a6634e4a1ad493ef48a8989f37c52a6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 20 May 2020 16:12:41 +1000 Subject: [PATCH] fix progress bar getting stuck on image paste --- qt/aqt/editor.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qt/aqt/editor.py b/qt/aqt/editor.py index 1ccd98080..c6298c5e7 100644 --- a/qt/aqt/editor.py +++ b/qt/aqt/editor.py @@ -804,6 +804,7 @@ to a cloze type first, via Edit>Change Note Type.""" # fetch it into a temporary folder self.mw.progress.start(immediate=not local, parent=self.parentWindow) ct = None + error_msg: Optional[str] = None try: if local: req = urllib.request.Request( @@ -816,18 +817,17 @@ to a cloze type first, via Edit>Change Note Type.""" reqs.timeout = 30 r = reqs.get(url) if r.status_code != 200: - showWarning(_("Unexpected response code: %s") % r.status_code) + error_msg = _("Unexpected response code: %s") % r.status_code return filecontents = r.content ct = r.headers.get("content-type") - except urllib.error.URLError as e: - showWarning(_("An error occurred while opening %s") % e) - return - except requests.exceptions.RequestException as e: - showWarning(_("An error occurred while opening %s") % e) + except (urllib.error.URLError, requests.exceptions.RequestException) as e: + error_msg = _("An error occurred while opening %s") % e return finally: self.mw.progress.finish() + if error_msg: + showWarning(error_msg) # strip off any query string url = re.sub(r"\?.*?$", "", url) fname = os.path.basename(urllib.parse.unquote(url))