Removed unused imports

This commit is contained in:
Andrew Murray 2015-06-19 15:35:56 +10:00
parent fa1c4bffaf
commit 43e2c92802
6 changed files with 52 additions and 47 deletions

View File

@ -18,20 +18,23 @@
import PIL
from PIL._util import isPath
import sys
qt_is_installed = True
qt_version = None
try:
from PyQt5.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
from PyQt5.QtGui import QImage, qRgba, QPixmap
from PyQt5.QtCore import QBuffer, QIODevice
qt_version = '5'
except ImportError:
try:
from PyQt4.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
from PyQt4.QtGui import QImage, qRgba, QPixmap
from PyQt4.QtCore import QBuffer, QIODevice
qt_version = '4'
except ImportError:
try:
from PySide.QtGui import QGuiApplication, QImage, qRgb, qRgba, QPixmap
from PySide.QtGui import QImage, qRgba, QPixmap
from PySide.QtCore import QBuffer, QIODevice
qt_version = 'side'
except ImportError:
qt_is_installed = False
@ -123,23 +126,6 @@ def _toqclass_helper(im):
'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
# class.
@ -157,4 +143,21 @@ if qt_is_installed:
im_data['format']
)
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)

View File

@ -1,16 +1,13 @@
from helper import unittest, PillowTestCase, hopper
from test_imageqt import PillowQtTestCase
from PIL import Image, ImageQt
if ImageQt.qt_is_installed:
from PIL.ImageQt import QImage
from PIL import ImageQt
class TestFromQImage(PillowQtTestCase, PillowTestCase):
def roundtrip(self, expected):
result = Image.fromqimage(expected.toqimage())
result = ImageQt.fromqimage(expected.toqimage())
# Qt saves all images as rgb
self.assert_image_equal(result, expected.convert('RGB'))

View File

@ -1,16 +1,14 @@
from helper import unittest, PillowTestCase, hopper
from test_imageqt import PillowQPixmapTestCase
from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase
from PIL import Image, ImageQt
if ImageQt.qt_is_installed:
from PIL.ImageQt import QPixmap
from PIL import ImageQt
class TestFromQPixmap(PillowQPixmapTestCase, PillowTestCase):
def roundtrip(self, expected):
result = Image.fromqpixmap(expected.toqpixmap())
PillowQtTestCase.setUp(self)
result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
# Qt saves all pixmaps as rgb
self.assert_image_equal(result, expected.convert('RGB'))

View File

@ -11,6 +11,7 @@ if ImageQt.qt_is_installed:
class TestToQImage(PillowQtTestCase, PillowTestCase):
def test_sanity(self):
PillowQtTestCase.setUp(self)
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
data = ImageQt.toqimage(hopper(mode))
data.save('/tmp/hopper_{}_qimage.png'.format(mode))

View File

@ -1,5 +1,5 @@
from helper import unittest, PillowTestCase, hopper
from test_imageqt import PillowQPixmapTestCase
from test_imageqt import PillowQtTestCase, PillowQPixmapTestCase
from PIL import ImageQt
@ -10,6 +10,7 @@ if ImageQt.qt_is_installed:
class TestToQPixmap(PillowQPixmapTestCase, PillowTestCase):
def test_sanity(self):
PillowQtTestCase.setUp(self)
QPixmap('Tests/images/hopper.ppm').save(
'/tmp/hopper_RGB_qpixmap_file.png')
for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):

View File

@ -1,10 +1,10 @@
from helper import unittest, PillowTestCase, hopper
from helper import unittest, PillowTestCase
from PIL import ImageQt
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(_):
pass
@ -16,26 +16,25 @@ else:
class PillowQtTestCase:
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)
def tearDown(self):
pass
class PillowQPixmapTestCase(PillowQtTestCase):
def 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([])
def tearDown(self):
@ -50,6 +49,12 @@ class TestImageQt(PillowQtTestCase, PillowTestCase):
# typedef QRgb
# An ARGB quadruplet on the format #AARRGGBB,
# 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))