Commit 7ea7d1e4 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Split TUIO server into input server and TUIO server.

parent 423b5dd8
from logger import Logger
class InputServer(Logger):
"""
Abstract class for input servers. An input server translates driver
events to point 'down', 'move' and 'up' events. An input server
implementation should define the methods 'start' and 'stop', which
starts/stops some event loop that triggers on_point_up, on_point_move and
on_point_down methods on the 'handler_obj' object.
"""
def __init__(self, handler_obj):
self.handler_obj = handler_obj
def start(self):
raise NotImplementedError
def stop(self):
raise NotImplementedError
class InputServerHandler(Logger):
"""
Interface for gesture server. Defines empty on_point_up, on_point_move and
on_point_down handlers.
"""
def on_point_down(self, sid, x, y):
return NotImplemented
def on_point_move(self, sid, x, y):
return NotImplemented
def on_point_up(self, sid):
return NotImplemented
from logger import Logger from input_server import InputServerHandler
from tuio_server import TuioServer2D
from window import FullscreenWindow from window import FullscreenWindow
from tuio_server import TuioServer2D, TuioServerHandler
from point import TouchPoint from point import TouchPoint
from screen import pixel_coords from screen import pixel_coords
class GestureServer(TuioServerHandler, Logger): class GestureServer(InputServerHandler):
""" """
Multi-touch gesture server. This uses a TUIO server to receive basic touch Multi-touch gesture server. This uses a TUIO server to receive basic touch
events, which are translated to gestures using gesture trackers. Trackers events, which are translated to gestures using gesture trackers. Trackers
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
from OSC import OSCServer from OSC import OSCServer
OSCServer.print_tracebacks = True OSCServer.print_tracebacks = True
from logger import Logger from input_server import InputServer
class TuioServer2D(Logger): class TuioServer2D(InputServer):
__tuio_address__ = 'localhost', 3333 __tuio_address__ = 'localhost', 3333
def __init__(self, handler_obj): def __init__(self, handler_obj):
super(TuioServer2D, self).__init__(handler_obj)
# OSC server that listens to incoming TUIO events # OSC server that listens to incoming TUIO events
self.server = OSCServer(self.__tuio_address__) self.server = OSCServer(self.__tuio_address__)
self.server.addDefaultHandlers() self.server.addDefaultHandlers()
...@@ -23,8 +25,6 @@ class TuioServer2D(Logger): ...@@ -23,8 +25,6 @@ class TuioServer2D(Logger):
# event # event
self.down = set() self.down = set()
self.handler_obj = handler_obj
def _receive(self, addr, tags, data, source): def _receive(self, addr, tags, data, source):
surface = addr[8:] surface = addr[8:]
#self.debug('Received message <surface=%s tags="%s" ' #self.debug('Received message <surface=%s tags="%s" '
...@@ -74,25 +74,13 @@ class TuioServer2D(Logger): ...@@ -74,25 +74,13 @@ class TuioServer2D(Logger):
self.server.close() self.server.close()
class TuioServerHandler(object):
"""
Interface for touch servers. Defines point_up, point_move and point_down
handlers.
"""
def on_point_down(self, sid, x, y):
return NotImplemented
def on_point_move(self, sid, x, y):
return NotImplemented
def on_point_up(self, sid):
return NotImplemented
if __name__ == '__main__': if __name__ == '__main__':
import argparse import argparse
import logging import logging
from logger import Logger
from input_server import InputServerHandler
parser = argparse.ArgumentParser(description='TUIO server test.') parser = argparse.ArgumentParser(description='TUIO server test.')
parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO', parser.add_argument('--log', metavar='LOG_LEVEL', default='INFO',
choices=['DEBUG', 'INFO', 'WARNING'], help='Global log level.') choices=['DEBUG', 'INFO', 'WARNING'], help='Global log level.')
...@@ -109,7 +97,7 @@ if __name__ == '__main__': ...@@ -109,7 +97,7 @@ if __name__ == '__main__':
Logger.configure(**log_config) Logger.configure(**log_config)
# Define handlers # Define handlers
class Handler(TuioServerHandler, Logger): class Handler(InputServerHandler, Logger):
def on_point_down(self, sid, x, y): def on_point_down(self, sid, x, y):
self.info('Point down: sid=%d (%s, %s)' % (sid, x, y)) self.info('Point down: sid=%d (%s, %s)' % (sid, x, y))
......
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