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
signature.asc
Description: Digital signature
