diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 2ded37c09..bd93828ef 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -1,7 +1,16 @@ from .helper import PillowTestCase, hopper -from PIL import ImageQt +import warnings +deprecated = False +with warnings.catch_warnings(): + warnings.filterwarnings("error", category=DeprecationWarning) + try: + from PIL import ImageQt + except DeprecationWarning: + deprecated = True + warnings.filterwarnings("ignore", category=DeprecationWarning) + from PIL import ImageQt if ImageQt.qt_is_installed: from PIL.ImageQt import qRgba @@ -78,3 +87,6 @@ class TestImageQt(PillowQtTestCase, PillowTestCase): def test_image(self): for mode in ('1', 'RGB', 'RGBA', 'L', 'P'): ImageQt.ImageQt(hopper(mode)) + + def test_deprecated(self): + self.assertEqual(ImageQt.qt_version in ["4", "side"], deprecated) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index b8131ac05..bc4e83161 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -12,6 +12,17 @@ Deprecated features Below are features which are considered deprecated. Where appropriate, a ``DeprecationWarning`` is issued. +PyQt4 and PySide +~~~~~~~~~~~~~~~~ + +.. deprecated:: 6.0.0 + +Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since +2018-08-31 and PySide since 2015-10-14. + +Support for PyQt4 and PySide has been deprecated from ``ImageQt`` and will be removed in +a future version. Please upgrade to PyQt5 or PySide2. + PIL.*ImagePlugin.__version__ attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/reference/ImageQt.rst b/docs/reference/ImageQt.rst index 386401075..5128f28fb 100644 --- a/docs/reference/ImageQt.rst +++ b/docs/reference/ImageQt.rst @@ -7,6 +7,12 @@ The :py:mod:`ImageQt` module contains support for creating PyQt4, PyQt5, PySide or PySide2 QImage objects from PIL images. +Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since +2018-08-31 and PySide since 2015-10-14. + +Support for PyQt4 and PySide is deprecated since Pillow 6.0.0 and will be removed in a +future version. Please upgrade to PyQt5 or PySide2. + .. versionadded:: 1.1.6 .. py:class:: ImageQt.ImageQt(image) diff --git a/docs/releasenotes/6.0.0.rst b/docs/releasenotes/6.0.0.rst index e1fa83cce..9fbb3d69a 100644 --- a/docs/releasenotes/6.0.0.rst +++ b/docs/releasenotes/6.0.0.rst @@ -32,6 +32,18 @@ API Changes Deprecations ^^^^^^^^^^^^ +PyQt4 and PySide +~~~~~~~~~~~~~~~~ + +Qt 4 reached end-of-life on 2015-12-19. Its Python bindings are also EOL: PyQt4 since +2018-08-31 and PySide since 2015-10-14. + +Support for PyQt4 and PySide has been deprecated from ``ImageQt`` and will be removed in +a future version. Please upgrade to PyQt5 or PySide2. + +PIL.*ImagePlugin.__version__ attributes +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + These version constants have been deprecated and will be removed in a future version. diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index b747781c5..02ce6354e 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -20,6 +20,7 @@ from . import Image from ._util import isPath, py3 from io import BytesIO import sys +import warnings qt_versions = [ ['5', 'PyQt5'], @@ -27,6 +28,12 @@ qt_versions = [ ['4', 'PyQt4'], ['side', 'PySide'] ] + +WARNING_TEXT = ( + "Support for EOL {} is deprecated and will be removed in a future version. " + "Please upgrade to PyQt5 or PySide2." +) + # If a version has already been imported, attempt it first qt_versions.sort(key=lambda qt_version: qt_version[1] in sys.modules, reverse=True) @@ -41,9 +48,13 @@ for qt_version, qt_module in qt_versions: elif qt_module == 'PyQt4': from PyQt4.QtGui import QImage, qRgba, QPixmap from PyQt4.QtCore import QBuffer, QIODevice + + warnings.warn(WARNING_TEXT.format(qt_module), DeprecationWarning) elif qt_module == 'PySide': from PySide.QtGui import QImage, qRgba, QPixmap from PySide.QtCore import QBuffer, QIODevice + + warnings.warn(WARNING_TEXT.format(qt_module), DeprecationWarning) except (ImportError, RuntimeError): continue qt_is_installed = True @@ -67,7 +78,7 @@ def fromqimage(im): """ buffer = QBuffer() buffer.open(QIODevice.ReadWrite) - # preserve alha channel with png + # preserve alpha channel with png # otherwise ppm is more friendly with Image.open if im.hasAlphaChannel(): im.save(buffer, 'png')