2 from naja.events import InvalidateTheWorld
6 def __init__(self, pos, size=None):
8 self.size = size or (0, 0)
13 return pygame.Rect(self.pos, self.size)
15 def render(self, surface):
16 '''Draw the widget onto surface'''
17 if not self._prepared:
22 def draw(self, surface):
23 '''The overrideable bit of widget drawing'''
24 raise NotImplemented()
27 '''Prepare the widget for drawing. This usually caches a surface.'''
29 def handle_event(self, ev):
30 '''Return True if the event has been handled'''
31 if InvalidateTheWorld.matches(ev):
32 # Invalidate has special handling. Widgets should never return
33 # True for for this event
34 self._prepared = False
39 class Container(object):
40 def __init__(self, *widgets):
42 for widget in widgets:
45 def add(self, widget):
46 self.widgets.append(widget)
48 def render(self, surface):
49 for widget in self.widgets:
50 widget.render(surface)
52 def handle_event(self, ev):
53 for widget in self.widgets:
54 if widget.handle_event(ev):