On Thu, Oct 9, 2008 at 3:36 AM, Lucio Torre <[EMAIL PROTECTED]> wrote:
> so, we could remove that class. or move the "enable handlers on
> 'on_enter'" to that class so all nodes can be event handlers if one
> wants to and fix the order.

I gave a look on that and it seems to me that fixing the order is
non-trivial and should be done carefully. First the reason why
EventHandlerMixin never gets used is because Layer.add doesn't exist,
so when one calls .add on a layer instance the method is not found on
the class and the CocosNode.add is called instead. As CocosNode.add
doesn't call super(CocosNode, self).add, the call ends there and
EventHandlerMixin never do it's work.

However, just adding a super(CocosNode, self).add call on CocosNode
doesn't work because, aparently, when you do this the MRO used to call
the add method is the MRO of CocosNode class. This makes the program
try to call object.add, wich doesn't exist.

Adding an add method to Layer class wich just calls super(Layer,
self).add fixes this and all the classes on Layer MRO are called
(Layer, CocosNode, EventHandlerMixin, object is the order), but the
call still dies on EventHandler.add when it tries to do
super(EventHandlerMixin, self).add(child, *args, **kwargs) because
it's actually trying to call object.add.

Well, this is what I understood from my investigation. At first solve
this is very easy: just remove the super call from EventHandlerMixin.
But it seems a very nasty workaround to me, because I'm not sure that
one can guarantee that EventHandlerMixin would always be the last
class before object on any subclass MRO.

As I see this there are a few options:

1. Drop the class entirely, as suggested before.
2. Discover with someone more experienced in Python multiple
inheritance the right way to do this (this someone could be one of you
guys, or even me if I can learn how to do it :)
3. Use a metaclass or something alike to embed event handler niceties
to the classes that need it (this would need some careful to not make
the code too obscure)

>From my point of view, it could be nice to separate the handle of
events from the Layer or Scene classes, mainly because one could use
that to create other type of classes that handle events (gui
components, for instance). But it seems a task that need some thought
yet.

-- 
Kao Cardoso Félix

Página pessoal: http://www.inf.ufrgs.br/~kcfelix
Blog: http://kaofelix.blogspot.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to