mirror of
https://github.com/ankitects/anki.git
synced 2025-11-12 15:47:12 -05:00
catch urllib2 errors when pasting images
This commit is contained in:
parent
043c402a45
commit
11696f949e
1 changed files with 27 additions and 15 deletions
|
|
@ -639,6 +639,7 @@ class FactEdit(QTextEdit):
|
|||
if not source.hasImage():
|
||||
# firefox on linux just gives us a url
|
||||
ext = txt.split(".")[-1].lower()
|
||||
try:
|
||||
if ext in pics:
|
||||
name = self._retrieveURL(txt, ext)
|
||||
self.parent._addPicture(name, widget=self)
|
||||
|
|
@ -648,6 +649,11 @@ class FactEdit(QTextEdit):
|
|||
else:
|
||||
# not image or sound, treat as plain text
|
||||
self.insertPlainText(source.text())
|
||||
except urllib2.URLError, e:
|
||||
ui.utils.showWarning(_("""\
|
||||
An error was ecountered while opening %s
|
||||
|
||||
%s""") % (txt, e))
|
||||
return
|
||||
else:
|
||||
self.insertPlainText(source.text())
|
||||
|
|
@ -666,12 +672,18 @@ class FactEdit(QTextEdit):
|
|||
for url in source.urls():
|
||||
url = unicode(url.toString())
|
||||
ext = url.split(".")[-1].lower()
|
||||
try:
|
||||
if ext in pics:
|
||||
name = self._retrieveURL(url, ext)
|
||||
self.parent._addPicture(name, widget=self)
|
||||
elif ext in audio:
|
||||
name = self._retrieveURL(url, ext)
|
||||
self.parent._addSound(name, widget=self)
|
||||
except urllib2.URLError, e:
|
||||
ui.utils.showWarning(_("""\
|
||||
An error was ecountered while opening %s
|
||||
|
||||
%s""") % (txt, e))
|
||||
return
|
||||
|
||||
def _retrieveURL(self, url, ext):
|
||||
|
|
|
|||
Loading…
Reference in a new issue