示例#1
0
文件: base.py 项目: vidriloco/pymt
def runTouchApp(widget=None, slave=False):
    '''Static main function that starts the application loop.
    You got some magic things, if you are using argument like this :

    :Parameters:
        `<empty>`
            To make dispatching work, you need at least one
            input listener. If not, application will leave.
            (MTWindow act as an input listener)

        `widget`
            If you pass only a widget, a MTWindow will be created,
            and your widget will be added on the window as the root
            widget.

        `slave`
            No event dispatching are done. This will be your job.

        `widget + slave`
            No event dispatching are done. This will be your job, but
            we are trying to get the window (must be created by you before),
            and add the widget on it. Very usefull for embedding PyMT
            in another toolkit. (like Qt, check pymt-designed)
    
    '''

    global pymt_evloop
    global pymt_providers

    # Ok, we got one widget, and we are not in slave mode
    # so, user don't create the window, let's create it for him !
    ### Not needed, since we always create window ?!
    #if not slave and widget:
    #    global pymt_window
    #    from ui.window import MTWindow
    #    pymt_window = MTWindow()

    # Check if we show event stats
    if pymt.pymt_config.getboolean('pymt', 'show_eventstats'):
        pymt.widget.event_stats_activate()

    # Instance all configured input
    for key, value in pymt.pymt_config.items('input'):
        pymt_logger.debug('Base: Create provider from %s' % (str(value)))

        # split value
        args = str(value).split(',', 1)
        if len(args) == 1:
            args.append('')
        provider_id, args = args
        provider = TouchFactory.get(provider_id)
        if provider is None:
            pymt_logger.warning('Base: Unknown <%s> provider' % str(provider_id))
            continue

        # create provider
        p = provider(key, args)
        if p:
            pymt_providers.append(p)

    pymt_evloop = TouchEventLoop()

    # add postproc modules
    for mod in pymt_postproc_modules:
        pymt_evloop.add_postproc_module(mod)

    # add main widget
    if widget and getWindow():
        getWindow().add_widget(widget)

    # start event loop
    pymt_logger.info('Base: Start application main loop')
    pymt_evloop.start()

    # we are in a slave mode, don't do dispatching.
    if slave:
        return

    # in non-slave mode, they are 2 issues
    #
    # 1. if user created a window, call the mainloop from window.
    #    This is due to glut, it need to be called with
    #    glutMainLoop(). Only FreeGLUT got a gluMainLoopEvent().
    #    So, we are executing the dispatching function inside
    #    a redisplay event.
    #
    # 2. if no window is created, we are dispatching event lopp
    #    ourself (previous behavior.)
    #
    try:
        if pymt_window is None:
            _run_mainloop()
        else:
            pymt_window.mainloop()
    finally:
        stopTouchApp()

    # Show event stats
    if pymt.pymt_config.getboolean('pymt', 'show_eventstats'):
        pymt.widget.event_stats_print()
示例#2
0
文件: __init__.py 项目: imc/pymt
    'camera': ('opencv', 'gstreamer', 'videocapture'),
    'svg': ('squirtle',),
}

# Read environment
for option in options:
    key = 'PYMT_%s' % option.upper()
    if key in os.environ:
        try:
            if type(options[option]) in (list, tuple):
                options[option] = (str(os.environ[key]),)
            else:
                options[option] = os.environ[key].lower() in \
                    ('true', '1', 'yes', 'yup')
        except:
            pymt_logger.warning('Core: Wrong value for %s environment key' % key)
            pymt_logger.exception('')

# Extract all needed path in pymt
#: PyMT directory
pymt_base_dir        = os.path.dirname(sys.modules[__name__].__file__)
#: PyMT external libraries directory
pymt_libs_dir        = os.path.join(pymt_base_dir, 'lib')
#: PyMT modules directory
pymt_modules_dir     = os.path.join(pymt_base_dir, 'modules')
#: PyMT data directory
pymt_data_dir        = os.path.join(pymt_base_dir, 'data')
#: PyMT input provider directory
pymt_providers_dir   = os.path.join(pymt_base_dir, 'input', 'providers')
#: PyMT user-home storage directory
pymt_home_dir        = None
示例#3
0
文件: __init__.py 项目: azoon/pymt
    'image': ('pil', 'pygame'),
    'camera': ('opencv', 'gstreamer', 'videocapture'),
}

