23
|
1 import pygame
|
|
2
|
|
3
|
|
4 class Widget(object):
|
|
5
|
|
6 def __init__(self, rect):
|
|
7 self.rect = pygame.Rect(rect)
|
|
8
|
|
9 def do_event(self, event):
|
|
10 "Override me"
|
|
11 pass
|
|
12
|
|
13 def do_draw(self, surface):
|
|
14 "Override me"
|
|
15 pass
|
|
16
|
|
17
|
|
18 class Container(object):
|
|
19
|
|
20 def __init__(self):
|
|
21 self.children = []
|
|
22
|
|
23 def event(self, event):
|
|
24 for child in self.children:
|
|
25 # TODO mouse events
|
|
26 if issubclass(child, Container):
|
|
27 child.event(event)
|
|
28 else:
|
|
29 child.do_event(event)
|
|
30
|
|
31 def add(self, widget):
|
|
32 self.children.append(widget)
|
|
33
|
|
34 def draw(self, surface):
|
|
35 self.do_draw(surface)
|
|
36 for child in self.children:
|
|
37 if issubclass(child, Container):
|
|
38 child.draw(surface)
|
|
39 else:
|
|
40 child.do_draw(surface)
|