Lorenzo Gil Sanchez schrieb:
Sorry, but I can't find the o.get_name and o.set_name methods in the
gtklabel.c file (or any other file). Could you please put an example or
give me some more detailed pointer?

These methods were meant as an abstract example for a property called 'name' (take GtkWidget as an example).


If you read through gtklabel.c you find that gtk_label_set_property is a static function which is assigned to the set_property function pointer.
Thus it is actually this function which is called by label->set_property(...).
But as you can see there is also one non-static function per property to set it, and actually gtk_label_set_property is only a wrapper for these functions.
The same is true for gtk_label_get_property.
Since these property specific functions also issue the notify signal it does not matter whether you call them directly or via label->set/get_property.


I attached a python example which was derived from the example included in James' source tree.
import gobject

class MyObject(gobject.GObject):
    __gproperties__ = {
        'foo': (gobject.TYPE_STRING, 'foo property', 'the foo of the object',
                'bar', gobject.PARAM_READWRITE)
    }

    def __init__(self):
        self.__gobject_init__()
        self._foo = 'bar'

    def do_set_property(self, pspec, value):
        if pspec.name == 'foo':
            self.set_foo(value)
        else:
            raise AttributeError, 'unknown property %s' % pspec.name

    def do_get_property(self, pspec):
        if pspec.name == 'foo':
            return self.get_foo()
        else:
            raise AttributeError, 'unknown property %s' % pspec.name

    def set_foo(self, value):
        self._foo = value
        self.notify("foo")

    def get_foo(self):
        return self._foo

gobject.type_register(MyObject)

print "MyObject properties: ", gobject.list_properties(MyObject)

def notify_cb(object, pspec):
    print "Property '" + pspec.name + "' changed to '" + 
object.get_property(pspec.name) + "'"

obj = MyObject()
obj.connect("notify", notify_cb)

print "foo: ", obj.get_property("foo")
obj.set_property('foo', 'spam')
print "foo: ", obj.get_property('foo')
obj.set_foo('spam2')
print "foo: ", obj.get_foo()
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to