summaryrefslogtreecommitdiff
path: root/examples/properties.py
blob: cc05920621c85bbb4e4abf82acbe1c8ccc3d0c20 (plain)
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
import gobject

class MyObject(gobject.GObject):

    foo = gobject.property(type=str, default='bar')
    boolprop = gobject.property(type=bool, default=False)

    def __init__(self):
        gobject.GObject.__init__(self)

    @gobject.property
    def readonly(self):
        return 'readonly'

gobject.type_register(MyObject)

print "MyObject properties: ", list(MyObject.props)

obj = MyObject()

print "obj.foo ==", obj.foo

obj.foo = 'spam'
print "obj.foo = spam"

print "obj.foo == ", obj.foo

print "obj.boolprop == ", obj.boolprop

print obj.readonly
obj.readonly = 'does-not-work'