From 4e27b4e10d7fd4f66097ece17a8c51b80233a363 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 11 May 2014 21:52:20 +0200 Subject: [PATCH] The world is invalid (sometimes, when desirable) --- naja/events.py | 10 ++++++++++ naja/widgets/base.py | 6 ++++++ 2 files changed, 16 insertions(+) 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 -- 2.34.1