source: nagslang/events.py@ 133:79e1888573d3

Last change on this file since 133:79e1888573d3 was 20:347667c941de, checked in by Simon Cross <hodgestar@…>, 8 years ago

Hook up area.

File size: 791 bytes
Line 
1"""Events to post."""
2
3import pygame
4
5
6class Event(object):
7 TYPE = None
8
9 @classmethod
10 def post(cls, **data):
11 ev = pygame.event.Event(cls.TYPE, **data)
12 pygame.event.post(ev)
13
14 @classmethod
15 def matches(cls, ev):
16 return ev.type == cls.TYPE
17
18
19class QuitEvent(Event):
20 TYPE = pygame.locals.QUIT
21
22
23class UserEvent(Event):
24 TYPE = pygame.locals.USEREVENT
25
26 @classmethod
27 def post(cls, **data):
28 super(UserEvent, cls).post(user_type=cls.__name__, **data)
29
30 @classmethod
31 def matches(cls, ev):
32 return (super(UserEvent, cls).matches(ev)
33 and ev.user_type == cls.__name__)
34
35
36class ScreenChange(UserEvent):
37 @classmethod
38 def post(cls, new_screen):
39 super(ScreenChange, cls).post(screen=new_screen)
Note: See TracBrowser for help on using the repository browser.