Skip to content

Instantly share code, notes, and snippets.

@timo
Created January 19, 2012 19:27
Show Gist options
  • Save timo/1641976 to your computer and use it in GitHub Desktop.
Save timo/1641976 to your computer and use it in GitHub Desktop.
test case for pyside bug 1124
import unittest
from PySide import QtGui, QtCore
import itertools
class TestBug1124(unittest.TestCase):
def test_bug_1124(self):
a = QtGui.QApplication([])
all_black = QtGui.QPixmap(10, 6)
half_half = QtGui.QPixmap(2, 2)
hhp = QtGui.QPainter(half_half)
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
fragments = []
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)
all_black.fill(QtGui.QColor("black"))
abp = QtGui.QPainter(all_black)
abp.drawPixmapFragments(fragments, half_half)
del abp
image = all_black.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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment