Exemplo n.º 1
0
        def __init__(self, device, args):
            super(ProbeSysfsHardwareProbe, self).__init__(device, args)
            self.provider = 'mtdev'
            self.match = None
            self.input_path = '/sys/class/input'
            self.args = []

            args = args.split(',')
            for arg in args:
                if arg == '':
                    continue
                arg = arg.split('=', 1)
                # ensure it's a key = value
                if len(arg) != 2:
                    pymt_logger.error('ProbeSysfs: invalid parameters %s, not'
                                      ' key=value format' % arg)
                    continue

                key, value = arg
                if key == 'match':
                    self.match = value
                elif key == 'provider':
                    self.provider = value
                elif key == 'param':
                    self.args.append(value)
                else:
                    pymt_logger.error('ProbeSysfs: unknown %s option' % key)
                    continue

            self.probe()
Exemplo n.º 2
0
    def run(self):
        self.haveSocket = False
        # create socket
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # fix trouble if python leave without cleaning well the socket
        # not needed under windows, he can reuse addr even if the socket
        # are in fin2 or wait state.
        if os.name in ['posix', 'mac'] and hasattr(socket, 'SO_REUSEADDR'):
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        # try to bind the socket, retry if necessary
        while not self.haveSocket and self.isRunning:
            try :
                self.socket.bind((self.ipAddr, self.port))
                self.socket.settimeout(0.5)
                self.haveSocket = True

            except socket.error, e:
                error, message = e.args

                # special handle for EADDRINUSE
                if error == errno.EADDRINUSE:
                    pymt_logger.error('OSC: Address %s:%i already in use, retry in 2 second' % (self.ipAddr, self.port))
                else:
                    pymt_logger.exception(e)
                self.haveSocket = False

                # sleep 2 second before retry
                time.sleep(2)
Exemplo n.º 3
0
    def run(self):
        self.haveSocket = False
        # create socket
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # fix trouble if python leave without cleaning well the socket
        # not needed under windows, he can reuse addr even if the socket
        # are in fin2 or wait state.
        if os.name in ['posix', 'mac'] and hasattr(socket, 'SO_REUSEADDR'):
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        # try to bind the socket, retry if necessary
        while not self.haveSocket and self.isRunning:
            try:
                self.socket.bind((self.ipAddr, self.port))
                self.socket.settimeout(0.5)
                self.haveSocket = True

            except socket.error, e:
                error, message = e.args

                # special handle for EADDRINUSE
                if error == errno.EADDRINUSE:
                    pymt_logger.error(
                        'OSC: Address %s:%i already in use, retry in 2 second'
                        % (self.ipAddr, self.port))
                else:
                    pymt_logger.exception(e)
                self.haveSocket = False

                # sleep 2 second before retry
                time.sleep(2)
Exemplo n.º 4
0
def parse_filename(filename):
    '''Parse a filename, and search inside resource if exist.
    If we haven't found it, just return the name.
    '''
    filename = parse_string(filename)
    result = resource_find(filename)
    if result is None:
        pymt_logger.error('Resource: unable to found <%s>' % filename)
    return result or filename
Exemplo n.º 5
0
        def __init__(self, device, args):
            super(LinuxWacomTouchProvider, self).__init__(device, args)
            self.input_fn = None
            self.default_ranges = dict()
            self.mode = 'touch'

            # split arguments
            args = args.split(',')
            if not args:
                pymt_logger.error(
                    'LinuxWacom: No filename pass to LinuxWacom configuration')
                pymt_logger.error(
                    'LinuxWacom: Use /dev/input/event0 for example')
                return None

            # read filename
            self.input_fn = args[0]
            pymt_logger.info('LinuxWacom: Read event from <%s>' %
                             self.input_fn)

            # read parameters
            for arg in args[1:]:
                if arg == '':
                    continue
                arg = arg.split('=')

                # ensure it's a key = value
                if len(arg) != 2:
                    pymt_logger.error(
                        'LinuxWacom: invalid parameter %s, not in key=value format.'
                        % arg)
                    continue

                # ensure the key exist
                key, value = arg
                if key == 'mode':
                    self.mode = value
                    continue

                if key not in LinuxWacomTouchProvider.options:
                    pymt_logger.error('LinuxWacom: unknown %s option' % key)
                    continue

                # ensure the value
                try:
                    self.default_ranges[key] = int(value)
                except ValueError:
                    pymt_logger.error(
                        'LinuxWacom: invalid value %s for option %s' %
                        (key, value))
                    continue

                # all good!
                pymt_logger.info('LinuxWacom: Set custom %s to %d' %
                                 (key, int(value)))
            pymt_logger.info('LinuxWacom: mode is <%s>' % self.mode)
Exemplo n.º 6
0
 def _on_gst_message(self, bus, message):
     t = message.type
     if t == gst.MESSAGE_EOS:
         self._data.set_state(gst.STATE_NULL)
         self.stop()
     elif t == gst.MESSAGE_ERROR:
         self._data.set_state(gst.STATE_NULL)
         err, debug = message.parse_error()
         pymt_logger.error('AudioGstreamer: %s' % err)
         pymt_logger.debug(str(debug))
         self.stop()
