diff --git a/src/calibre/gui2/book_details.py b/src/calibre/gui2/book_details.py index 7633c49010..e1a25a8aa3 100644 --- a/src/calibre/gui2/book_details.py +++ b/src/calibre/gui2/book_details.py @@ -23,6 +23,7 @@ from calibre.ebooks.metadata.book.base import (field_metadata, Metadata) from calibre.ebooks.metadata.book.render import mi_to_html from calibre.gui2 import (config, open_url, pixmap_to_data, gprefs, rating_font, NO_URL_FORMATTING) from calibre.utils.config import tweaks +from calibre.utils.img import image_from_x, blend_image from calibre.utils.localization import is_rtl _css = None @@ -368,6 +369,8 @@ class CoverView(QWidget): # {{{ pmap.loadFromData(cdata) if pmap.isNull(): return + if pmap.hasAlphaChannel(): + pmap = QPixmap.fromImage(blend_image(image_from_x(pmap))) self.pixmap = pmap self.do_layout() self.update() @@ -665,7 +668,7 @@ class BookDetails(QWidget): # {{{ return # Now look for ebook files - urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True) + urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True, filter_exts=image_extensions()) if not urls: # Nothing found return diff --git a/src/calibre/gui2/dnd.py b/src/calibre/gui2/dnd.py index e3828ff46a..cde3b52964 100644 --- a/src/calibre/gui2/dnd.py +++ b/src/calibre/gui2/dnd.py @@ -246,7 +246,7 @@ def dnd_get_image(md, image_exts=None): return None, None -def dnd_get_files(md, exts, allow_all_extensions=False): +def dnd_get_files(md, exts, allow_all_extensions=False, filter_exts=()): ''' Get the file in the QMimeData object md with an extension that is one of the extensions in exts. @@ -261,9 +261,9 @@ def dnd_get_files(md, exts, allow_all_extensions=False): local_files = [path_from_qurl(x) for x in urls] def is_ok(path): ext = posixpath.splitext(path)[1][1:].lower() - if allow_all_extensions and ext: + if allow_all_extensions and ext and ext not in filter_exts: return True - return ext in exts + return ext in exts and ext not in filter_exts local_files = [p for p in local_files if is_ok(urllib.unquote(p))] local_files = [x for x in local_files if os.path.exists(x)] if local_files: diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index a62db32b26..4f16678235 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -8,7 +8,7 @@ import os, subprocess, errno, shutil, tempfile, sys from io import BytesIO from threading import Thread -from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter, QTransform +from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter, QTransform, QPixmap from calibre import fit_image, force_unicode from calibre.constants import iswindows, plugins, get_version from calibre.utils.config_base import tweaks @@ -71,6 +71,8 @@ def image_from_x(x): return image_from_data(x) if isinstance(x, bytearray): return image_from_data(bytes(x)) + if isinstance(x, QPixmap): + return x.toImage() raise TypeError('Unknown image src type: %s' % type(x)) def image_and_format_from_data(data):