summaryrefslogtreecommitdiffstats
path: root/examples/properties.py
diff options
context:
space:
mode:
authorJames Henstridge <james@daa.com.au>2001-12-18 08:19:51 +0000
committerJames Henstridge <jamesh@src.gnome.org>2001-12-18 08:19:51 +0000
commitb98d703df4f7837c2ed5359e85d158bec880bd30 (patch)
tree29b00f83345c36acfcebad29afffb85b2fd20dd6 /examples/properties.py
parent6bd8ae3492a556aed7653c7f5da2bfd6edca402f (diff)
downloadpygobject-b98d703df4f7837c2ed5359e85d158bec880bd30.tar.gz
pygobject-b98d703df4f7837c2ed5359e85d158bec880bd30.tar.xz
pygobject-b98d703df4f7837c2ed5359e85d158bec880bd30.zip
add new example to dist.
2001-12-18 James Henstridge <james@daa.com.au> * Makefile.am (EXTRA_DIST): add new example to dist. * examples/gobject/properties.py: test program that implements a few properties. * gobjectmodule.c (add_properties): new function for parsing the __gproperties__ class attribute. (create_property): helper routine for creating and installing the new pspecs. (pyg_type_register): add code to call add_properties if a __gproperties__ attribute is found. (pyg_object_class_init): set set_property/get_property methods in vtable, and get rid of debug message. (initgobject): add G_PARAM_* constants.
Diffstat (limited to 'examples/properties.py')
-rw-r--r--examples/properties.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/properties.py b/examples/properties.py
new file mode 100644
index 0000000..2d36afc
--- /dev/null
+++ b/examples/properties.py
@@ -0,0 +1,43 @@
+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),
+ }
+
+ 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.type_register(MyObject)
+
+print "MyObject properties: ", gobject.list_properties(MyObject)
+obj = MyObject()
+
+val = obj.get_property('foo')
+print "obj.get_property('foo') == ", val
+
+obj.set_property('foo', 'spam')
+print "obj.set_property('foo', 'spam')"
+
+val = obj.get_property('foo')
+print "obj.get_property('foo') == ", val
+
+val = obj.get_property('boolprop')
+print "obj.get_property('boolprop') == ", val