diff options
Diffstat (limited to 'tests/QtGui/bug_1124.py')
-rw-r--r-- | tests/QtGui/bug_1124.py | 104 |
1 files changed, 48 insertions, 56 deletions
diff --git a/tests/QtGui/bug_1124.py b/tests/QtGui/bug_1124.py index 63fccf3..3f2e772 100644 --- a/tests/QtGui/bug_1124.py +++ b/tests/QtGui/bug_1124.py @@ -1,66 +1,58 @@ ''' unit test for BUG #1124 ''' import unittest -from helper import UsesQApplication -from PySide import QtCore, QtGui -import sys +from PySide import QtGui, QtCore +import itertools -class MyWidget(QtGui.QWidget): - def __init__(self, parent=None, app=None): - super(MyWidget, self).__init__(parent) - if not app: - app = QApplication([]) +class TestBug1124(unittest.TestCase): + def test_bug_1124(self): + a = QtGui.QApplication([]) + allBlack = QtGui.QPixmap(10, 6) + halfHalf = QtGui.QPixmap(2, 2) - self.app = app + hhp = QtGui.QPainter(halfHalf) + hhp.fillRect(QtCore.QRect(0, 0, 1, 2), QtGui.QColor.fromRgbF(0, 1, 0)) + hhp.fillRect(QtCore.QRect(1, 0, 1, 2), QtGui.QColor.fromRgbF(0, 0, 1)) + del hhp - def paintEvent(self, event): - pa = QtGui.QPainter(self) fragments = [] - - makeFragment = lambda *a, **kw: \ - fragments.append(QtGui.QPainter.PixmapFragment.create(*a, **kw)) - - makeFragment(QtCore.QPointF(0, 0), QtCore.QRectF(0, 0, 2, 2)) - makeFragment(QtCore.QPointF(2, 0), QtCore.QRectF(0, 0, 2, 2), - rotation=90) - makeFragment(QtCore.QPointF(4, 0), QtCore.QRectF(0, 0, 2, 2), - rotation=180) - makeFragment(QtCore.QPointF(6, 0), QtCore.QRectF(0, 0, 1, 1), - scaleX=2, scaleY=2) - makeFragment(QtCore.QPointF(8, 0), QtCore.QRectF(1, 0, 1, 1), - scaleX=2, scaleY=2) - makeFragment(QtCore.QPointF(0, 2), QtCore.QRectF(0, 0, 2, 2), - opacity=0.5) - makeFragment(QtCore.QPointF(2, 2), QtCore.QRectF(0, 0, 2, 2), - scaleX=2, scaleY=2) - makeFragment(QtCore.QPointF(6, 2), QtCore.QRectF(0, 0, 2, 2), - scaleX=2, scaleY=2, rotation=90, opacity=0.5) - - try: - pa.drawPixmapFragments(fragments, QtGui.QPixmap(2, 2), 0) - except TypeError: - sys.exit(-1) - - # test pa.drawPixmapFragments() by passing a tuple of integers rather - # than QtGui.QPainter.PixmapFragment's that _must_ throw a TypeError - # exception. - try: - pa.drawPixmapFragments((1, 2, 3), QtGui.QPixmap(2, 2), 0) - sys.exit(-1) # it should not reach here - except TypeError: - pass - -class QPainterTestCase(UsesQApplication): - qapplication = True - - def setUp(self): - super(QPainterTestCase, self).setUp() - self.wid = MyWidget(app=self.app) - - def testIt(self): - QtCore.QTimer.singleShot(200, self.app.quit) - self.wid.show() - self.app.exec_() + mf = lambda *a, **kw: fragments.append(QtGui.QPainter.PixmapFragment.create(*a, **kw)) + + mf(QtCore.QPointF(1, 1), QtCore.QRectF(0, 0, 2, 2)) + mf(QtCore.QPointF(3, 1), QtCore.QRectF(0, 0, 2, 2), rotation=90) + mf(QtCore.QPointF(5, 1), QtCore.QRectF(0, 0, 2, 2), rotation=180) + mf(QtCore.QPointF(7, 1), QtCore.QRectF(0, 0, 1, 1), scaleX=2, scaleY=2) + mf(QtCore.QPointF(9, 1), QtCore.QRectF(1, 0, 1, 1), scaleX=2, scaleY=2) + mf(QtCore.QPointF(1, 3), QtCore.QRectF(0, 0, 2, 2), opacity=0.5) + mf(QtCore.QPointF(4, 4), QtCore.QRectF(0, 0, 2, 2), scaleX=2, scaleY=2) + mf(QtCore.QPointF(8, 4), QtCore.QRectF(0, 0, 2, 2), scaleX=2, scaleY=2, rotation=90, opacity=0.5) + + allBlack.fill(QtGui.QColor("black")) + + abp = QtGui.QPainter(allBlack) + abp.drawPixmapFragments(fragments, halfHalf) + del abp + + image = allBlack.toImage() + + colors = {"G": QtGui.QColor.fromRgbF(0, 1, 0).rgb(), + "B": QtGui.QColor.fromRgbF(0, 0, 1).rgb(), + "g": QtGui.QColor.fromRgbF(0, 0.499, 0).rgb(), + "b": QtGui.QColor.fromRgbF(0, 0, 0.499).rgb(), + "0": QtGui.QColor("black").rgb()} + + lines = ["GBGGBGGGBB", + "GBBBBGGGBB", + "gbGGBBgggg", + "gbGGBBgggg", + "00GGBBbbbb", + "00GGBBbbbb"] + + for x, y in itertools.product(range(10), range(6)): + c = colors[lines[y][x]] + assert c == image.pixel(QtCore.QPoint(x, y)) + + del a if __name__ == "__main__": unittest.main() |