[pygtk] gobject & metaclasses

Hrvoje Nikšić hrvoje.niksic at avl.com
Mon Oct 27 21:19:58 WST 2008


On Mon, 2008-10-27 at 10:20 +0100, Alessandro Dentella wrote:
> I had this idea and I tryed what follows that in my idea is what you
> suggest, changes the error...
> 
>    import gobject
> 
>    class Dummy(type, gobject.GObject):
>        def __new__(cls, name, bases, attrs):
> 	   return type.__new__(cls, name, bases, attrs)

You cannot inherit from both type and gobject.GObject, but it's not very
useful anyway since gobject.GObject is not a metatype (it's a metatype
*instance*).  If I understand you correctly, you want to use a custom
metaclass with GObject.  In that case you need to manually create the
"mixed" metaclass.

class Dummy(type):
    ... your original metaclass ...

# this class mixes GObject's metaclass and your metaclass.
# note that GObjectMeta is simply type(GObject)
class DummyGObjectMeta(Dummy, gobject.GObjectMeta):
    pass

class A(gobject.GObject):
    __metaclass__ = DummyGObjectMeta

>>> A()
<A object at 0x81c370c (GObject at 0x821f790)>



More information about the pygtk mailing list