extended help
[tabakrolletjie.git] / tabakrolletjie / events.py
1 """ Custom events. """
2
3 import pygame.event
4 import pygame.locals as pgl
5
6
7 class TabakEvent(object):
8     TYPE = "UNKNOWN"
9     ATTRIBUTES = set()
10
11     @classmethod
12     def post(cls, **attributes):
13         assert set(attributes.keys()) == cls.ATTRIBUTES
14         ev = pygame.event.Event(
15             pgl.USEREVENT, tabak_type=cls.TYPE, **attributes)
16         pygame.event.post(ev)
17
18     @classmethod
19     def matches(cls, ev):
20         return (ev.type == pgl.USEREVENT and ev.tabak_type == cls.TYPE)
21
22
23 class QuitEvent(TabakEvent):
24     TYPE = "QUIT"
25
26
27 class SceneChangeEvent(TabakEvent):
28     TYPE = "SCENE_CHANGE"
29     ATTRIBUTES = {'scene'}