4d3fb07f80a94bc5502edfa048b3e0e017c80393
[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()