def registerListener(self, *args): """Registers a new listener with the specified activation method to listen events generated by this component. If the activation method does not have any arguments the event object will not be passed to it when it's called. This method additionally informs the event-api to route events with the given eventIdentifier to the components handleEvent function call. For more information on the inheritable event mechanism see the L{muntjac.event package documentation<muntjac.event>}. @param args: tuple of the form - (eventIdentifier, eventType, target, method) 1. the identifier of the event to listen for 2. the type of the listened event. Events of this type or its subclasses activate the listener. 3. the object instance who owns the activation method. 4. the activation method. - (eventType, target, method) 1. the type of the listened event. Events of this type or its subclasses activate the listener. 2. the object instance who owns the activation method. 3. the activation method or the name of the activation method. """ nargs = len(args) if nargs == 3: eventType, target, method = args if self._eventRouter is None: self._eventRouter = EventRouter() self._eventRouter.addListener(eventType, target, method) elif nargs == 4: eventIdentifier, eventType, target, method = args if self._eventRouter is None: self._eventRouter = EventRouter() if self._eventIdentifiers is None: self._eventIdentifiers = set() needRepaint = not self._eventRouter.hasListeners(eventType) self._eventRouter.addListener(eventType, target, method) if needRepaint: self._eventIdentifiers.add(eventIdentifier) self.requestRepaint() else: raise ValueError, 'invalid number of arguments'
def registerCallback(self, eventType, callback, eventId, *args): if hasattr(callback, 'im_self'): target = callback.im_self elif hasattr(callback, 'func_name'): target = None else: raise ValueError('invalid callback: %s' % callback) if len(args) > 0: arguments = (None, ) + args # assume event always passed first eventArgIdx = 0 else: arguments = None eventArgIdx = None if self._eventRouter is None: self._eventRouter = EventRouter() if self._eventIdentifiers is None: self._eventIdentifiers = set() if eventId is not None: needRepaint = not self._eventRouter.hasListeners(eventType) self._eventRouter.addListener(eventType, target, callback, arguments, eventArgIdx) if (eventId is not None) and needRepaint: self._eventIdentifiers.add(eventId) self.requestRepaint()