Ensure that the imageformat Qt plugins are loaded even when no QApplication is created

This commit is contained in:
Kovid Goyal 2016-06-24 21:57:15 +05:30
parent 48f4670ed5
commit a182438cba
2 changed files with 13 additions and 4 deletions

View File

@ -6,8 +6,5 @@ env:
before_install: before_install:
- curl https://download.calibre-ebook.com/travis/sw-linux.tar.xz | tar xJ -C $HOME - curl https://download.calibre-ebook.com/travis/sw-linux.tar.xz | tar xJ -C $HOME
- $QMAKE -query
- ldd $SW/qt/plugins/imageformats/libqjpeg.so
- python -c "import os, sys; os.environ['QT_DEBUG_PLUGINS']='1'; from PyQt5.Qt import *; print QLibraryInfo.location(QLibraryInfo.PluginsPath); fmts = map(str, QImageReader.supportedImageFormats()); print fmts; sys.exit('jpg' not in fmts)"
- python setup.py bootstrap --ephemeral - python setup.py bootstrap --ephemeral
script: python setup.py test script: python setup.py test

View File

@ -4,17 +4,29 @@
from __future__ import (unicode_literals, division, absolute_import, from __future__ import (unicode_literals, division, absolute_import,
print_function) print_function)
from future_builtins import map
import os, subprocess, errno, shutil, tempfile, sys import os, subprocess, errno, shutil, tempfile, sys
from io import BytesIO from io import BytesIO
from threading import Thread 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, QCoreApplication, QProcessEnvironment
from calibre import fit_image, force_unicode from calibre import fit_image, force_unicode
from calibre.constants import iswindows, plugins, get_version from calibre.constants import iswindows, plugins, get_version
from calibre.utils.config_base import tweaks from calibre.utils.config_base import tweaks
from calibre.utils.filenames import atomic_rename from calibre.utils.filenames import atomic_rename
# Ensure that Qt can load the imageformat plugins
if QCoreApplication.instance() is None:
# Normally constructing a QCoreApplication takes care of this, but if we
# are being used without a QCoreApplication, then we have to do it manually
if len(set(b'jpeg gif png'.split(b' ')).intersection(set(map(bytes, QImageReader.supportedImageFormats())))) != 3:
qpp = QProcessEnvironment.systemEnvironment().value('QT_PLUGIN_PATH')
if qpp:
for path in qpp.split(os.pathsep):
QCoreApplication.addLibraryPath(path)
# Utilities {{{ # Utilities {{{
imageops, imageops_err = plugins['imageops'] imageops, imageops_err = plugins['imageops']
if imageops is None: if imageops is None: