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
3036a05c
Commit
3036a05c
authored
Jun 16, 2012
by
UVA Multi-touch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merged 'event driver' and 'event server' into 'event driver'.
parent
502fe8e6
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
74 additions
and
113 deletions
+74
-113
src/__init__.py
src/__init__.py
+1
-1
src/drivers/__init__.py
src/drivers/__init__.py
+5
-5
src/drivers/tuio.py
src/drivers/tuio.py
+9
-12
src/event_driver.py
src/event_driver.py
+30
-7
src/event_server.py
src/event_server.py
+0
-52
tests/basic.py
tests/basic.py
+5
-8
tests/cairotest.py
tests/cairotest.py
+2
-2
tests/draw.py
tests/draw.py
+4
-5
tests/tap.py
tests/tap.py
+5
-6
tests/transform.py
tests/transform.py
+5
-6
tests/vtk_interactor.py
tests/vtk_interactor.py
+8
-9
No files found.
src/__init__.py
View file @
3036a05c
from
logger
import
Logger
from
tracker
import
GestureTracker
,
Gesture
from
event_server
import
EventSer
ver
from
drivers
import
create_dri
ver
from
areas
import
*
src/drivers/__init__.py
View file @
3036a05c
from
tuio
import
TuioDriver
def
select_driver
(
event_server
):
def
create_driver
(
root_area
=
None
):
"""
Create an object of a
driver implementation, based on hardware support.
Currently, only a TUIO driver implementation exists. In the future, this
method should select one driver from a set of implementations.
Create an object of a
n event driver implementation, based on hardware
support. Currently, only a TUIO driver implementation exists. In the
future, this
method should select one driver from a set of implementations.
"""
return
TuioDriver
(
event_server
)
return
TuioDriver
(
root_area
)
src/drivers/tuio.py
View file @
3036a05c
...
...
@@ -11,8 +11,8 @@ from ..screen import pixel_coords
class
TuioDriver
(
EventDriver
):
tuio_address
=
'localhost'
,
3333
def
__init__
(
self
,
event_server
):
super
(
TuioDriver
,
self
).
__init__
(
event_server
)
def
__init__
(
self
,
root_area
=
None
):
super
(
TuioDriver
,
self
).
__init__
(
root_area
)
# OSC server that listens to incoming TUIO events
self
.
server
=
OSCServer
(
self
.
tuio_address
)
...
...
@@ -53,8 +53,7 @@ class TuioDriver(EventDriver):
for
sid
in
released
:
point
=
self
.
points
[
sid
]
del
self
.
points
[
sid
]
self
.
event_server
.
delegate_event
(
PointUpEvent
(
point
))
#self.event_server.on_point_up(sid)
self
.
delegate_event
(
PointUpEvent
(
point
))
elif
msg_type
==
'set'
:
sid
,
x
,
y
=
data
[
1
:
4
]
...
...
@@ -71,23 +70,21 @@ class TuioDriver(EventDriver):
%
(
sid
,
x
,
y
,
px
,
py
))
point
=
self
.
points
[
sid
]
point
.
set_position
(
px
,
py
)
self
.
event_server
.
delegate_event
(
PointMoveEvent
(
point
))
#self.event_server.on_point_move(sid, px, py)
self
.
delegate_event
(
PointMoveEvent
(
point
))
else
:
self
.
debug
(
'Down %d at (%.4f, %.4f), in pixels: (%d, %d).'
%
(
sid
,
x
,
y
,
px
,
py
))
self
.
down
.
add
(
sid
)
self
.
points
[
sid
]
=
point
=
TouchPoint
(
px
,
py
)
self
.
event_server
.
delegate_event
(
PointDownEvent
(
point
))
#self.event_server.on_point_down(sid, px, py)
self
.
delegate_event
(
PointDownEvent
(
point
))
def
run
(
self
):
self
.
server
.
handle_request
()
def
start
(
self
):
def
start_loop
(
self
):
self
.
info
(
'Starting OSC server'
)
self
.
server
.
serve_forever
()
def
stop
(
self
):
self
.
info
(
'Stopping OSC server'
)
self
.
server
.
close
()
def
run
(
self
):
self
.
server
.
handle_request
()
src/event_driver.py
View file @
3036a05c
...
...
@@ -3,16 +3,39 @@ from logger import Logger
class
EventDriver
(
Logger
):
"""
Abstract factory class for drivers. A driver translates driver-specific
messages to a common set of events. The minimal set is {point_down,
point_move, point_up}. A driver implementation should define the methods
'start' and 'stop', which starts/stops some event loop that triggers the
'delegate_event' method of a area.
The event driver receives driver-specific messages, which are delegated to
the root area in the form of common events such as 'piont_down' pr
'point_up'.
"""
def
__init__
(
self
,
event_server
):
self
.
event_server
=
event_server
def
__init__
(
self
,
root_area
=
None
):
self
.
root_area
=
root_area
def
get_root_area
(
self
):
return
self
.
root_area
def
set_root_area
(
self
,
area
):
self
.
root_area
=
area
def
delegate_event
(
self
,
event
):
"""
Delegate an event that has been triggered by the event driver to the
area tree.
"""
if
self
.
root_area
.
contains_event
(
event
):
event
.
set_root_area
(
self
.
root_area
)
self
.
root_area
.
delegate_event
(
event
)
def
start
(
self
):
"""
Start the event loop. A root area is needed to be able to delegate
events, so check if it exists first.
"""
if
not
self
.
root_area
:
raise
ValueError
(
'Cannot start event server without root area.'
)
self
.
start_loop
()
def
start_loop
(
self
):
"""
Start the event loop.
"""
...
...
src/event_server.py
deleted
100644 → 0
View file @
502fe8e6
from
logger
import
Logger
from
drivers
import
select_driver
class
EventServer
(
Logger
):
"""
The event server uses an event driver to receive events, which are
delegated to a area tree (and eventually to gesture trackers).
"""
def
__init__
(
self
,
root_area
=
None
):
# Root area to which events are delegated
self
.
root_area
=
root_area
# Driver implementation that will be serving events
self
.
event_driver
=
select_driver
(
self
)
def
get_root_area
(
self
):
return
self
.
root_area
def
set_root_area
(
self
,
area
):
self
.
root_area
=
area
def
delegate_event
(
self
,
event
):
"""
Delegate an event that has been triggered by the event driver to the
area tree.
"""
if
self
.
root_area
.
contains_event
(
event
):
event
.
set_root_area
(
self
.
root_area
)
self
.
root_area
.
delegate_event
(
event
)
def
start
(
self
):
"""
Start the event loop. A root area is needed to be able to delegate
events, so check if it exists first.
"""
if
not
self
.
root_area
:
raise
ValueError
(
'Cannot start event server without root area.'
)
self
.
event_driver
.
start
()
def
stop
(
self
):
"""
Stop the event loop.
"""
self
.
event_driver
.
stop
()
def
run
(
self
):
"""
Execute a single loop iteration of the event driver.
"""
self
.
event_driver
.
run
()
tests/basic.py
View file @
3036a05c
from
src.event_server
import
EventServer
from
src.areas
import
FullscreenArea
from
tests.parse_arguments
import
create_parser
,
parse_args
from
src
import
FullscreenArea
,
create_driver
parse_args
(
create_parser
())
# Create
ser
ver and fullscreen area
# Create
dri
ver and fullscreen area
screen
=
FullscreenArea
()
server
=
EventSer
ver
(
screen
)
driver
=
create_dri
ver
(
screen
)
# Bind handlers
# Add tracker and handlers
screen
.
on_point_down
(
lambda
g
:
0
)
screen
.
on_point_move
(
lambda
g
:
0
)
screen
.
on_point_up
(
lambda
g
:
0
)
# Start listening to TUIO events
try
:
ser
ver
.
start
()
dri
ver
.
start
()
except
KeyboardInterrupt
:
ser
ver
.
stop
()
dri
ver
.
stop
()
tests/cairotest.py
View file @
3036a05c
...
...
@@ -162,8 +162,8 @@ if __name__ == '__main__':
create_context_window
(
640
,
460
,
on_show
)
# Run multi-touch gesture server in separate thread
server
=
mt
.
EventSer
ver
(
root
)
mt_thread
=
Thread
(
target
=
ser
ver
.
start
)
driver
=
mt
.
create_dri
ver
(
root
)
mt_thread
=
Thread
(
target
=
dri
ver
.
start
)
mt_thread
.
daemon
=
True
mt_thread
.
start
()
...
...
tests/draw.py
View file @
3036a05c
...
...
@@ -4,9 +4,8 @@ import pygame
from
threading
import
Thread
from
math
import
degrees
from
src.event_server
import
EventServer
from
src.areas
import
FullscreenArea
from
tests.parse_arguments
import
create_parser
,
parse_args
from
src
import
FullscreenArea
,
create_driver
from
src.screen
import
screen_size
# Parse arguments
...
...
@@ -147,7 +146,7 @@ def pinch(gesture):
area
=
FullscreenArea
()
server
=
EventSer
ver
(
area
)
driver
=
create_dri
ver
(
area
)
area
.
on_rotate
(
rotate
)
area
.
on_pinch
(
pinch
)
...
...
@@ -161,7 +160,7 @@ area.on_point_up(lambda g: points.remove(g.get_event().point))
try
:
# Start touch gesture server in separate thread
thread
=
Thread
(
target
=
ser
ver
.
start
)
thread
=
Thread
(
target
=
dri
ver
.
start
)
thread
.
daemon
=
True
thread
.
start
()
...
...
@@ -175,4 +174,4 @@ try:
except
KeyboardInterrupt
:
pass
finally
:
ser
ver
.
stop
()
dri
ver
.
stop
()
tests/tap.py
View file @
3036a05c
from
src.event_server
import
EventServer
from
src.areas
import
FullscreenArea
from
tests.parse_arguments
import
create_parser
,
parse_args
from
src
import
FullscreenArea
,
create_driver
parse_args
(
create_parser
())
# Create
ser
ver and fullscreen area
# Create
dri
ver and fullscreen area
screen
=
FullscreenArea
()
server
=
EventSer
ver
(
screen
)
driver
=
create_dri
ver
(
screen
)
# Bind handlers
screen
.
on_tap
(
lambda
g
:
0
)
...
...
@@ -15,6 +14,6 @@ screen.on_double_tap(lambda g: 0)
# Start listening to TUIO events
try
:
ser
ver
.
start
()
dri
ver
.
start
()
except
KeyboardInterrupt
:
ser
ver
.
stop
()
dri
ver
.
stop
()
tests/transform.py
View file @
3036a05c
from
src.event_server
import
EventServer
from
src.areas
import
FullscreenArea
from
tests.parse_arguments
import
create_parser
,
parse_args
from
src
import
FullscreenArea
,
create_driver
parse_args
(
create_parser
())
# Create
ser
ver and fullscreen area
# Create
dri
ver and fullscreen area
screen
=
FullscreenArea
()
server
=
EventSer
ver
(
screen
)
driver
=
create_dri
ver
(
screen
)
# Bind handlers
screen
.
on_rotate
(
lambda
g
:
0
)
...
...
@@ -15,6 +14,6 @@ screen.on_drag(lambda g: 0)
# Start listening to TUIO events
try
:
ser
ver
.
start
()
dri
ver
.
start
()
except
KeyboardInterrupt
:
ser
ver
.
stop
()
dri
ver
.
stop
()
tests/vtk_interactor.py
View file @
3036a05c
...
...
@@ -2,20 +2,19 @@ import vtk
from
threading
import
Thread
from
math
import
degrees
from
src.event_server
import
EventServer
from
src.widgets
import
FullscreenWidget
from
src
import
FullscreenArea
,
create_driver
class
vtkMultitouchInteractor
():
def
__init__
(
self
):
self
.
iren
=
vtk
.
vtkRenderWindowInteractor
()
s
elf
.
widget
=
FullscreenWidget
()
self
.
server
=
EventSer
ver
(
screen
)
s
creen
=
FullscreenArea
()
self
.
driver
=
create_dri
ver
(
screen
)
widget
.
on_rotate
(
self
.
on_rotate
)
widget
.
on_pinch
(
self
.
on_pinch
)
widget
.
on_tap
(
self
.
on_tap
)
screen
.
on_rotate
(
self
.
on_rotate
)
screen
.
on_pinch
(
self
.
on_pinch
)
screen
.
on_tap
(
self
.
on_tap
)
def
SetRenderWindow
(
self
,
window
):
self
.
iren
.
SetRenderWindow
(
window
)
...
...
@@ -29,9 +28,9 @@ class vtkMultitouchInteractor():
#t = Thread(target=self.iren.Start)
#t.daemon = True
#t.start()
#self.
ser
ver.start()
#self.
dri
ver.start()
thread
=
Thread
(
target
=
self
.
ser
ver
.
start
)
thread
=
Thread
(
target
=
self
.
dri
ver
.
start
)
thread
.
daemon
=
True
thread
.
start
()
#self.iren.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