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

Added a new way of binding handlers to trackers.

parent b7c9d41d
Code: Code:
- Connect to VTK. - Connect to VTK.
- Rotation has a 'bump' at 0. - Rotation has a 'bump' at 0.
- tracker.gesture(...) instead of tracker.bind('gesture', ...)
Thesis: Thesis:
- Network protocol. - Network protocol.
......
...@@ -66,6 +66,19 @@ class GestureTracker(Logger): ...@@ -66,6 +66,19 @@ class GestureTracker(Logger):
setattr(self, name, value) setattr(self, name, value)
def __getattr__(self, name):
"""
Allow calls like:
tracker.gesture(...)
instead of:
tracker.bind('gesture', ...)
"""
if name not in self.__gesture_types__:
raise AttributeError("'%s' has no attribute '%s'"
% (self.__class__.__name__, name))
return lambda handler: self.bind(name, handler)
class Gesture(object): class Gesture(object):
""" """
......
...@@ -13,9 +13,9 @@ win = FullscreenWindow(server=server) ...@@ -13,9 +13,9 @@ win = FullscreenWindow(server=server)
# Add tracker and handlers # Add tracker and handlers
tracker = BasicTracker(win) tracker = BasicTracker(win)
tracker.bind('down', lambda g: 0) tracker.down(lambda g: 0)
tracker.bind('move', lambda g: 0) tracker.move(lambda g: 0)
tracker.bind('up', lambda g: 0) tracker.up(lambda g: 0)
# Start listening to TUIO events # Start listening to TUIO events
try: try:
......
...@@ -141,13 +141,13 @@ def pinch(gesture): ...@@ -141,13 +141,13 @@ def pinch(gesture):
scale = min(scale * gesture.get_scale(), MAX_SCALE) scale = min(scale * gesture.get_scale(), MAX_SCALE)
transform = TransformationTracker(win) transform = TransformationTracker(win)
transform.bind('rotate', rotate) transform.rotate(rotate)
transform.bind('pinch', pinch) transform.pinch(pinch)
tap = TapTracker(win) tap = TapTracker(win)
tap.bind('tap', lambda g: taps.append([coord(*g.xy), FINGER_RADIUS])) tap.tap(lambda g: taps.append([coord(*g.xy), FINGER_RADIUS]))
tap.bind('single_tap', lambda g: dtaps.append(list(coord(*g.xy)) + [1])) tap.single_tap(lambda g: dtaps.append(list(coord(*g.xy)) + [1]))
tap.bind('double_tap', lambda g: dtaps.append(list(coord(*g.xy)) + [0])) tap.double_tap(lambda g: dtaps.append(list(coord(*g.xy)) + [0]))
try: try:
......
...@@ -18,12 +18,12 @@ win = FullscreenWindow(server=server) ...@@ -18,12 +18,12 @@ win = FullscreenWindow(server=server)
# Add tracker and handlers # Add tracker and handlers
tracker = TapTracker(win) tracker = TapTracker(win)
def handler(gesture): pass def handler(gesture):
#print 'handler:', gesture pass
tracker.bind('tap', handler) tracker.tap(handler)
tracker.bind('single_tap', handler) tracker.single_tap(handler)
tracker.bind('double_tap', handler) tracker.double_tap(handler)
# Start listening to TUIO events # Start listening to TUIO events
try: try:
......
...@@ -13,9 +13,9 @@ win = FullscreenWindow(server=server) ...@@ -13,9 +13,9 @@ win = FullscreenWindow(server=server)
# Add tracker and handlers # Add tracker and handlers
tracker = TransformationTracker(win) tracker = TransformationTracker(win)
tracker.bind('rotate', lambda g: 0) tracker.rotate(lambda g: 0)
tracker.bind('pinch', lambda g: 0) tracker.pinch(lambda g: 0)
tracker.bind('move', lambda g: 0) tracker.move(lambda g: 0)
# Start listening to TUIO events # Start listening to TUIO events
try: try:
......
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