Commit 3c6f417f authored by Taddeus Kroes's avatar Taddeus Kroes

Updated some event formats and added 'basic' events.

parent 5ca9a829
class GestureEvent(object): class BasicEvent(object):
def __init__(self, gesture): def __init__(self, point):
self.gesture = gesture self.point = point
def __str__(self):
return '<%s (%s, %s) sid=%d>' % \
(self.__class__.__name__, self.point.x, self.point.y,
self.point.sid)
class TapEvent(GestureEvent): def __getattr__(self, name):
def __init__(self, x, y, double=False): """
super(TapEvent, self).__init__('tap') Delegate attributes to touch point.
"""
if hasattr(self.point, name):
return getattr(self.point, name)
raise AttributeError
class DownEvent(BasicEvent):
_name = 'down'
class UpEvent(BasicEvent):
_name = 'up'
class MoveEvent(BasicEvent):
_name = 'move'
def __str__(self):
return '<%s (%s, %s) to (%s, %s) sid=%d>' % \
(self.__class__.__name__, self.point.px, self.point.py,
self.point.x, self.point.y, self.point.sid)
class GestureEvent(object):
def __init__(self, x, y):
self.x = x self.x = x
self.y = y self.y = y
self.double = double
@property
def xy(self):
return self.x, self.y
def __str__(self): def __str__(self):
return '<%s (%s, %s)%s>' % (self.__class__.__name__, self.x, self.y, return '<%s (%s, %s)>' % (self.__class__.__name__, self.x, self.y)
' double' if self.double else '')
class TapEvent(GestureEvent):
_name = 'tap'
class SingleTapEvent(GestureEvent):
_name = 'single_tap'
class DoubleTapEvent(GestureEvent):
_name = 'double_tap'
class FlickEvent(GestureEvent): class FlickEvent(GestureEvent):
_name = 'flick'
def __init__(self, x, y, velocity): def __init__(self, x, y, velocity):
super(FlickEvent, self).__init__('flick') super(FlickEvent, self).__init__(x, y)
self.x = x
self.y = y
self.velocity = velocity self.velocity = velocity
def __str__(self): def __str__(self):
...@@ -28,10 +72,10 @@ class FlickEvent(GestureEvent): ...@@ -28,10 +72,10 @@ class FlickEvent(GestureEvent):
class RotateEvent(GestureEvent): class RotateEvent(GestureEvent):
_name = 'rotate'
def __init__(self, cx, cy, angle, n): def __init__(self, cx, cy, angle, n):
super(RotateEvent, self).__init__('rotate') super(RotateEvent, self).__init__(cx, cy)
self.cx = cx
self.cy = cy
self.angle = angle self.angle = angle
self.n = n self.n = n
...@@ -41,10 +85,10 @@ class RotateEvent(GestureEvent): ...@@ -41,10 +85,10 @@ class RotateEvent(GestureEvent):
class PinchEvent(GestureEvent): class PinchEvent(GestureEvent):
_name = 'pinch'
def __init__(self, cx, cy, amount, n): def __init__(self, cx, cy, amount, n):
super(RotateEvent, self).__init__('pinch') super(RotateEvent, self).__init__(cx, cy)
self.cx = cx
self.cy = cy
self.amount = amount self.amount = amount
self.n = n self.n = n
...@@ -54,14 +98,15 @@ class PinchEvent(GestureEvent): ...@@ -54,14 +98,15 @@ class PinchEvent(GestureEvent):
class PanEvent(GestureEvent): class PanEvent(GestureEvent):
_name = 'pan'
def __init__(self, x, y, dx, dy, n): def __init__(self, x, y, dx, dy, n):
super(RotateEvent, self).__init__('pan') super(RotateEvent, self).__init__(x, y)
self.x = x
self.y = y
self.dx = dx self.dx = dx
self.dy = dy self.dy = dy
self.n = n self.n = n
def __str__(self): def __str__(self):
return '<%s (%s, %s) amount=%s n=%d>' % \ return '<%s (%s, %s) to (%s, %s) n=%d>' % \
(self.__class__.__name__, self.x, self.y, self.amount, self.n) (self.__class__.__name__, self.x, self.y, self.dx, self.dy,
self.amount, self.n)
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