Commit a495e74e authored by Taddeus Kroes's avatar Taddeus Kroes

Verbosity level is now and integer, and ran pyflakes+pep8.

parent ea38f361
#!/usr/bin/env python #!/usr/bin/env python
from events import TapEvent, FlickEvent, RotateEvent, PinchEvent, PanEvent from events import TapEvent, FlickEvent, RotateEvent, PinchEvent, PanEvent
import time import time
from math import atan2 from math import atan2, PI
from threading import Thread from threading import Thread
from OSC import OSCServer from OSC import OSCServer
...@@ -61,14 +61,15 @@ class TouchPoint(object): ...@@ -61,14 +61,15 @@ class TouchPoint(object):
# TODO: Encapsulate DPI resolution in distance heuristics # TODO: Encapsulate DPI resolution in distance heuristics
SUPPORTED_GESTURES = ('tap', 'pan', 'flick', 'rotate', 'pinch') SUPPORTED_GESTURES = ('tap', 'pan', 'flick', 'rotate', 'pinch')
TUIO_ADDRESS = ('localhost', 3333) TUIO_ADDRESS = ('localhost', 3333)
DOUBLE_TAP_DISTANCE = 30 DOUBLE_TAP_DISTANCE_THRESHOLD = 30
FLICK_VELOCITY_TRESHOLD = 20
TAP_INTERVAL = .200 TAP_INTERVAL = .200
TAP_TIMEOUT = .200 TAP_TIMEOUT = .200
MAX_MULTI_DRAG_DISTANCE = 100 MAX_MULTI_DRAG_DISTANCE = 100
class MultiTouchListener(object): class MultiTouchListener(object):
def __init__(self, verbose=False, update_rate=60): def __init__(self, verbose=0, update_rate=60):
self.verbose = verbose self.verbose = verbose
self.last_tap = 0 self.last_tap = 0
self.update_rate = update_rate self.update_rate = update_rate
...@@ -102,7 +103,7 @@ class MultiTouchListener(object): ...@@ -102,7 +103,7 @@ class MultiTouchListener(object):
def detect_taps(self): def detect_taps(self):
if len(self.taps) == 2: if len(self.taps) == 2:
if distance(*self.taps) > DOUBLE_TAP_DISTANCE: if distance(*self.taps) > DOUBLE_TAP_DISTANCE_THRESHOLD:
# Taps are too far away too be a double tap, add 2 separate # Taps are too far away too be a double tap, add 2 separate
# events # events
self.trigger(TapEvent(*self.taps[0])) self.trigger(TapEvent(*self.taps[0]))
...@@ -130,6 +131,7 @@ class MultiTouchListener(object): ...@@ -130,6 +131,7 @@ class MultiTouchListener(object):
return return
rotation = pinch = 0 rotation = pinch = 0
cx, cy = self.centroid
for p in self.points: for p in self.points:
p.set_angle(atan2(p.y - cy, p.x - cx)) p.set_angle(atan2(p.y - cy, p.x - cx))
...@@ -163,7 +165,6 @@ class MultiTouchListener(object): ...@@ -163,7 +165,6 @@ class MultiTouchListener(object):
for p in self.points]) for p in self.points])
directions = [(cmp(p.dx(), 0), cmp(p.dy(), 0)) for p in self.points] directions = [(cmp(p.dx(), 0), cmp(p.dy(), 0)) for p in self.points]
if any(map(all, zip(*directions))) and clustered: if any(map(all, zip(*directions))) and clustered:
if l == 1: if l == 1:
p = self.points[0] p = self.points[0]
...@@ -179,7 +180,7 @@ class MultiTouchListener(object): ...@@ -179,7 +180,7 @@ class MultiTouchListener(object):
if sid in self.points: if sid in self.points:
raise KeyError('Point with session id "%s" already exists.' % sid) raise KeyError('Point with session id "%s" already exists.' % sid)
self.points[sid] = TouchPoint(sid, x, y) self.points[sid] = p = TouchPoint(sid, x, y)
self.update_centroid() self.update_centroid()
# Detect multi-point gestures # Detect multi-point gestures
...@@ -249,8 +250,8 @@ class MultiTouchListener(object): ...@@ -249,8 +250,8 @@ class MultiTouchListener(object):
except KeyboardInterrupt: except KeyboardInterrupt:
self.log('Stopping event loop') self.log('Stopping event loop')
def log(self, msg): def log(self, msg, verbosity=1):
if self.verbose: if self.verbose >= verbosity:
print '| LOG | %s' % msg print '| LOG | %s' % msg
def bind(self, gesture, handler): def bind(self, gesture, handler):
...@@ -275,6 +276,6 @@ if __name__ == '__main__': ...@@ -275,6 +276,6 @@ if __name__ == '__main__':
def tap(event): def tap(event):
print 'tap:', event print 'tap:', event
loop = MultiTouchListener(verbose=True) loop = MultiTouchListener(verbose=2)
loop.bind('tap', tap) loop.bind('tap', tap)
loop.start() loop.start()
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