Mercurial > mamba
comparison mamba/widgets/base.py @ 24:30d4f3e62bcf
Refactor widgets *again*, add container to Habitat
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Sun, 11 Sep 2011 14:21:50 +0200 |
parents | d0e8940df703 |
children | 047273a63054 |
comparison
equal
deleted
inserted
replaced
23:d0e8940df703 | 24:30d4f3e62bcf |
---|---|
4 class Widget(object): | 4 class Widget(object): |
5 | 5 |
6 def __init__(self, rect): | 6 def __init__(self, rect): |
7 self.rect = pygame.Rect(rect) | 7 self.rect = pygame.Rect(rect) |
8 | 8 |
9 def do_event(self, event): | 9 def event(self, event): |
10 "Override me" | 10 "Override me" |
11 pass | 11 pass |
12 | 12 |
13 def do_draw(self, surface): | 13 def draw(self, surface): |
14 "Override me" | 14 "Override me" |
15 pass | 15 pass |
16 | 16 |
17 | 17 |
18 class Container(object): | 18 class Container(object): |
21 self.children = [] | 21 self.children = [] |
22 | 22 |
23 def event(self, event): | 23 def event(self, event): |
24 for child in self.children: | 24 for child in self.children: |
25 # TODO mouse events | 25 # TODO mouse events |
26 if issubclass(child, Container): | 26 child.event(event) |
27 child.event(event) | |
28 else: | |
29 child.do_event(event) | |
30 | 27 |
31 def add(self, widget): | 28 def add(self, widget): |
32 self.children.append(widget) | 29 self.children.append(widget) |
33 | 30 |
34 def draw(self, surface): | 31 def draw(self, surface): |
35 self.do_draw(surface) | |
36 for child in self.children: | 32 for child in self.children: |
37 if issubclass(child, Container): | 33 child.draw(surface) |
38 child.draw(surface) | |
39 else: | |
40 child.do_draw(surface) |