I wrongly sent my answer offlist. Sending it again: -------------------- Thank you very much for this example.
Is it normal that you don't call clutter.Container method? Like: clutter.Container.do_add(). If I don't call clutter.Container's methods, what's the use of inheriting from clutter.Container? I was thinking I could leverage the existing implementation of clutter.Container's method. Cheers, Julien 2009/2/23 Bastian Winkler <[email protected]> > Hi Julien, > > take a look at this sample container which acts like a (very simple) > gtk.VBox container: > > > class SampleBox(clutter.Actor, clutter.Container): > __gtype_name__ = 'SampleBox' > def __init__(self): > clutter.Actor.__init__(self) > self._children = [] > > def do_add(self, actor): > self._children.append(actor) > actor.set_parent(self) > self.queue_relayout() > > def do_remove(self, actor): > if actor in self._children: > self._children.remove(actor) > actor.unparent() > self.queue_relayout() > > def do_allocate(self, box, absolute_origin_changed): > child_x = child_y = 0 > for actor in self._children: > x, y, w, h = actor.get_preferred_size() > child_box = clutter.ActorBox() > child_box.x1 = child_x > child_box.x2 = child_x + w > child_box.y1 = child_y > child_box.y2 = child_y + h > actor.allocate(child_box, absolute_origin_changed) > #child_x = child_box.x2 > child_y = child_box.y2 > clutter.Actor.do_allocate(self, box, absolute_origin_changed) > > def do_paint(self): > for actor in self._children: > actor.paint() > > > > On Mon, Feb 23, 2009 at 03:47:21PM +0100, Julien Pauty wrote: > > Hello, > > > > I'm trying to implement a container in python. > > > > I have something like this: > > > > class Cont(clutter.Actor, clutter.Container): > > > > __gtype_name__ = 'Cont' > > > > def __init__(self): > > clutter.Actor.__init__(self) > > clutter.Container.__init__(self) > > > > > > def do_add(self, child): > > clutter.Container.do_add(self, child) > > > > def do_remove(self, child): > > clutter.Container.do_remove(child) > > > > If try to build such a class I get the following error: > > > > clutter.Container.__init__(self) > > NotImplementedError: Cont can not be constructed > > > > I tried to provide some dummy method for the container, but this seems > > useless, since Container provides default implementations. > > > > I also tried to not call the __init__ method of container, which seems > > logical, since it's an interface. However, I get the following error when > I > > call do_add:. > > > > Warning: g_type_interface_peek: assertion `instance_class != NULL' > failed > > clutter.Container.do_add(self, child) > > > > This sounds like something is not initialized, but what ? > > > > So, what is the regular way to implement an interface ? > > > > Thanks, > > > > Julien > > -- > This is a free country. You have a right to send me email, and I have a > right > not to read them! > > GnuPG Fingerprint: 2FFF FC48 C7DF 1EA0 00A0 FD53 8C35 FD2E 6908 7B82 > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.9 (GNU/Linux) > > iEYEARECAAYFAkmiyZ4ACgkQjDX9LmkIe4KTTgCgquSqJ3QR08F9lTPfc2cmUboG > p8cAn3UCsiyxYbXmwFn9Yx50AW6l/eMP > =2SaY > -----END PGP SIGNATURE----- > >
