-class MetaRenamer(type):
- def __new__(mcs, name, bases, dict) :
- for k, v in dict.items() :
- if isinstance(v, types.FunctionType) :
- if k != v.__name__ :
- print 'renommage de %s en %s' % (k, v.__name__)
- dict[v.__name__] = v
- del dict[k]
- return type.__new__(mcs, name, bases, dict)
+class EventInitializer(type):
+
+ def __init__(cls, name, bases, dict) :
+ def init_listeners(self) :
+ for k, v in dict.items() :
+ if isinstance(v, types.FunctionType) and hasattr(v, '__islistener__') :
+ listener = getattr(self, k)
+ EventDispatcher.addEventListener(v.__eventtype__, listener)
+ del v.__islistener__
+ del v.__eventtype__
+
+ def ctor(self, *args, **kw) :
+ init_listeners(self)
+ default_ctor = dict.get('__init__')
+ if not default_ctor :
+ super(cls, self).__init__(*args, **kw)
+ else :
+ default_ctor(self, *args, **kw)
+
+ cls.__init__ = ctor