Add a non-empty set of locations for testing
[naja.git] / naja / events.py
1 """
2 Custom Pygame events.
3 """
4
5 import pygame.event as pge
6 import pygame.locals as pgl
7
8
9 class NajaEvent(object):
10
11     TYPE = "UNKNOWN"
12
13     @classmethod
14     def post(cls, **attributes):
15         event = pge.Event(pgl.USEREVENT, naja_event_type=cls.TYPE,
16                           **attributes)
17         pge.post(event)
18
19     @classmethod
20     def matches(cls, ev):
21         return ev.type == pgl.USEREVENT and ev.naja_event_type == cls.TYPE
22
23
24 class SceneChangeEvent(NajaEvent):
25     TYPE = "SCENE_CHANGE"
26
27     @classmethod
28     def post(cls, scene_cls):
29         super(SceneChangeEvent, cls).post(scene_cls=scene_cls)
30
31
32 class QuitGameEvent(NajaEvent):
33     TYPE = "QUIT_GAME"
34
35     @classmethod
36     def post(cls):
37         super(QuitGameEvent, cls).post()
38
39
40 class InvalidateTheWorld(NajaEvent):
41     # This is used to signal to all the widgets that the world has changed
42     # and cached state may need to be recreated
43     TYPE = "INVALIDATE"
44
45     @classmethod
46     def post(cls):
47         super(InvalidateTheWorld, cls).post()