mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Removed unused imports
This commit is contained in:
parent
fa1c4bffaf
commit
43e2c92802
|
@ -18,20 +18,23 @@
|
||||||
|
|
||||||
import PIL
|
import PIL
|
||||||
from PIL._util import isPath
|
from PIL._util import isPath
|
||||||
import sys
|
|
||||||
|
|
||||||
qt_is_installed = True
|
qt_is_installed = True
|
||||||
|
qt_version = None
|
||||||
try:
|
try:
|
||||||
from PyQt5.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
|
from PyQt5.QtGui import QImage, qRgba, QPixmap
|
||||||
from PyQt5.QtCore import QBuffer, QIODevice
|
from PyQt5.QtCore import QBuffer, QIODevice
|
||||||
|
qt_version = '5'
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from PyQt4.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
|
from PyQt4.QtGui import QImage, qRgba, QPixmap
|
||||||
from PyQt4.QtCore import QBuffer, QIODevice
|
from PyQt4.QtCore import QBuffer, QIODevice
|
||||||
|
qt_version = '4'
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from PySide.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
|
from PySide.QtGui import QImage, qRgba, QPixmap
|
||||||
from PySide.QtCore import QBuffer, QIODevice
|
from PySide.QtCore import QBuffer, QIODevice
|
||||||
|
qt_version = 'side'
|
||||||
except ImportError:
|
except ImportError:
|
||||||
qt_is_installed = False
|
qt_is_installed = False
|
||||||
|
|
||||||
|
@ -123,23 +126,6 @@ def _toqclass_helper(im):
|
||||||
'data': __data, 'im': im, 'format': format, 'colortable': colortable
|
'data': __data, 'im': im, 'format': format, 'colortable': colortable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def toqimage(im):
|
|
||||||
return ImageQt(im)
|
|
||||||
|
|
||||||
|
|
||||||
def toqpixmap(im):
|
|
||||||
# This doesn't work. For now using a dumb approach.
|
|
||||||
# im_data = _toqclass_helper(im)
|
|
||||||
# result = QPixmap(im_data['im'].size[0], im_data['im'].size[1])
|
|
||||||
# result.loadFromData(im_data['data'])
|
|
||||||
# Fix some strange bug that causes
|
|
||||||
if im.mode == 'RGB':
|
|
||||||
im = im.convert('RGBA')
|
|
||||||
qimage = im.toqimage()
|
|
||||||
qimage.save('/tmp/hopper_{}_qpixmap_qimage.png'.format(im.mode))
|
|
||||||
return QPixmap.fromImage(qimage)
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage
|
# An PIL image wrapper for Qt. This is a subclass of PyQt4's QImage
|
||||||
# class.
|
# class.
|
||||||
|
@ -157,4 +143,21 @@ if qt_is_installed:
|
||||||
im_data['format']
|
im_data['format']
|
||||||
)
|
)
|
||||||
if im_data['colortable']:
|
if im_data['colortable']:
|
||||||
self.setColorTable(im_data['colortable'])
|
self.setColorTable(im_data['colortable'])
|
||||||
|
|
||||||
|
|
||||||
|
def toqimage(im):
|
||||||
|
return ImageQt(im)
|
||||||
|
|
||||||
|
|
||||||
|
def toqpixmap(im):
|
||||||
|
# This doesn't work. For now using a dumb approach.
|
||||||
|
# im_data = _toqclass_helper(im)
|
||||||
|
# result = QPixmap(im_data['im'].size[0], im_data['im'].size[1])
|
||||||
|
# result.loadFromData(im_data['data'])
|
||||||
|
# Fix some strange bug that causes
|
||||||
|
if im.mode == 'RGB':
|
||||||
|
im = im.convert('RGBA')
|
||||||
|
qimage = toqimage(im)
|
||||||
|
qimage.save('/tmp/hopper_{}_qpixmap_qimage.png'.format(im.mode))
|
||||||
|
return QPixmap.fromImage(qimage)
|
|
@ -1,16 +1,13 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
from test_imageqt import PillowQtTestCase
|
from test_imageqt import PillowQtTestCase
|
||||||
|
|
||||||
from PIL import Image, ImageQt
|
from PIL import ImageQt
|
||||||
|
|
||||||
if ImageQt.qt_is_installed:
|
|
||||||
from PIL.ImageQt import QImage
|
|
||||||
|
|
||||||
|
|
||||||
class TestFromQImage(PillowQtTestCase, PillowTestCase):
|
class TestFromQImage(PillowQtTestCase, PillowTestCase):
|
||||||
|
|
||||||
def roundtrip(self, expected):
|
def roundtrip(self, expected):
|
||||||
result = Image.fromqimage(expected.toqimage())
|
result = ImageQt.fromqimage(expected.toqimage())
|
||||||
# Qt saves all images as rgb
|
# Qt saves all images as rgb
|
||||||
self.assert_image_equal(result, expected.convert('RGB'))
|
self.assert_image_equal(result, expected.convert('RGB'))
|
||||||
|
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
from test_imageqt import PillowQPixmapTestCase
|
from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase
|
||||||
|
|
||||||
from PIL import Image, ImageQt
|
from PIL import ImageQt
|
||||||
|
|
||||||
if ImageQt.qt_is_installed:
|
|
||||||
from PIL.ImageQt import QPixmap
|
|
||||||
|
|
||||||
|
|
||||||
class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase):
|
class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase):
|
||||||
|
|
||||||
def roundtrip(self, expected):
|
def roundtrip(self, expected):
|
||||||
result = Image.fromqpixmap(expected.toqpixmap())
|
PillowQtTestCase.setUp(self)
|
||||||
|
result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
|
||||||
# Qt saves all pixmaps as rgb
|
# Qt saves all pixmaps as rgb
|
||||||
self.assert_image_equal(result, expected.convert('RGB'))
|
self.assert_image_equal(result, expected.convert('RGB'))
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ if ImageQt.qt_is_installed:
|
||||||
class TestToQImage(PillowQtTestCase, PillowTestCase):
|
class TestToQImage(PillowQtTestCase, PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
PillowQtTestCase.setUp(self)
|
||||||
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
|
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
|
||||||
data = ImageQt.toqimage(hopper(mode))
|
data = ImageQt.toqimage(hopper(mode))
|
||||||
data.save('/tmp/hopper_{}_qimage.png'.format(mode))
|
data.save('/tmp/hopper_{}_qimage.png'.format(mode))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase, hopper
|
||||||
from test_imageqt import PillowQPixmapTestCase
|
from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase
|
||||||
|
|
||||||
from PIL import ImageQt
|
from PIL import ImageQt
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ if ImageQt.qt_is_installed:
|
||||||
class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase):
|
class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase):
|
||||||
|
|
||||||
def test_sanity(self):
|
def test_sanity(self):
|
||||||
|
PillowQtTestCase.setUp(self)
|
||||||
QPixmap('Tests/images/hopper.ppm').save(
|
QPixmap('Tests/images/hopper.ppm').save(
|
||||||
'/tmp/hopper_RGB_qpixmap_file.png')
|
'/tmp/hopper_RGB_qpixmap_file.png')
|
||||||
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
|
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from helper import unittest, PillowTestCase, hopper
|
from helper import unittest, PillowTestCase
|
||||||
|
|
||||||
from PIL import ImageQt
|
from PIL import ImageQt
|
||||||
|
|
||||||
|
|
||||||
if ImageQt.qt_is_installed:
|
if ImageQt.qt_is_installed:
|
||||||
from PIL.ImageQt import QGuiApplication, QImage, qRgb, qRgba
|
from PIL.ImageQt import qRgba
|
||||||
|
|
||||||
def skip_if_qt_is_not_installed(_):
|
def skip_if_qt_is_not_installed(_):
|
||||||
pass
|
pass
|
||||||
|
@ -16,26 +16,25 @@ else:
|
||||||
class PillowQtTestCase:
|
class PillowQtTestCase:
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
try:
|
|
||||||
from PyQt5.QtGui import QImage, qRgb, qRgba
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
from PyQt4.QtGui import QImage, qRgb, qRgba
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
from PySide.QtGui import QImage, qRgb, qRgba
|
|
||||||
except ImportError:
|
|
||||||
self.skipTest('PyQt4 or 5 or PySide not installed')
|
|
||||||
skip_if_qt_is_not_installed(self)
|
skip_if_qt_is_not_installed(self)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PillowQPixmapTestCase(PillowQtTestCase):
|
class PillowQPixmapTestCase(PillowQtTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
PillowQtTestCase.setUp(self)
|
PillowQtTestCase.setUp(self)
|
||||||
|
try:
|
||||||
|
if ImageQt.qt_version == '5':
|
||||||
|
from PyQt5.QtGui import QGuiApplication
|
||||||
|
elif ImageQt.qt_version == '4':
|
||||||
|
from PyQt4.QtGui import QGuiApplication
|
||||||
|
elif ImageQt.qt_version == 'side':
|
||||||
|
from PySide.QtGui import QGuiApplication
|
||||||
|
except ImportError:
|
||||||
|
self.skipTest('QGuiApplication not installed')
|
||||||
|
|
||||||
self.app = QGuiApplication([])
|
self.app = QGuiApplication([])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -50,6 +49,12 @@ class TestImageQt(PillowQtTestCase, PillowTestCase):
|
||||||
# typedef QRgb
|
# typedef QRgb
|
||||||
# An ARGB quadruplet on the format #AARRGGBB,
|
# An ARGB quadruplet on the format #AARRGGBB,
|
||||||
# equivalent to an unsigned int.
|
# equivalent to an unsigned int.
|
||||||
|
if ImageQt.qt_version == '5':
|
||||||
|
from PyQt5.QtGui import qRgb
|
||||||
|
elif ImageQt.qt_version == '4':
|
||||||
|
from PyQt4.QtGui import qRgb
|
||||||
|
elif ImageQt.qt_version == 'side':
|
||||||
|
from PySide.QtGui import qRgb
|
||||||
|
|
||||||
self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255))
|
self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user