-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.py
38 lines (29 loc) · 1.11 KB
/
event.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pygame, gui
UPDATE = 33
listeners = []
func_names = {pygame.QUIT : "_onQuit",
pygame.MOUSEBUTTONUP : "_onMouseButtonUp",
pygame.MOUSEBUTTONDOWN : "_onMouseButtonDown",
pygame.MOUSEMOTION : "_onMouseMotion",
pygame.KEYDOWN : "_onKeyDown",
pygame.KEYUP : "_onKeyUp",
UPDATE : "_onUpdate"
}
def handleEvent (event, elem):
toplayer = -1
for obj in elem._gui_items.sprites()[::-1]:
temp = notifyObject (obj, event, toplayer)
if toplayer == -1 : toplayer = temp
def notifyObject (obj, event, toplayer):
try :
if (event.type == pygame.USEREVENT):
event = pygame.event.Event(event.ID, event.dict)
name = func_names[event.type]
except KeyError:
return -1
if not hasattr(obj, name): return -1
return obj.__getattribute__(name)(event, toplayer)
def pull ():
for event in pygame.event.get():
notifyObject (gui.def_surf, event, -1)
handleEvent (event, gui.def_surf)