# Read environment
for option in options:
    key = 'PYMT_%s' % option.upper()
    if key in os.environ:
        try:
            if type(options[option]) in (list, tuple):
                options[option] = (str(os.environ[key]),)
            else:
                options[option] = os.environ[key].lower() in \
                    ('true', '1', 'yes', 'yup')
        except:
            pymt_logger.warning('Wrong value for %s environment key' % key)
            pymt_logger.exception('')

# Include lib as new module.
pymt_base_dir = os.path.dirname(sys.modules[__name__].__file__)
pymt_libs_dir = os.path.join(pymt_base_dir, 'lib')
pymt_modules_dir = os.path.join(pymt_base_dir, 'modules')
pymt_data_dir = os.path.join(pymt_base_dir, 'data')
pymt_providers_dir = os.path.join(pymt_base_dir, 'input', 'providers')
sys.path = [pymt_libs_dir] + sys.path

# Don't go further if we generate documentation
if not os.path.basename(sys.argv[0]).startswith('sphinx'):

    # Configuration management
    pymt_home_dir = os.path.expanduser('~/.pymt/')
示例#4
0
            pymt_logger.exception('Core: error while reading local configuration')

    pymt_config_version = pymt_config.getdefault('pymt', 'config_version', 0)

# Add defaults section
    pymt_config.adddefaultsection('pymt')
    pymt_config.adddefaultsection('keyboard')
    pymt_config.adddefaultsection('graphics')
    pymt_config.adddefaultsection('input')
    pymt_config.adddefaultsection('dump')
    pymt_config.adddefaultsection('modules')

# Upgrade default configuration until having the current version
    need_save = False
    if pymt_config_version != PYMT_CONFIG_VERSION:
        pymt_logger.warning('Config: Older configuration version detected (%d instead of %d)' % (
                            pymt_config_version, PYMT_CONFIG_VERSION))
        pymt_logger.warning('Config: Upgrading configuration in progress.')
        need_save = True

    while pymt_config_version < PYMT_CONFIG_VERSION:
        pymt_logger.debug('Config: Upgrading from %d' % pymt_config_version)

        # Versionning introduced in version 0.4.
        if pymt_config_version == 0:

            pymt_config.setdefault('pymt', 'show_fps', '0')
            pymt_config.setdefault('pymt', 'show_eventstats', '0')
            pymt_config.setdefault('pymt', 'log_level', 'info')
            pymt_config.setdefault('pymt', 'double_tap_time', '250')
            pymt_config.setdefault('pymt', 'double_tap_distance', '20')
            pymt_config.setdefault('pymt', 'enable_simulator', '1')
示例#5
0
文件: event.py 项目: bernt/pymt
                    raise
                for p in p2:
                    if p is None:
                        continue
                    w2.__setattr__(p, type(w2.__getattribute__(p))(
                        func(largs[p2.index(p)])))
            else:
                dtype = type(w2.__getattribute__(p2))
                try:
                    if len(largs) == 1:
                        w2.__setattr__(p2, dtype(func(*largs)))
                    else:
                        w2.__setattr__(p2, dtype(func(largs)))
                except Exception, e:
                    pymt_logger.exception('Widget: cannot connect with different size')
                    raise
        if p2 is None:
            self.push_handlers(**{p1: w2})
        else:
            self.push_handlers(**{p1: lambda_connect})

# install acceleration
try:
    import types
    from accelerate import accelerate
    if accelerate is not None:
        EventDispatcher.dispatch_event = types.MethodType(
            accelerate.eventdispatcher_dispatch_event, None, EventDispatcher)
except ImportError, e:
    pymt_logger.warning('Event: Unable to use accelerate module <%s>' % e)