コード例 #1
0
ファイル: clock.py プロジェクト: Tanganelli/kivy
def mainthread(func):
    '''Decorator that will schedule the call of the function for the next
    available frame in the mainthread. It can be useful when you use
    :class:`~kivy.network.urlrequest.UrlRequest` or when you do Thread
    programming: you cannot do any OpenGL-related work in a thread.

    Please note that this method will return directly and no result can be
    returned::

        @mainthread
        def callback(self, *args):
            print('The request succedded!',
                  'This callback is called in the main thread.')

        self.req = UrlRequest(url='http://...', on_success=callback)

    .. versionadded:: 1.8.0
    '''
    @wraps(func)
    def delayed_func(*args, **kwargs):
        def callback_func(dt):
            func(*args, **kwargs)
        Clock.schedule_once(callback_func, 0)
    return delayed_func

if 'KIVY_DOC_INCLUDE' in environ:
    #: Instance of :class:`ClockBase`.
    Clock = None
else:
    Clock = register_context('Clock', ClockBase)
コード例 #2
0
ファイル: builder.py プロジェクト: udiboy1209/kivy
                for prule in crule.properties.values():
                    key = prule.name
                    value = prule.co_value
                    if type(value) is CodeType:
                        value, _ = create_handler(
                            widget, instr.proxy_ref,
                            key, value, prule, idmap, True)
                    setattr(instr, key, value)
            except Exception as e:
                tb = sys.exc_info()[2]
                raise BuilderException(
                    prule.ctx, prule.line,
                    '{}: {}'.format(e.__class__.__name__, e), cause=tb)

#: Main instance of a :class:`BuilderBase`.
Builder = register_context('Builder', BuilderBase)
Builder.load_file(join(kivy_data_dir, 'style.kv'), rulesonly=True)

if 'KIVY_PROFILE_LANG' in environ:
    import atexit
    import cgi

    def match_rule(fn, index, rule):
        if rule.ctx.filename != fn:
            return
        for prop, prp in iteritems(rule.properties):
            if prp.line != index:
                continue
            yield prp
        for child in rule.children:
            for r in match_rule(fn, index, child):
コード例 #3
0
ファイル: clock.py プロジェクト: kivy/kivy
            _kwargs.clear()
            _kwargs.update(kwargs)
            cb_trigger()

        def trigger_cancel():
            cb_trigger.cancel()

        setattr(trigger_function, 'cancel', trigger_cancel)

        return trigger_function

    return wrapper_triggered


if 'KIVY_DOC_INCLUDE' in environ:
    #: Instance of :class:`ClockBaseBehavior`.
    Clock = None
else:
    _classes = {'default': ClockBase, 'interrupt': ClockBaseInterrupt,
                'free_all': ClockBaseFreeInterruptAll,
                'free_only': ClockBaseFreeInterruptOnly}
    _clk = environ.get('KIVY_CLOCK', Config.get('kivy', 'kivy_clock'))
    if _clk not in _classes:
        raise Exception(
            '{} is not a valid kivy clock. Valid clocks are {}'.format(
                _clk, sorted(_classes.keys())))

    Clock = register_context('Clock', _classes[_clk])
    '''The kivy Clock instance. See module documentation for details.
    '''
コード例 #4
0
ファイル: base.py プロジェクト: 15huangtimothy/kivy
    def remove_handler(self, cls):
        '''Remove a exception handler from the stack.'''
        if cls in self.handlers:
            self.handlers.remove(cls)

    def handle_exception(self, inst):
        '''Called when an exception occured in the runTouchApp() main loop.'''
        ret = self.policy
        for handler in self.handlers:
            r = handler.handle_exception(inst)
            if r == ExceptionManagerBase.PASS:
                ret = r
        return ret

#: Instance of a :class:`ExceptionManagerBase` implementation.
ExceptionManager = register_context('ExceptionManager', ExceptionManagerBase)


class EventLoopBase(EventDispatcher):
    '''Main event loop. This loop handles the updating of input and
    dispatching events.
    '''

    __events__ = ('on_start', 'on_pause', 'on_stop')

    def __init__(self):
        super(EventLoopBase, self).__init__()
        self.quit = False
        self.input_events = []
        self.postproc_modules = []
        self.status = 'idle'
