1b57ee0dc3244bc0c7dc2077485f7671b0ec6ad5
[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
36 class InvalidateTheWorld(NajaEvent):
37     # This is used to signal to all the widgets that the world has changed
38     # and cached state may need to be recreated
39     TYPE = "INVALIDATE"
40
41
42 class SelectEvent(NajaEvent):
43     TYPE = "SELECT"