Bastard merge
[naja.git] / naja / widgets / base.py
index 6b86a870f5adadbb518ed4fc4caae837ccce7650..133cc532c2ae8fb0886117255decbba65f1e374c 100644 (file)
@@ -1,4 +1,5 @@
 import pygame
+from naja.events import InvalidateTheWorld
 
 
 class Widget(object):
@@ -12,18 +13,26 @@ class Widget(object):
         return pygame.Rect(self.pos, self.size)
 
     def render(self, surface):
+        '''Draw the widget onto surface'''
         if not self._prepared:
             self.prepare()
             self._prepared = True
         self.draw(surface)
 
     def draw(self, surface):
+        '''The overrideable bit of widget drawing'''
         raise NotImplemented()
 
     def prepare(self):
-        raise NotImplemented()
+        '''Prepare the widget for drawing. This usually caches a surface.'''
 
     def handle_event(self, ev):
+        '''Return True if the event has been handled'''
+        if InvalidateTheWorld.matches(ev):
+            # Invalidate has special handling. Widgets should never return
+            # True for for this event
+            self._prepared = False
+            return False
         return False