Re: GObject constructor
| From: | Andrei Zmievski | Date: | Sun, 15 Oct 2006 00:45:58 +0000 |
| Subject: | Re: GObject constructor | ||
| References: | 1 2 3 4 | Groups: | php.gtk.dev |
| Request: | Send a blank email to php-gtk-dev+get-3476@lists.php.net to get a copy of this message | ||
If all you want to do is create some custom properties or signals, it's not that bad. Probably a few hours of work and then you can do this (PyGTK example):
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)
and
class C(gobject.GObject):
__gsignals__ = {
'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
(gobject.TYPE_INT,))
}
def __init__(self):
self.__gobject_init__() # default constructor using our new GType
def do_my_signal(self, arg):
print "C: class closure for `my_signal' called with argument", arg
gobject.type_register(C)
class D(C):
def do_my_signal(self, arg):
print "D: class closure for `my_signal' called. Chaining up to C"
C.do_my_signal(self, arg)
gobject.type_register(D)
def my_signal_handler(object, arg, *extra):
print "handler for `my_signal' called with argument", arg, \
"and extra args", extra
inst = C()
inst2 = D()
inst.connect("my_signal", my_signal_handler, 1, 2, 3)
inst.emit("my_signal", 42)
inst2.emit("my_signal", 42)
The difficult case is when you actually want to override methods like GtkContainer::add/remove. PyGTK supports that (and so can we), but that's a lot more work.
-Andrei
On Oct 14, 2006, at 4:58 PM, Steph Fox wrote:
The question is more, how would the type be recognised without re-compiling GTK+? I'm seriously bemused as to how you could allow the possibility of custom widgets in PHP-GTK without making some special wrapper for GObject (at C level)... what am I missing? ----- Original Message ----- From: "Christian Weiske" <cweiske@cweiske.de> To: "PHP-GTK Dev list" <php-gtk-dev@lists.php.net> Sent: Sunday, October 15, 2006 2:00 AM Subject: Re: [PHP-GTK-DEV] GObject constructor --PHP-GTK Development Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php