コード例 #5
0
        if cls in self.handlers:
            self.handlers.remove(cls)

    def handle_exception(self, inst):
        '''Called when an exception occurred in the :func:`runTouchApp`
        main loop.'''
        ret = self.policy
        for handler in self.handlers:
            r = handler.handle_exception(inst)
            if r == ExceptionManagerBase.PASS:
                ret = r
        return ret


#: Instance of a :class:`ExceptionManagerBase` implementation.
ExceptionManager: ExceptionManagerBase = register_context(
    'ExceptionManager', ExceptionManagerBase)
"""The :class:`ExceptionManagerBase` instance that handles kivy exceptions.
"""


class EventLoopBase(EventDispatcher):
    '''Main event loop. This loop handles the updating of input and
    dispatching events.
    '''

    __events__ = ('on_start', 'on_pause', 'on_stop')

    def __init__(self):
        super(EventLoopBase, self).__init__()
        self.quit = False
        self.input_events = []
コード例 #6
0
ファイル: clock.py プロジェクト: jesseanderson/kivy
    :class:`~kivy.network.urlrequest.UrlRequest` or when you do Thread
    programming: you cannot do any OpenGL-related work in a thread.

    Please note that this method will return directly and no result can be
    returned::

        @mainthread
        def callback(self, *args):
            print('The request succedded!'
                  'This callback is call in the main thread')

        self.req = UrlRequest(url='http://...', on_success=callback)

    .. versionadded:: 1.8.0
    """

    def delayed_func(*args, **kwargs):
        def callback_func(dt):
            func(*args, **kwargs)

        Clock.schedule_once(callback_func, 0)

    return delayed_func


if "KIVY_DOC_INCLUDE" in environ:
    #: Instance of :class:`ClockBase`.
    Clock = None
else:
    Clock = register_context("Clock", ClockBase)
コード例 #7
0
    '''
    @wraps(func)
    def delayed_func(*args, **kwargs):
        def callback_func(dt):
            func(*args, **kwargs)

        Clock.schedule_once(callback_func, 0)

    return delayed_func


if 'KIVY_DOC_INCLUDE' in environ:
    #: Instance of :class:`ClockBaseBehavior`.
    Clock = None
else:
    _classes = {
        'default': ClockBase,
        'interrupt': ClockBaseInterrupt,
        'free_all': ClockBaseFreeInterruptAll,
        'free_only': ClockBaseFreeInterruptOnly
    }
    _clk = environ.get('KIVY_CLOCK', Config.get('kivy', 'kivy_clock'))
    if _clk not in _classes:
        raise Exception(
            '{} is not a valid kivy clock. Valid clocks are {}'.format(
                _clk, sorted(_classes.keys())))

    Clock = register_context('Clock', _classes[_clk])
    '''The kivy Clock instance. See module documentation for details.
    '''
コード例 #8
0
ファイル: builder.py プロジェクト: markpengisme/Python
                    value = prule.co_value
                    if type(value) is CodeType:
                        value, _ = create_handler(widget, instr.proxy_ref, key,
                                                  value, prule, idmap, True)
                    setattr(instr, key, value)
            except Exception as e:
                tb = sys.exc_info()[2]
                raise BuilderException(prule.ctx,
                                       prule.line,
                                       '{}: {}'.format(e.__class__.__name__,
                                                       e),
                                       cause=tb)


#: Main instance of a :class:`BuilderBase`.
Builder = register_context('Builder', BuilderBase)
Builder.load_file(join(kivy_data_dir, 'style.kv'), rulesonly=True)

if 'KIVY_PROFILE_LANG' in environ:
    import atexit
    import cgi

    def match_rule(fn, index, rule):
        if rule.ctx.filename != fn:
            return
        for prop, prp in iteritems(rule.properties):
            if prp.line != index:
                continue
            yield prp
        for child in rule.children:
            for r in match_rule(fn, index, child):
コード例 #9
0
            cb_trigger()

        def trigger_cancel():
            cb_trigger.cancel()

        setattr(trigger_function, 'cancel', trigger_cancel)

        return trigger_function

    return wrapper_triggered


if 'KIVY_DOC_INCLUDE' in environ:
    #: Instance of :class:`ClockBaseBehavior`.
    Clock: ClockBase = None
else:
    _classes = {'default': ClockBase, 'interrupt': ClockBaseInterrupt,
                'free_all': ClockBaseFreeInterruptAll,
                'free_only': ClockBaseFreeInterruptOnly}
    _clk = environ.get('KIVY_CLOCK', Config.get('kivy', 'kivy_clock'))
    if _clk not in _classes:
        raise Exception(
            '{} is not a valid kivy clock. Valid clocks are {}'.format(
                _clk, sorted(_classes.keys())))

    Clock: ClockBase = register_context(
        'Clock', _classes[_clk],
        async_lib=environ.get('KIVY_EVENTLOOP', 'asyncio'))
    '''The kivy Clock instance. See module documentation for details.
    '''
コード例 #10
0
ファイル: knspace.py プロジェクト: Kulothungan16/kivy
        knspace = self.knspace
        if old_name and knspace and getattr(knspace, old_name) == self:
            setattr(knspace, old_name, None)

        self._knsname = value
        if value:
            if knspace:
                setattr(knspace, value, self)
            else:
                raise ValueError(
                    'Object has name "{}", but no namespace'.format(value))

    knsname = AliasProperty(_get_knsname,
                            _set_knsname,
                            bind=('_knsname', ),
                            cache=False)
    '''The name given to this instance. If named, the name will be added to the
    associated :attr:`knspace` namespace, which will then point to the
    `proxy_ref` of this instance.

    When named, one can access this object by e.g. self.knspace.name, where
    `name` is the given name of this instance. See :attr:`knspace` and the
    module description for more details.
    '''


knspace = register_context('knspace', KNSpace)
'''The default :class:`KNSpace` namespace. See :attr:`KNSpaceBehavior.knspace`
for more details.
'''
コード例 #11
0
    mainthread.  It can be useful when you use
    :class:`~kivy.network.urlrequest.UrlRequest` or when you do Thread
    programming: you cannot do any OpenGL-related work in a thread.

    Please note that this method will return directly and no result can be
    returned::

        @mainthread
        def callback(self, *args):
            print('The request succedded!'
                  'This callback is call in the main thread')

        self.req = UrlRequest(url='http://...', on_success=callback)

    .. versionadded:: 1.8.0
    '''
    def delayed_func(*args, **kwargs):
        def callback_func(dt):
            func(*args, **kwargs)

        Clock.schedule_once(callback_func, 0)

    return delayed_func


if 'KIVY_DOC_INCLUDE' in environ:
    #: Instance of :class:`ClockBase`.
    Clock = None
else:
    Clock = register_context('Clock', ClockBase)
コード例 #12
0
ファイル: factory.py プロジェクト: sonnyky/kivy
                    raise FactoryException(
                        'No class named <%s> in module <%s>' %
                        (name, item['module']))
                cls = item['cls'] = getattr(module, name)

            elif item['baseclasses']:
                rootwidgets = []
                for basecls in item['baseclasses'].split('+'):
                    rootwidgets.append(Factory.get(basecls))
                cls = item['cls'] = type(str(name), tuple(rootwidgets), {})

            else:
                raise FactoryException('No information to create the class')

        return cls

    get = __getattr__


#: Factory instance to use for getting new classes
Factory: FactoryBase = register_context('Factory', FactoryBase)

# Now import the file with all registers
# automatically generated by build_factory
import kivy.factory_registers  # NOQA
Logger.info('Factory: %d symbols loaded' % len(Factory.classes))

if __name__ == '__main__':
    Factory.register('Vector', module='kivy.vector')
    Factory.register('Widget', module='kivy.uix.widget')
コード例 #13
0
ファイル: main.py プロジェクト: matham/go_nogo
'''The main module that starts the experiment.
'''

__all__ = ('ExperimentApp', 'run_app')

# TODO: fix restart

import os
from moa.clock import MoaClockBase
from kivy.context import register_context
import kivy
if not os.environ.get('SPHINX_DOC_INCLUDE', None):
    kivy.clock.Clock = register_context('Clock', MoaClockBase)
    from kivy.config import Config
    Config.set('kivy', 'exit_on_escape', 0)
    Config.set('kivy', 'multitouch_on_demand', 1)

from kivy.properties import (ObjectProperty, OptionProperty,
    ConfigParserProperty, StringProperty, BooleanProperty, NumericProperty)
from kivy import resources
from kivy.modules import inspector
from kivy.core.window import Window
from kivy.factory import Factory
from kivy.animation import Sequence, Animation

from moa.app import MoaApp
from moa.compat import unicode_type
from moa.config import ConfigParser
from go_nogo.graphics import MainView
from go_nogo.stages import RootStage
from go_nogo import device_config_name, exp_config_name