From: Neil Date: Sun, 11 May 2014 19:52:20 +0000 (+0200) Subject: The world is invalid (sometimes, when desirable) X-Git-Tag: 0.1~392^2 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=4e27b4e10d7fd4f66097ece17a8c51b80233a363;p=naja.git The world is invalid (sometimes, when desirable) --- diff --git a/naja/events.py b/naja/events.py index 4d3fb07..0e102ed 100644 --- a/naja/events.py +++ b/naja/events.py @@ -35,3 +35,13 @@ class QuitGameEvent(NajaEvent): @classmethod def post(cls): super(QuitGameEvent, cls).post() + + +class InvalidateTheWorld(NajaEvent): + # This is used to signal to all the widgets that the world has changed + # and cached state may need to be recreated + TYPE = "INVALIDATE" + + @classmethod + def post(cls): + super(InvalidateTheWorld, cls).post() diff --git a/naja/widgets/base.py b/naja/widgets/base.py index bda00a4..133cc53 100644 --- a/naja/widgets/base.py +++ b/naja/widgets/base.py @@ -1,4 +1,5 @@ import pygame +from naja.events import InvalidateTheWorld class Widget(object): @@ -27,6 +28,11 @@ class Widget(object): 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