diff --git a/kivy/input/providers/tuio.py b/kivy/input/providers/tuio.py index 5d19c0085..6e4b8e160 100644 --- a/kivy/input/providers/tuio.py +++ b/kivy/input/providers/tuio.py @@ -39,13 +39,14 @@ You must add the provider before your application is run, like this:: __all__ = ('TuioMotionEventProvider', 'Tuio2dCurMotionEvent', 'Tuio2dObjMotionEvent') -from kivy.lib import osc +from kivy.logger import Logger + +from functools import partial from collections import deque from kivy.input.provider import MotionEventProvider from kivy.input.factory import MotionEventFactory from kivy.input.motionevent import MotionEvent from kivy.input.shape import ShapeRect -from kivy.logger import Logger class TuioMotionEventProvider(MotionEventProvider): @@ -131,21 +132,27 @@ class TuioMotionEventProvider(MotionEventProvider): def start(self): '''Start the TUIO provider''' - self.oscid = osc.listen(self.ip, self.port) + try: + from oscpy.server import OSCThreadServer + except ImportError: + Logger.info( + 'Please install the oscpy python module to use the TUIO ' + 'provider.' + ) + raise + self.oscid = osc = OSCThreadServer() + osc.listen(self.ip, self.port, default=True) for oscpath in TuioMotionEventProvider.__handlers__: self.touches[oscpath] = {} - osc.bind(self.oscid, self._osc_tuio_cb, oscpath) + osc.bind(oscpath, partial(self._osc_tuio_cb, oscpath)) def stop(self): '''Stop the TUIO provider''' - osc.dontListen(self.oscid) + self.oscid.stop_all() def update(self, dispatch_fn): '''Update the TUIO provider (pop events from the queue)''' - # deque osc queue - osc.readQueue(self.oscid) - # read the Queue with event while True: try: @@ -155,37 +162,34 @@ class TuioMotionEventProvider(MotionEventProvider): return self._update(dispatch_fn, value) - def _osc_tuio_cb(self, *incoming): - message = incoming[0] - oscpath, types, args = message[0], message[1], message[2:] - self.tuio_event_q.appendleft([oscpath, args, types]) + def _osc_tuio_cb(self, oscpath, address, *args): + self.tuio_event_q.appendleft([oscpath, address, args]) def _update(self, dispatch_fn, value): - oscpath, args, types = value - command = args[0] + oscpath, command, args = value # verify commands - if command not in ['alive', 'set']: + if command not in [b'alive', b'set']: return # move or create a new touch - if command == 'set': - id = args[1] + if command == b'set': + id = args[0] if id not in self.touches[oscpath]: # new touch touch = TuioMotionEventProvider.__handlers__[oscpath]( - self.device, id, args[2:]) + self.device, id, args[1:]) self.touches[oscpath][id] = touch dispatch_fn('begin', touch) else: # update a current touch touch = self.touches[oscpath][id] - touch.move(args[2:]) + touch.move(args[1:]) dispatch_fn('update', touch) # alive event, check for deleted touch - if command == 'alive': - alives = args[1:] + if command == b'alive': + alives = args to_delete = [] for id in self.touches[oscpath]: if id not in alives: @@ -326,7 +330,7 @@ class Tuio2dBlbMotionEvent(TuioMotionEvent): # registers -TuioMotionEventProvider.register('/tuio/2Dcur', Tuio2dCurMotionEvent) -TuioMotionEventProvider.register('/tuio/2Dobj', Tuio2dObjMotionEvent) -TuioMotionEventProvider.register('/tuio/2Dblb', Tuio2dBlbMotionEvent) +TuioMotionEventProvider.register(b'/tuio/2Dcur', Tuio2dCurMotionEvent) +TuioMotionEventProvider.register(b'/tuio/2Dobj', Tuio2dObjMotionEvent) +TuioMotionEventProvider.register(b'/tuio/2Dblb', Tuio2dBlbMotionEvent) MotionEventFactory.register('tuio', TuioMotionEventProvider) diff --git a/kivy/lib/osc/__init__.py b/kivy/lib/osc/__init__.py index eca388f76..b5d06712e 100644 --- a/kivy/lib/osc/__init__.py +++ b/kivy/lib/osc/__init__.py @@ -20,7 +20,12 @@ __author__ = "www.ixi-software.net" __license__ = "GNU General Public License" __all__ = ("oscAPI", "OSC") +from kivy.logger import Logger +Logger.warn( + 'The kivy.lib.osc package has been replaced with `oscpy` and will be ' + 'removed in a future version' +) + from .OSC import * from .oscAPI import * - diff --git a/setup.py b/setup.py index e24f4d7b3..0c3e2e46d 100644 --- a/setup.py +++ b/setup.py @@ -1103,7 +1103,12 @@ if not build_examples: 'Topic :: Software Development :: User Interfaces'], dependency_links=[ 'https://github.com/kivy-garden/garden/archive/master.zip'], - install_requires=['Kivy-Garden>=0.1.4', 'docutils', 'pygments'], + install_requires=[ + 'Kivy-Garden>=0.1.4', 'docutils', 'pygments' + ], + extra_requires={ + 'tuio': ['oscpy'] + }, setup_requires=[ 'cython>=' + MIN_CYTHON_STRING ] if not skip_cython else [])