# HG changeset patch # User Stefano Rivera # Date 1316025076 -7200 # Node ID 51d54026b15391a92e0fddbd61d87ded402a7c6c # Parent c35e22dc225af2b6ababd619772f6a0965e4e826 Support UserEvents in callbacks diff -r c35e22dc225a -r 51d54026b153 mamba/widgets/base.py --- a/mamba/widgets/base.py Wed Sep 14 20:30:34 2011 +0200 +++ b/mamba/widgets/base.py Wed Sep 14 20:31:16 2011 +0200 @@ -2,7 +2,10 @@ import pygame from pygame.constants import K_UP, K_DOWN, K_RETURN -from pygame.locals import MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN, KEYDOWN +from pygame.locals import (KEYDOWN, MOUSEMOTION, MOUSEBUTTONUP, + MOUSEBUTTONDOWN, USEREVENT) + +from mamba.engine import UserEvent class Widget(object): @@ -20,7 +23,16 @@ self.callbacks[eventtype].append((callback, args)) def event(self, ev): - for callback, args in self.callbacks[ev.type]: + "Don't override this without damn good reason" + type_ = ev.type + if type_ == USEREVENT: + for k in self.callbacks.iterkeys(): + if (isinstance(k, type) and issubclass(k, UserEvent) + and k.matches(ev)): + type_ = k + break + + for callback, args in self.callbacks[type_]: if callback(ev, self, *args): return True return False