Exemplo n.º 7
0
 def _on_gst_message(self, bus, message):
     t = message.type
     if t == gst.MESSAGE_EOS:
         self._data.set_state(gst.STATE_NULL)
         self.stop()
     elif t == gst.MESSAGE_ERROR:
         self._data.set_state(gst.STATE_NULL)
         err, debug = message.parse_error()
         pymt_logger.error('AudioGstreamer: %s' % err)
         pymt_logger.debug(str(debug))
         self.stop()
Exemplo n.º 8
0
        def __init__(self, device, args):
            super(LinuxWacomTouchProvider, self).__init__(device, args)
            self.input_fn = None
            self.default_ranges = dict()
            self.mode = 'touch'

            # split arguments
            args = args.split(',')
            if not args:
                pymt_logger.error('LinuxWacom: No filename pass to LinuxWacom configuration')
                pymt_logger.error('LinuxWacom: Use /dev/input/event0 for example')
                return None

            # read filename
            self.input_fn = args[0]
            pymt_logger.info('LinuxWacom: Read event from <%s>' % self.input_fn)

            # read parameters
            for arg in args[1:]:
                if arg == '':
                    continue
                arg = arg.split('=')

                # ensure it's a key = value
                if len(arg) != 2:
                    pymt_logger.error('LinuxWacom: invalid parameter %s, not in key=value format.' % arg)
                    continue

                # ensure the key exist
                key, value = arg
                if key == 'mode':
                    self.mode = value
                    continue

                if key not in LinuxWacomTouchProvider.options:
                    pymt_logger.error('LinuxWacom: unknown %s option' % key)
                    continue

                # ensure the value
                try:
                    self.default_ranges[key] = int(value)
                except ValueError:
                    pymt_logger.error('LinuxWacom: invalid value %s for option %s' % (key, value))
                    continue

                # all good!
                pymt_logger.info('LinuxWacom: Set custom %s to %d' % (key, int(value)))
            pymt_logger.info('LinuxWacom: mode is <%s>' % self.mode)
Exemplo n.º 9
0
    def __init__(self, device, args):
        super(MouseTouchProvider, self).__init__(device, args)
        self.waiting_event = deque()
        self.window = None
        self.touches = {}
        self.counter = 0
        self.current_drag = None
        self.alt_touch = None
        self.disable_on_activity = False

        # split arguments
        args = args.split(',')
        for arg in args:
            if arg == '':
                continue
            elif arg == 'disable_on_activity':
                self.disable_on_activity = True
            else:
                pymt_logger.error('Mouse: unknown parameter <%s>' % arg)
Exemplo n.º 10
0
        def __init__(self, device, args):
            super(MTDTouchProvider, self).__init__(device, args)
            self._device = None
            self.input_fn = None
            self.default_ranges = dict()

            # split arguments
            args = args.split(",")
            if not args:
                pymt_logger.error("MTD: No filename pass to MTD configuration")
                pymt_logger.error("MTD: Use /dev/input/event0 for example")
                return None

            # read filename
            self.input_fn = args[0]
            pymt_logger.info("MTD: Read event from <%s>" % self.input_fn)

            # read parameters
            for arg in args[1:]:
                if arg == "":
                    continue
                arg = arg.split("=")

                # ensure it's a key = value
                if len(arg) != 2:
                    pymt_logger.error("MTD: invalid parameter %s, not in key=value format." % arg)
                    continue

                # ensure the key exist
                key, value = arg
                if key not in MTDTouchProvider.options:
                    pymt_logger.error("MTD: unknown %s option" % key)
                    continue

                # ensure the value
                try:
                    self.default_ranges[key] = int(value)
                except ValueError:
                    pymt_logger.error("MTD: invalid value %s for option %s" % (key, value))
                    continue

                # all good!
                pymt_logger.info("MTD: Set custom %s to %d" % (key, int(value)))
Exemplo n.º 11
0
    def __init__(self, device, args):
        super(MouseTouchProvider, self).__init__(device, args)
        self.waiting_event = deque()
        self.window = None
        self.touches = {}
        self.counter = 0
        self.current_drag = None
        self.alt_touch = None
        self.disable_on_activity = False

        # split arguments
        args = args.split(',')
        for arg in args:
            if arg == '':
                continue
            elif arg == 'disable_on_activity':
                self.disable_on_activity = True
            else:
                pymt_logger.error('Mouse: unknown parameter <%s>' % arg)
