44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
|
import asyncio
|
||
|
import time
|
||
|
import sys
|
||
|
|
||
|
import pygame
|
||
|
from . import modules
|
||
|
class GUI:
|
||
|
def __init__(self, loop, size=(600,600)):
|
||
|
self.loop = loop
|
||
|
self.events = asyncio.Queue()
|
||
|
self.size = self.width, self.height = size
|
||
|
self.screen = None
|
||
|
self.modules = [module.MainClass(self) for module in modules.imports]
|
||
|
|
||
|
async def start(self):
|
||
|
pygame.init()
|
||
|
self.screen = pygame.display.set_mode(self.size, flags=pygame.RESIZABLE)
|
||
|
self.loop.run_in_executor(None, self.blocking_event_loop)
|
||
|
|
||
|
def blocking_event_loop(self):
|
||
|
while True:
|
||
|
event = pygame.event.wait()
|
||
|
self.dispatch("pygame_" + pygame.event.event_name(event.type).lower(), event)
|
||
|
|
||
|
def dispatch(self, event_type, *args, **kwargs):
|
||
|
print(event_type)
|
||
|
for module in self.modules:
|
||
|
asyncio.run_coroutine_threadsafe(module.dispatch_event(event_type, *args, **kwargs), loop=self.loop)
|
||
|
|
||
|
def stop(self):
|
||
|
pass
|
||
|
|
||
|
|
||
|
if True:
|
||
|
loop = asyncio.get_event_loop()
|
||
|
gui = GUI(loop)
|
||
|
asyncio.ensure_future(gui.start())
|
||
|
try:
|
||
|
loop.run_forever()
|
||
|
except KeyboardInterrupt:
|
||
|
pass
|
||
|
finally:
|
||
|
gui.stop()
|