Mercurial > mamba
changeset 58:7fa000c4b3c7
Dispatch key events
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 11 Sep 2011 16:21:36 +0200 |
parents | cd5ad2c45e2d |
children | 3cc917814579 |
files | mamba/widgets/base.py |
diffstat | 1 files changed, 7 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mamba/widgets/base.py Sun Sep 11 16:19:05 2011 +0200 +++ b/mamba/widgets/base.py Sun Sep 11 16:21:36 2011 +0200 @@ -1,7 +1,7 @@ import collections import pygame -from pygame.locals import MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN +from pygame.locals import MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN, KEYDOWN class Widget(object): @@ -10,6 +10,7 @@ if not isinstance(rect, pygame.Rect): rect = pygame.Rect(rect, (0, 0)) self.rect = rect + self.focussable = False self.callbacks = collections.defaultdict(list) def add_callback(self, eventtype, callback, *args): @@ -30,10 +31,13 @@ self.children = [] def event(self, event): - for child in self.children: - if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN): + if event.type in (MOUSEMOTION, MOUSEBUTTONUP, MOUSEBUTTONDOWN): + for child in self.children: if child.rect.collidepoint(event.pos): child.event(event) + elif event.type == KEYDOWN: + for child in self.children: + child.event(event) def add(self, widget): self.children.append(widget)