Commit 530c6a5f authored by Taddeus Kroes's avatar Taddeus Kroes

Added 'unbind' method and moved screen_size to a separate file to prevent cyclic imports.

parent d0ffb5c1
import pygame.display
__all__ = ['screen_size']
# get screen resolution
pygame.display.init()
info = pygame.display.Info()
screen_size = info.current_w, info.current_h
pygame.display.quit()
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import division from __future__ import division
import time import time
import pygame.display
from math import atan2, pi from math import atan2, pi
from threading import Thread from threading import Thread
from screen import screen_size
from tuio_server import TuioServer2D from tuio_server import TuioServer2D
from logger import Logger from logger import Logger
from events import Event, DownEvent, UpEvent, MoveEvent, Tap, \ from events import Event, DownEvent, UpEvent, MoveEvent, Tap, \
SingleTap, DoubleTap, Flick, Rotate, Pinch, \ SingleTap, DoubleTap, Flick, Rotate, Pinch, \
Pan Pan
# get screen resolution
pygame.display.init()
info = pygame.display.Info()
screen_size = info.current_w, info.current_h
pygame.display.quit()
# Heuristic constants # Heuristic constants
# TODO: Encapsulate screen resolution in distance heuristics # TODO: Encapsulate screen resolution in distance heuristics
SUPPORTED_EVENTS = ('down', 'up', 'move', 'tap', 'single_tap', 'double_tap', SUPPORTED_EVENTS = ('down', 'up', 'move', 'tap', 'single_tap', 'double_tap',
...@@ -401,17 +395,30 @@ class MultitouchServer(Logger): ...@@ -401,17 +395,30 @@ class MultitouchServer(Logger):
except SystemExit: except SystemExit:
self.stop() self.stop()
def bind(self, gesture, handler, *args, **kwargs): def bind(self, name, handler, *args, **kwargs):
""" """
Bind a handler to an event or gesture. Bind a handler to an event or gesture.
""" """
if gesture not in SUPPORTED_EVENTS: if name not in SUPPORTED_EVENTS:
raise ValueError('Unsupported gesture "%s".' % gesture) raise ValueError('Unsupported event name "%s".' % name)
if name not in self.handlers:
self.handlers[name] = []
self.handlers[name].append((handler, args, kwargs))
if gesture not in self.handlers: def unbind(self, name, handler=None):
self.handlers[gesture] = [] """
Remove one or all handlers that are bound to an event name.
"""
if name not in self.handlers:
raise KeyError('No handlers are bound to event name "%s".' % name)
self.handlers[gesture].append((handler, args, kwargs)) if handler:
self.handlers[name] = [h for h in self.handlers[name]
if h[0] != handler]
else:
del self.handlers[name]
def trigger(self, event): def trigger(self, event):
""" """
......
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