Skip to content

Commit 514f03d

Browse files
committed
updating event handling
1 parent 9cb76c1 commit 514f03d

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

pypboy/core.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,26 @@ def handle_action(self, action):
8686
self.active.handle_action(action)
8787

8888
def handle_event(self, event):
89-
if hasattr(self, 'active'):
90-
self.active.handle_event(event)
89+
if event.type == pygame.KEYDOWN:
90+
if (event.key == pygame.K_ESCAPE):
91+
self.running = False
92+
else:
93+
if event.key in config.ACTIONS:
94+
self.handle_action(config.ACTIONS[event.key])
95+
elif event.type == pygame.QUIT:
96+
self.running = False
97+
elif event.type == config.EVENTS['SONG_END']:
98+
if hasattr(config, 'radio'):
99+
config.radio.handle_event(event)
100+
else:
101+
if hasattr(self, 'active'):
102+
self.active.handle_event(event)
91103

92104
def run(self):
93105
self.running = True
94106
while self.running:
95107
for event in pygame.event.get():
96-
if event.type == pygame.KEYDOWN:
97-
if (event.key == pygame.K_ESCAPE):
98-
self.running = False
99-
else:
100-
if event.key in config.ACTIONS:
101-
self.handle_action(config.ACTIONS[event.key])
102-
elif event.type == pygame.QUIT:
103-
self.running = False
104-
else:
105-
self.handle_event(event)
106-
108+
self.handle_event(event)
107109
self.update()
108110
self.render()
109111
self.check_gpio_input()

0 commit comments

Comments
 (0)