Exemplo n.º 12
0
class OSCServer(_OSCServer):
    def __init__(self, **kwargs):
        kwargs.setdefault('ipAddr', '127.0.0.1')
        kwargs.setdefault('port', 9001)
        super(OSCServer, self).__init__()
        self.ipAddr = kwargs.get('ipAddr')
        self.port = kwargs.get('port')

    def run(self):
        self.haveSocket = False
        # create socket
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        # fix trouble if python leave without cleaning well the socket
        # not needed under windows, he can reuse addr even if the socket
        # are in fin2 or wait state.
        if os.name in ['posix', 'mac'] and hasattr(socket, 'SO_REUSEADDR'):
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        # try to bind the socket, retry if necessary
        while not self.haveSocket and self.isRunning:
            try:
                self.socket.bind((self.ipAddr, self.port))
                self.socket.settimeout(0.5)
                self.haveSocket = True

            except socket.error, e:
                error, message = e.args

                # special handle for EADDRINUSE
                if error == errno.EADDRINUSE:
                    pymt_logger.error(
                        'OSC: Address %s:%i already in use, retry in 2 second'
                        % (self.ipAddr, self.port))
                else:
                    pymt_logger.exception(e)
                self.haveSocket = False

                # sleep 2 second before retry
                time.sleep(2)

        pymt_logger.info('OSC: listening for Tuio on %s:%i' %
                         (self.ipAddr, self.port))

        while self.isRunning:
            try:
                message = self.socket.recv(65535)
                self._queue_message(message)
            except Exception, e:
                if type(e) == socket.timeout:
                    continue
                pymt_logger.error('OSC: Error in Tuio recv()')
                pymt_logger.exception(e)
                return 'no data arrived'
Exemplo n.º 13
0
 def __init__(self, device, args):
     super(TuioTouchProvider, self).__init__(device, args)
     args = args.split(',')
     if len(args) <= 0:
         pymt_logger.error('Tuio: Invalid configuration for TUIO provider')
         pymt_logger.error('Tuio: Format must be ip:port (eg. 127.0.0.1:3333)')
         pymt_logger.error('Tuio: Actual TUIO configuration is <%s>' % (str(','.join(args))))
         return None
     ipport = args[0].split(':')
     if len(ipport) != 2:
         pymt_logger.error('Tuio: Invalid configuration for TUIO provider')
         pymt_logger.error('Tuio: Format must be ip:port (eg. 127.0.0.1:3333)')
         pymt_logger.error('Tuio: Actual TUIO configuration is <%s>' % (str(','.join(args))))
         return None
     self.ip, self.port = args[0].split(':')
     self.port = int(self.port)
     self.handlers = {}
     self.oscid = None
     self.tuio_event_q = deque()
     self.touches = {}
Exemplo n.º 14
0
            elif opt in ('-s', '--save'):
                need_save = True
            elif opt in ('-n', ):
                pymt_options['shadow_window'] = False

        if need_save:
            try:
                with open(pymt_config_fn, 'w') as fd:
                    pymt_config.write(fd)
            except Exception, e:
                pymt_logger.exception('Core: error while saving default'
                                      'configuration file')
            pymt_logger.info('Core: PyMT configuration saved.')
            sys.exit(0)

        # last initialization
        if pymt_options['shadow_window']:
            pymt_logger.debug('Core: Creating PyMT Window')
            shadow_window = MTWindow()
            pymt_configure()

    except getopt.GetoptError, err:
        pymt_logger.error('Core: %s' % str(err))
        pymt_usage()
        sys.exit(2)

# cleanup namespace
if not 'PYMT_DOC_INCLUDE' in os.environ:
    del level, need_save, opts, args
del sys, getopt, os, key
Exemplo n.º 15
0
            elif opt in ('-r', '--rotation'):
                pymt_config.set('graphics', 'rotation', arg)
            elif opt in ('-n', ):
                pymt_options['shadow_window'] = False

        if need_save:
            try:
                with open(pymt_config_fn, 'w') as fd:
                    pymt_config.write(fd)
            except Exception, e:
                pymt_logger.exception('Core: error while saving default'
                                      'configuration file')
            pymt_logger.info('Core: PyMT configuration saved.')
            sys.exit(0)

        # last initialization
        if pymt_options['shadow_window']:
            pymt_logger.debug('Core: Creating PyMT Window')
            shadow_window = MTWindow()
            pymt_configure()

    except getopt.GetoptError, err:
        pymt_logger.error('Core: %s' % str(err))
        pymt_usage()
        sys.exit(2)

# cleanup namespace
if not 'PYMT_DOC_INCLUDE' in os.environ:
    del level, need_save, opts, args
del sys, getopt, os, key
Exemplo n.º 16
0
 def __init__(self, device, args):
     super(TuioTouchProvider, self).__init__(device, args)
     args = args.split(',')
     if len(args) <= 0:
         pymt_logger.error('Tuio: Invalid configuration for TUIO provider')
         pymt_logger.error(
             'Tuio: Format must be ip:port (eg. 127.0.0.1:3333)')
         pymt_logger.error('Tuio: Actual TUIO configuration is <%s>' %
                           (str(','.join(args))))
         return None
     ipport = args[0].split(':')
     if len(ipport) != 2:
         pymt_logger.error('Tuio: Invalid configuration for TUIO provider')
         pymt_logger.error(
             'Tuio: Format must be ip:port (eg. 127.0.0.1:3333)')
         pymt_logger.error('Tuio: Actual TUIO configuration is <%s>' %
                           (str(','.join(args))))
         return None
     self.ip, self.port = args[0].split(':')
     self.port = int(self.port)
     self.handlers = {}
     self.oscid = None
     self.tuio_event_q = deque()
     self.touches = {}