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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import sys
from PyQt5 import QtCore
sys.path.append(sys.argv[1])
import PyTest.CppLib
mo = PyTest.CppLib.MyObject()
assert(mo.addThree(39) == 42)
assert(mo.addThree([38, 39, 40]) == [41, 42, 43])
assert(mo.addThree("SomeString") == "DefaultSomeStringThree")
assert(mo.findNeedle(["One", "Two", "Three"], "Two") == 1)
assert(mo.findNeedle(["One", "Two", "Three"], "Four") == -1)
assert(mo.findNeedle(["One", "Two", "Three"], "Th") == 2)
assert(mo.findNeedle(["One", "Two", "Three"], "Th", QtCore.Qt.MatchExactly) == -1)
assert(mo.const_parameters(30) == 15)
assert(mo.const_parameters(30, mo) == 10)
assert(mo.qtEnumTest(QtCore.Qt.MatchContains | QtCore.Qt.MatchStartsWith) == 3)
assert(mo.localEnumTest(PyTest.CppLib.MyObject.Val2) == 2)
#
# Verify that an enum with attributes can be read.
#
assert(PyTest.CppLib.Foo == 0)
assert(PyTest.CppLib.Bar == 2)
class Reactor(QtCore.QObject):
def __init__(self, obj):
QtCore.QObject.__init__(self)
self.gotPrivateSlotCalledSignal = False
self.gotProtectedSlotCalledSignal = False
self.gotPublicSlotCalledSignal = False
obj.privateSlotCalled.connect(self.react_to_privateSlotCalled)
obj.protectedSlotCalled.connect(self.react_to_protectedSlotCalled)
obj.publicSlotCalled.connect(self.react_to_publicSlotCalled)
def react_to_privateSlotCalled(self):
self.gotPrivateSlotCalledSignal = True
def react_to_protectedSlotCalled(self):
self.gotProtectedSlotCalledSignal = True
def react_to_publicSlotCalled(self):
self.gotPublicSlotCalledSignal = True
class Emitter(QtCore.QObject):
privateTrigger = QtCore.pyqtSignal()
protectedTrigger = QtCore.pyqtSignal()
publicTrigger = QtCore.pyqtSignal()
def __init__(self, obj):
QtCore.QObject.__init__(self)
self.privateTrigger.connect(obj.privateSlot1)
self.protectedTrigger.connect(obj.protectedSlot1)
self.publicTrigger.connect(obj.publicSlot1)
def emitSignalForPublic(self):
self.publicTrigger.emit()
def emitSignalForPrivate(self):
self.privateTrigger.emit()
def emitSignalForProtected(self):
self.protectedTrigger.emit()
e = Emitter(mo)
r = Reactor(mo)
assert(not r.gotPrivateSlotCalledSignal)
assert(not r.gotProtectedSlotCalledSignal)
assert(not r.gotPublicSlotCalledSignal)
e.emitSignalForPrivate()
assert(r.gotPrivateSlotCalledSignal)
e.emitSignalForProtected()
assert(r.gotProtectedSlotCalledSignal)
e.emitSignalForPublic()
assert(r.gotPublicSlotCalledSignal)
assert(PyTest.CppLib.SomeNS.EnumValueOne == 1)
assert(PyTest.CppLib.SomeNS.EnumValueTwo == 2)
assert(PyTest.CppLib.SomeNS.useEnum() == 1.0)
assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueOne) == 1.0)
assert(PyTest.CppLib.SomeNS.useEnum(PyTest.CppLib.SomeNS.EnumValueTwo) == 2.0)
assert(PyTest.CppLib.SomeNS.customMethod([2, 3, 5]) == 10)
assert(PyTest.CppLib.anotherCustomMethod([2, 3, 5]) == 52)
|