mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Merge pull request #3655 from hugovk/deprecate-eol-qt
Deprecate support for PyQt4 and PySide
This commit is contained in:
commit
5d9898b686
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user