1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
''' unit test for BUG #1124 '''
import unittest
from helper import UsesQApplication
from PySide import QtCore, QtGui
import sys
class MyWidget(QtGui.QWidget):
def __init__(self, parent=None, app=None):
super(MyWidget, self).__init__(parent)
if not app:
app = QApplication([])
self.app = app
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_()
if __name__ == "__main__":
unittest.main()
|