Commit 31a4bae6 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Renamed some classes and variables.

- Removed '__' from at begin and end of class variables.
- Renamed input server to event server.
parent 6c5e0a2c
Code: Code:
- Connect to VTK. - Connect to VTK.
- Rotation has a 'bump' at 0. - Rotation has a 'bump' at 0.
- Rename InputServer to EventServer.
Thesis: Thesis:
- Network protocol. - Network protocol.
......
from logger import Logger from logger import Logger
class InputServer(Logger): class EventServer(Logger):
""" """
Abstract class for input servers. An input server translates driver Abstract class for event servers. An event server translates driver
events to point 'down', 'move' and 'up' events. An input server events to point 'down', 'move' and 'up' events. An event server
implementation should define the methods 'start' and 'stop', which implementation should define the methods 'start' and 'stop', which
starts/stops some event loop that triggers on_point_up, on_point_move and starts/stops some event loop that triggers on_point_up, on_point_move and
on_point_down methods on the 'handler_obj' object. on_point_down methods on the 'handler_obj' object.
...@@ -19,7 +19,7 @@ class InputServer(Logger): ...@@ -19,7 +19,7 @@ class InputServer(Logger):
raise NotImplementedError raise NotImplementedError
class InputServerHandler(Logger): class EventServerHandler(Logger):
""" """
Interface for gesture server. Defines empty on_point_up, on_point_move and Interface for gesture server. Defines empty on_point_up, on_point_move and
on_point_down handlers. on_point_down handlers.
......
...@@ -128,7 +128,7 @@ class Surface(Positionable): ...@@ -128,7 +128,7 @@ class Surface(Positionable):
'contains', which calculates whether a position is located in the surface. 'contains', which calculates whether a position is located in the surface.
""" """
def contains(self, point): def contains(self, point):
raise NotImplemented raise NotImplementedError
class RectangularSurface(Surface): class RectangularSurface(Surface):
......
from input_server import InputServerHandler from event_server import EventServerHandler
from tuio_server import TuioServer2D from tuio_server import TuioServer2D
from window import FullscreenWindow from window import FullscreenWindow
from point import TouchPoint from point import TouchPoint
class GestureServer(InputServerHandler): class GestureServer(EventServerHandler):
""" """
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
......
...@@ -36,14 +36,14 @@ class GestureTracker(Logger): ...@@ -36,14 +36,14 @@ class GestureTracker(Logger):
self.handlers[gesture_type].append(h) self.handlers[gesture_type].append(h)
def trigger(self, gesture): def trigger(self, gesture):
if gesture.__type__ not in self.handlers: if gesture._type not in self.handlers:
self.debug('Triggered "%s", but no handlers are bound.' self.debug('Triggered "%s", but no handlers are bound.'
% gesture.__type__) % gesture._type)
return return
self.info('Triggered %s.' % gesture) self.info('Triggered %s.' % gesture)
for handler, args, kwargs in self.handlers[gesture.__type__]: for handler, args, kwargs in self.handlers[gesture._type]:
handler(gesture, *args, **kwargs) handler(gesture, *args, **kwargs)
def is_type_bound(self, gesture_type): def is_type_bound(self, gesture_type):
......
...@@ -7,7 +7,7 @@ class BasicTracker(GestureTracker): ...@@ -7,7 +7,7 @@ class BasicTracker(GestureTracker):
The main goal of this class is to provide a triggering mechanism for the The main goal of this class is to provide a triggering mechanism for the
low-level point-down, point-move and point-up events. low-level point-down, point-move and point-up events.
""" """
__gesture_types__ = ['down', 'move', 'up'] gesture_types = ['down', 'move', 'up']
def on_point_down(self, point): def on_point_down(self, point):
self.trigger(DownGesture(point)) self.trigger(DownGesture(point))
...@@ -20,12 +20,12 @@ class BasicTracker(GestureTracker): ...@@ -20,12 +20,12 @@ class BasicTracker(GestureTracker):
class DownGesture(PointGesture): class DownGesture(PointGesture):
__type__ = 'down' _type = 'down'
class MoveGesture(PointGesture): class MoveGesture(PointGesture):
__type__ = 'move' _type = 'move'
class UpGesture(PointGesture): class UpGesture(PointGesture):
__type__ = 'up' _type = 'up'
...@@ -7,9 +7,9 @@ from utils import PointGesture ...@@ -7,9 +7,9 @@ from utils import PointGesture
class TapTracker(GestureTracker): class TapTracker(GestureTracker):
__gesture_types__ = ['tap', 'single_tap', 'double_tap'] gesture_types = ['tap', 'single_tap', 'double_tap']
__configurable__ = ['tap_distance', 'tap_time', 'double_tap_time', configurable = ['tap_distance', 'tap_time', 'double_tap_time',
'double_tap_distance', 'update_rate'] 'double_tap_distance', 'update_rate']
def __init__(self, window=None): def __init__(self, window=None):
...@@ -110,7 +110,7 @@ class TapGesture(PointGesture): ...@@ -110,7 +110,7 @@ class TapGesture(PointGesture):
""" """
A tap gesture is triggered A tap gesture is triggered
""" """
__type__ = 'tap' _type = 'tap'
class SingleTapGesture(TapGesture): class SingleTapGesture(TapGesture):
...@@ -118,7 +118,7 @@ class SingleTapGesture(TapGesture): ...@@ -118,7 +118,7 @@ class SingleTapGesture(TapGesture):
A single tap gesture is triggered after a regular tap gesture, if no double A single tap gesture is triggered after a regular tap gesture, if no double
tap is triggered for that gesture. tap is triggered for that gesture.
""" """
__type__ = 'single_tap' _type = 'single_tap'
class DoubleTapGesture(TapGesture): class DoubleTapGesture(TapGesture):
...@@ -126,4 +126,4 @@ class DoubleTapGesture(TapGesture): ...@@ -126,4 +126,4 @@ class DoubleTapGesture(TapGesture):
A double tap gesture is triggered if two sequential taps are triggered A double tap gesture is triggered if two sequential taps are triggered
within a certain time and distance of eachother. within a certain time and distance of eachother.
""" """
__type__ = 'double_tap' _type = 'double_tap'
...@@ -9,7 +9,7 @@ class TransformationTracker(GestureTracker): ...@@ -9,7 +9,7 @@ class TransformationTracker(GestureTracker):
Tracker for linear transformations. This implementation detects rotation, Tracker for linear transformations. This implementation detects rotation,
scaling and translation using the centroid of all touch points. scaling and translation using the centroid of all touch points.
""" """
__gesture_types__ = ['rotate', 'pinch', 'move'] gesture_types = ['rotate', 'pinch', 'move']
def __init__(self, window=None): def __init__(self, window=None):
super(TransformationTracker, self).__init__(window) super(TransformationTracker, self).__init__(window)
...@@ -77,7 +77,7 @@ class RotationGesture(Positionable, Gesture): ...@@ -77,7 +77,7 @@ class RotationGesture(Positionable, Gesture):
""" """
A rotation gesture has a angle in radians and a rotational centroid. A rotation gesture has a angle in radians and a rotational centroid.
""" """
__type__ = 'rotate' _type = 'rotate'
def __init__(self, centroid, angle): def __init__(self, centroid, angle):
Positionable.__init__(self, *centroid.get_position()) Positionable.__init__(self, *centroid.get_position())
...@@ -96,7 +96,7 @@ class PinchGesture(Positionable, Gesture): ...@@ -96,7 +96,7 @@ class PinchGesture(Positionable, Gesture):
A pinch gesture has a scale (1.0 means no scaling) and a centroid from A pinch gesture has a scale (1.0 means no scaling) and a centroid from
which the scaling originates. which the scaling originates.
""" """
__type__ = 'pinch' _type = 'pinch'
def __init__(self, centroid, scale): def __init__(self, centroid, scale):
Positionable.__init__(self, *centroid.get_position()) Positionable.__init__(self, *centroid.get_position())
...@@ -115,7 +115,7 @@ class MovementGesture(Positionable, Gesture): ...@@ -115,7 +115,7 @@ class MovementGesture(Positionable, Gesture):
A momevent gesture has an initial position, and a translation from that A momevent gesture has an initial position, and a translation from that
position. position.
""" """
__type__ = 'move' _type = 'move'
def __init__(self, initial_position, translation): def __init__(self, initial_position, translation):
Positionable.__init__(self, *initial_position.get_position()) Positionable.__init__(self, *initial_position.get_position())
......
from OSC import OSCServer from OSC import OSCServer
OSCServer.print_tracebacks = True OSCServer.print_tracebacks = True
from input_server import InputServer from event_server import EventServer
from screen import pixel_coords from screen import pixel_coords
class TuioServer2D(InputServer): class TuioServer2D(EventServer):
tuio_address = 'localhost', 3333 tuio_address = 'localhost', 3333
def __init__(self, handler_obj): def __init__(self, handler_obj):
...@@ -84,7 +84,7 @@ if __name__ == '__main__': ...@@ -84,7 +84,7 @@ if __name__ == '__main__':
import logging import logging
from logger import Logger from logger import Logger
from input_server import InputServerHandler from event_server import EventServerHandler
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',
...@@ -102,7 +102,7 @@ if __name__ == '__main__': ...@@ -102,7 +102,7 @@ if __name__ == '__main__':
Logger.configure(**log_config) Logger.configure(**log_config)
# Define handlers # Define handlers
class Handler(InputServerHandler, Logger): class Handler(EventServerHandler, Logger):
def on_point_down(self, sid, x, y): def on_point_down(self, sid, x, y):
self.info('Point down: sid=%d (%.4f, %.4f)' % (sid, x, y)) self.info('Point down: sid=%d (%.4f, %.4f)' % (sid, x, y))
......
from src.server import GestureServer from src.gesture_server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.basic import BasicTracker from src.trackers.basic import BasicTracker
......
...@@ -4,7 +4,7 @@ import pygame ...@@ -4,7 +4,7 @@ import pygame
from threading import Thread from threading import Thread
from math import degrees from math import degrees
from src.server import GestureServer from src.gesture_server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.transform import TransformationTracker from src.trackers.transform import TransformationTracker
from src.trackers.tap import TapTracker from src.trackers.tap import TapTracker
......
from src.server import GestureServer from src.gesture_server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.tap import TapTracker from src.trackers.tap import TapTracker
......
from src.server import GestureServer from src.gesture_server import GestureServer
from src.window import FullscreenWindow from src.window import FullscreenWindow
from src.trackers.transform import TransformationTracker from src.trackers.transform import TransformationTracker
......
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