From 3183fd29855afbbf465586acf0603e0fc9406835 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 26 Feb 2009 03:06:20 +0900 Subject: [PATCH] work around firefox png problems, revert previous change --- ankiqt/ui/facteditor.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/ankiqt/ui/facteditor.py b/ankiqt/ui/facteditor.py index 8ee2a8839..7e99483e0 100644 --- a/ankiqt/ui/facteditor.py +++ b/ankiqt/ui/facteditor.py @@ -851,7 +851,11 @@ class FactEdit(QTextEdit): txt = unicode(source.text()) l = txt.lower() if l.startswith("http://") or l.startswith("file://"): - if not source.hasImage(): + hadN = False + if "\n" in txt: + txt = txt.split("\n")[0] + hadN = True + if not source.hasImage() or hadN: # firefox on linux just gives us a url ext = txt.split(".")[-1].lower() try: @@ -870,6 +874,18 @@ class FactEdit(QTextEdit): else: self.insertPlainText(source.text()) return + if source.hasImage(): + im = QImage(source.imageData()) + if im.hasAlphaChannel(): + (fd, name) = tempfile.mkstemp(prefix="anki", suffix=".png") + uname = unicode(name, sys.getfilesystemencoding()) + im.save(uname) + else: + (fd, name) = tempfile.mkstemp(prefix="anki", suffix=".jpg") + uname = unicode(name, sys.getfilesystemencoding()) + im.save(uname, None, 95) + self.parent._addPicture(uname, widget=self) + return if source.hasUrls(): for url in source.urls(): url = unicode(url.toString()) @@ -884,18 +900,6 @@ class FactEdit(QTextEdit): except urllib2.URLError, e: ui.utils.showWarning(errtxt % e) return - if source.hasImage(): - im = QImage(source.imageData()) - if im.hasAlphaChannel(): - (fd, name) = tempfile.mkstemp(prefix="anki", suffix=".png") - uname = unicode(name, sys.getfilesystemencoding()) - im.save(uname) - else: - (fd, name) = tempfile.mkstemp(prefix="anki", suffix=".jpg") - uname = unicode(name, sys.getfilesystemencoding()) - im.save(uname, None, 95) - self.parent._addPicture(uname, widget=self) - return if source.hasHtml(): self.insertHtml(self.simplifyHTML(unicode(source.html()))) return