A bit of cleanup. Pygame and multithreading is a real pain in the ass...

This commit is contained in:
Balthasar Reuter
2015-06-20 00:08:22 +02:00
parent 76b3c54c39
commit 0f25f8de88
2 changed files with 22 additions and 39 deletions

22
gui.py
View File

@@ -141,6 +141,7 @@ class GUI_PyGame:
# Clear screen
self.clear()
self.apply()
def clear(self, color=(0,0,0)):
self.screen.fill(color)
@@ -221,26 +222,5 @@ class GUI_PyGame:
if r:
return e
def mainloop(self, filename, handle_keypress, handle_mousebutton, handle_gpio_event):
while True:
# Ignore all input that happened before entering the loop
EventModule.get()
# Clear display
self.clear()
# Show idle-picture and message
if filename != None:
self.show_picture(filename)
self.show_message("Hit the button!")
# Render everything
self.apply()
# Wait for event
event = EventModule.wait()
# Handle the event
if event.type == pygame.QUIT: return
elif event.type == pygame.KEYDOWN: handle_keypress(event.key)
elif event.type == pygame.MOUSEBUTTONUP: handle_mousebutton(event.button, event.pos)
elif event.type == gpio_pygame_event: handle_gpio_event(event.channel)
def teardown(self):
pygame.quit()