summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2007-05-01 15:54:05 +0000
committerJohan Dahlin <johan@src.gnome.org>2007-05-01 15:54:05 +0000
commita57fde73b509adcf56a73ae1fb97474d136fd2af (patch)
tree808278f44be0091211dd0113d6293ea0d6510583 /examples
parentecbf8b6315dda927f4f90d8651033eb67c46a187 (diff)
downloadpygobject-a57fde73b509adcf56a73ae1fb97474d136fd2af.tar.gz
Add a property helper, fixes #338098
* examples/properties.py: * gobject/Makefile.am: * gobject/__init__.py: * gobject/constants.py.in: * gobject/generate-constants.c: (main): * gobject/propertyhelper.py: * tests/Makefile.am: * tests/test_enum.py: * tests/test_interface.py: * tests/test_properties.py: Add a property helper, fixes #338098 svn path=/trunk/; revision=662
Diffstat (limited to 'examples')
-rw-r--r--examples/properties.py50
1 files changed, 19 insertions, 31 deletions
diff --git a/examples/properties.py b/examples/properties.py
index 2d36afc6..cc059206 100644
--- a/examples/properties.py
+++ b/examples/properties.py
@@ -1,43 +1,31 @@
import gobject
class MyObject(gobject.GObject):
- __gproperties__ = {
- 'foo': (gobject.TYPE_STRING, 'foo property', 'the foo of the object',
- 'bar', gobject.PARAM_READWRITE),
- 'boolprop': (gobject.TYPE_BOOLEAN, 'bool prop', 'a test boolean prop',
- 0, gobject.PARAM_READABLE),
- }
+
+ foo = gobject.property(type=str, default='bar')
+ boolprop = gobject.property(type=bool, default=False)
def __init__(self):
- self.__gobject_init__()
- self.foo = 'bar'
- def do_set_property(self, pspec, value):
- print ' do_set_property called for %s=%r' % (pspec.name, value)
- if pspec.name == 'foo':
- self.foo = value
- else:
- raise AttributeError, 'unknown property %s' % pspec.name
- def do_get_property(self, pspec):
- print ' do_get_property called for %s' % pspec.name
- if pspec.name == 'foo':
- return self.foo
- elif pspec.name == 'boolprop':
- return 1
- else:
- raise AttributeError, 'unknown property %s' % pspec.name
+ gobject.GObject.__init__(self)
+
+ @gobject.property
+ def readonly(self):
+ return 'readonly'
+
gobject.type_register(MyObject)
-print "MyObject properties: ", gobject.list_properties(MyObject)
+print "MyObject properties: ", list(MyObject.props)
+
obj = MyObject()
-val = obj.get_property('foo')
-print "obj.get_property('foo') == ", val
+print "obj.foo ==", obj.foo
+
+obj.foo = 'spam'
+print "obj.foo = spam"
-obj.set_property('foo', 'spam')
-print "obj.set_property('foo', 'spam')"
+print "obj.foo == ", obj.foo
-val = obj.get_property('foo')
-print "obj.get_property('foo') == ", val
+print "obj.boolprop == ", obj.boolprop
-val = obj.get_property('boolprop')
-print "obj.get_property('boolprop') == ", val
+print obj.readonly
+obj.readonly = 'does-not-work'