Commit b3dd89c3 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added 'threaded' keyword argument to event driver.

parent a7d80112
from threading import Thread
from logger import Logger from logger import Logger
...@@ -24,14 +26,21 @@ class EventDriver(Logger): ...@@ -24,14 +26,21 @@ class EventDriver(Logger):
if self.root_area.contains_event(event): if self.root_area.contains_event(event):
self.root_area.delegate_event(event) self.root_area.delegate_event(event)
def start(self): def start(self, threaded=False):
""" """
Start the event loop. A root area is needed to be able to delegate Start the event loop. A root area is needed to be able to delegate
events, so check if it exists first. events, so check if it exists first. The argument determines if the
driver should start in a new (daemon) thread.
""" """
if not self.root_area: if not self.root_area:
raise ValueError('Cannot start event server without root area.') raise ValueError('Cannot start event server without root area.')
if threaded:
thread = Thread(target=self.start)
thread.daemon = True
thread.start()
return thread
self.start_loop() self.start_loop()
def start_loop(self): def start_loop(self):
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division from __future__ import division
import pygame import pygame
from threading import Thread
from math import degrees from math import degrees
from src import FullscreenArea, create_driver from src import FullscreenArea, create_driver
...@@ -160,9 +159,7 @@ area.on_point_up(lambda g: points.remove(g.get_event().point)) ...@@ -160,9 +159,7 @@ area.on_point_up(lambda g: points.remove(g.get_event().point))
try: try:
# Start touch gesture server in separate thread # Start touch gesture server in separate thread
thread = Thread(target=driver.start) driver.start(threaded=True)
thread.daemon = True
thread.start()
# Start GUI event loop # Start GUI event loop
def is_quit_event(e): def is_quit_event(e):
......
...@@ -342,10 +342,7 @@ if __name__ == '__main__': ...@@ -342,10 +342,7 @@ if __name__ == '__main__':
create_context_window(800, 600, on_show) create_context_window(800, 600, on_show)
# Run multi-touch gesture server in separate thread # Run multi-touch gesture server in separate thread
driver = mt.create_driver(screen) mt.create_driver(screen).start(threaded=True)
mt_thread = Thread(target=driver.start)
mt_thread.daemon = True
mt_thread.start()
# Flick movement is also handled in a separate thread # Flick movement is also handled in a separate thread
flicks = FlickThread() flicks = FlickThread()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment