Mercurial > mamba
changeset 209:51d54026b153
Support UserEvents in callbacks
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Wed, 14 Sep 2011 20:31:16 +0200 |
parents | c35e22dc225a |
children | b92f705bd8ea |
files | mamba/widgets/base.py |
diffstat | 1 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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