2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2013-11-21 10:19:28 +04:00
|
|
|
|
2019-02-16 04:36:10 +03:00
|
|
|
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
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
if ImageQt.qt_is_installed:
|
2015-06-19 08:35:56 +03:00
|
|
|
from PIL.ImageQt import qRgba
|
2014-09-15 22:24:56 +04:00
|
|
|
|
|
|
|
def skip_if_qt_is_not_installed(_):
|
|
|
|
pass
|
2019-06-13 18:54:46 +03:00
|
|
|
|
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
else:
|
2019-06-13 18:54:46 +03:00
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
def skip_if_qt_is_not_installed(test_case):
|
2019-06-13 18:54:46 +03:00
|
|
|
test_case.skipTest("Qt bindings are not installed")
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
|
2015-06-19 08:36:23 +03:00
|
|
|
class PillowQtTestCase(object):
|
2014-06-10 13:10:47 +04:00
|
|
|
def setUp(self):
|
2014-09-15 22:24:56 +04:00
|
|
|
skip_if_qt_is_not_installed(self)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
|
2015-06-19 08:36:23 +03:00
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
class PillowQPixmapTestCase(PillowQtTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
PillowQtTestCase.setUp(self)
|
2015-06-19 08:35:56 +03:00
|
|
|
try:
|
2019-06-13 18:54:46 +03:00
|
|
|
if ImageQt.qt_version == "5":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PyQt5.QtGui import QGuiApplication
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "4":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PyQt4.QtGui import QGuiApplication
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "side":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PySide.QtGui import QGuiApplication
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "side2":
|
2018-08-03 16:07:19 +03:00
|
|
|
from PySide2.QtGui import QGuiApplication
|
2015-06-19 08:35:56 +03:00
|
|
|
except ImportError:
|
2019-06-13 18:54:46 +03:00
|
|
|
self.skipTest("QGuiApplication not installed")
|
2015-06-19 08:36:23 +03:00
|
|
|
|
2014-09-15 22:24:56 +04:00
|
|
|
self.app = QGuiApplication([])
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
PillowQtTestCase.tearDown(self)
|
|
|
|
self.app.quit()
|
|
|
|
|
|
|
|
|
|
|
|
class TestImageQt(PillowQtTestCase, PillowTestCase):
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_rgb(self):
|
2018-06-23 03:58:41 +03:00
|
|
|
# from https://doc.qt.io/archives/qt-4.8/qcolor.html
|
2014-06-10 13:10:47 +04:00
|
|
|
# typedef QRgb
|
|
|
|
# An ARGB quadruplet on the format #AARRGGBB,
|
|
|
|
# equivalent to an unsigned int.
|
2019-06-13 18:54:46 +03:00
|
|
|
if ImageQt.qt_version == "5":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PyQt5.QtGui import qRgb
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "4":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PyQt4.QtGui import qRgb
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "side":
|
2015-06-19 08:35:56 +03:00
|
|
|
from PySide.QtGui import qRgb
|
2019-06-13 18:54:46 +03:00
|
|
|
elif ImageQt.qt_version == "side2":
|
2018-08-03 16:07:19 +03:00
|
|
|
from PySide2.QtGui import qRgb
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
self.assertEqual(qRgb(0, 0, 0), qRgba(0, 0, 0, 255))
|
|
|
|
|
|
|
|
def checkrgb(r, g, b):
|
|
|
|
val = ImageQt.rgb(r, g, b)
|
2019-06-13 18:54:46 +03:00
|
|
|
val = val % 2 ** 24 # drop the alpha
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(val >> 16, r)
|
2019-06-13 18:54:46 +03:00
|
|
|
self.assertEqual(((val >> 8) % 2 ** 8), g)
|
|
|
|
self.assertEqual(val % 2 ** 8, b)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
checkrgb(0, 0, 0)
|
|
|
|
checkrgb(255, 0, 0)
|
|
|
|
checkrgb(0, 255, 0)
|
|
|
|
checkrgb(0, 0, 255)
|
|
|
|
|
2015-06-19 11:23:17 +03:00
|
|
|
def test_image(self):
|
2019-06-13 18:54:46 +03:00
|
|
|
for mode in ("1", "RGB", "RGBA", "L", "P"):
|
2015-06-19 11:23:17 +03:00
|
|
|
ImageQt.ImageQt(hopper(mode))
|
2019-02-14 23:59:14 +03:00
|
|
|
|
|
|
|
def test_deprecated(self):
|
2019-02-16 04:36:10 +03:00
|
|
|
self.assertEqual(ImageQt.qt_version in ["4", "side"], deprecated)
|