Implemented support to notify argument on Properties.

Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
          Marcelo Lira <marcelo.lira@openbossa.org>
This commit is contained in:
renatofilho 2010-10-21 13:15:04 -03:00
commit 26750d345c
10 changed files with 241 additions and 107 deletions

View file

@ -36,6 +36,21 @@ class MyObject(QObject):
pp = Property(int, readPP)
class MyObjectWithNotifyProperty(QObject):
def __init__(self, parent=None):
QObject.__init__(self, parent)
self.p = 0
def readP(self):
return self.p
def writeP(self, v):
self.p = v
self.notifyP.emit()
notifyP = Signal()
myProperty = Property(int, readP, fset=writeP, notify=notifyP)
class PropertyCase(unittest.TestCase):
'''Test case for QObject properties'''
@ -146,6 +161,25 @@ class PropertyWithConstructorCase(unittest.TestCase):
self.assertEqual(o.pp, 42)
self.assertRaises(AttributeError, o.trySetPP)
class PropertyWithNotify(unittest.TestCase):
def called(self):
self.called_ = True
def testMetaData(self):
obj = MyObjectWithNotifyProperty()
mo = obj.metaObject()
self.assertEqual(mo.propertyCount(), 2)
p = mo.property(1)
self.assertEqual(p.name(), "myProperty")
self.assert_(p.hasNotifySignal())
def testNotify(self):
self.called_ = False
obj = MyObjectWithNotifyProperty()
obj.notifyP.connect(self.called)
obj.myProperty = 10
self.assert_(self.called_)
if __name__ == '__main__':
unittest.main()