Line | |
---|
1 | """Events to post."""
|
---|
2 |
|
---|
3 | import pygame
|
---|
4 |
|
---|
5 |
|
---|
6 | class 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 |
|
---|
19 | class QuitEvent(Event):
|
---|
20 | TYPE = pygame.locals.QUIT
|
---|
21 |
|
---|
22 |
|
---|
23 | class 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 |
|
---|
36 | class 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.