Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
a495e74e
Commit
a495e74e
authored
Apr 24, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verbosity level is now and integer, and ran pyflakes+pep8.
parent
ea38f361
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
9 deletions
+10
-9
src/multitouch/touch.py
src/multitouch/touch.py
+10
-9
No files found.
src/multitouch/touch.py
View file @
a495e74e
#!/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
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment