Exemplo n.º 1
0
    def build(self):
        # set fullscreen and resolution
        if self.exp._fullscreen is not None:
            Window.fullscreen = self.exp._fullscreen
        if self.exp._resolution is not None:
            Window.system_size = self.exp._resolution

        # handle setting the bg color
        self.set_background_color()

        # base layout uses positional placement
        self.wid = FloatLayout()
        Window._system_keyboard.bind(on_key_down=self._on_key_down,
                                     on_key_up=self._on_key_up)
        Window.bind(on_motion=self._on_motion,
                    mouse_pos=self._on_mouse_pos,
                    on_resize=self._on_resize)
        self.current_touch = None

        # set starting times
        self._post_dispatch_time = clock.now()

        # use our idle callback (defined below)
        kivy.base.EventLoop.set_idle_callback(self._idle_callback)

        # get start of event loop
        EventLoop.bind(on_start=self._on_start)

        # set width and height
        self.exp._screen._set_width(Window.width)
        self.exp._screen._set_height(Window.height)

        return self.wid
Exemplo n.º 2
0
Arquivo: main.py Projeto: npl2dq/smile
    def build(self):
        # set fullscreen and resolution
        if self.exp._fullscreen is not None:
            # set based on the experiment preference
            Window.fullscreen = self.exp._fullscreen

            if Window.fullscreen == False:
                # make sure we have a border
                Window.borderless = False

        if self.exp._resolution is not None:
            Window.system_size = self.exp._resolution

        # handle setting the bg color
        self.set_background_color()

        # base layout uses positional placement
        self.wid = FloatLayout()
        Window._system_keyboard.bind(on_key_down=self._on_key_down,
                                     on_key_up=self._on_key_up)
        Window.bind(on_motion=self._on_motion,
                    mouse_pos=self._on_mouse_pos,
                    on_resize=self._on_resize)
        self.current_touch = None

        # set starting times
        self._post_dispatch_time = clock.now()

        # use our idle callback (defined below)
        kivy.base.EventLoop.set_idle_callback(self._idle_callback)

        # get start of event loop
        EventLoop.bind(on_start=self._on_start)

        # set width and height
        self.exp._screen._set_width(Window.width)
        self.exp._screen._set_height(Window.height)
        scale._calc_scale_factor(Window.width, Window.height)

        self.exp._sysinfo.update({
            "screen_size": [Window.width, Window.height],
            "scale_factor": scale._scale_factor
        })
        self.exp._write_sysinfo()

        return self.wid
Exemplo n.º 3
0
 def __init__(self, **kwargs):
     self._root_node = kwargs.get('root_node')
     self._init_complete = False
     self._nodes_built = False
     self.root_button = None
     super(MainWin, self).__init__(**kwargs)
     EventLoop.bind(on_start=self.on_event_loop_start)
     self.menu_bar = MenuBar()
     self.add_widget(self.menu_bar)
     self.debug_label = Label()
     self.add_widget(self.debug_label)
     self.node_bubble = NodeBubble()
     self.menu_bar.file_menu.bind(on_new_file=self.do_file_new, 
                                  on_open_file=self.do_file_open, 
                                  on_save_file=self.do_file_save)
     if self.root_node is not None:
         self.build_nodes()
Exemplo n.º 4
0
    def build(self):
        # base layout uses positional placement
        self.wid = FloatLayout()
        Window._system_keyboard.bind(on_key_down=self._on_key_down,
                                     on_key_up=self._on_key_up)
        Window.bind(on_motion=self._on_motion,
                    mouse_pos=self._on_mouse_pos,
                    on_resize=self._on_resize)
        self.current_touch = None

        # set starting times
        self._last_time = clock.now()
        self._last_kivy_tick = clock.now()

        # use our idle callback (defined below)
        kivy.base.EventLoop.set_idle_callback(self._idle_callback)

        # get start of event loop
        EventLoop.bind(on_start=self._on_start)

        return self.wid
Exemplo n.º 5
0
    def build(self):
        # set fullscreen and resolution
        if self.exp._fullscreen is not None:
            Window.fullscreen = self.exp._fullscreen
        if self.exp._resolution is not None:
            Window.system_size = self.exp._resolution

        # handle setting the bg color
        self.set_background_color()

        # base layout uses positional placement
        self.wid = FloatLayout()
        Window._system_keyboard.bind(on_key_down=self._on_key_down,
                                     on_key_up=self._on_key_up)
        Window.bind(on_motion=self._on_motion,
                    mouse_pos=self._on_mouse_pos,
                    on_resize=self._on_resize)
        self.current_touch = None

        # set starting times
        self._post_dispatch_time = clock.now()

        # use our idle callback (defined below)
        kivy.base.EventLoop.set_idle_callback(self._idle_callback)

        # get start of event loop
        EventLoop.bind(on_start=self._on_start)

        # set width and height
        self.exp._screen._set_width(Window.width)
        self.exp._screen._set_height(Window.height)
        scale._calc_scale_factor(Window.width, Window.height)

        self.exp._sysinfo.update({"screen_size":[Window.width, Window.height],})
        self.exp._write_sysinfo()

        return self.wid
Exemplo n.º 6
0
def install_twisted_reactor(**kwargs):
    '''Installs a threaded twisted reactor, which will schedule one
    reactor iteration before the next frame only when twisted needs
    to do some work.

    Any arguments or keyword arguments passed to this function will be
    passed on the the threadedselect reactors interleave function. These
    are the arguments one would usually pass to twisted's reactor.startRunning.

    Unlike the default twisted reactor, the installed reactor will not handle
    any signals unless you set the 'installSignalHandlers' keyword argument
    to 1 explicitly. This is done to allow kivy to handle the signals as
    usual unless you specifically want the twisted reactor to handle the
    signals (e.g. SIGINT).

    .. note::
        Twisted is not included in iOS build by default. To use it on iOS,
        put the twisted distribution (and zope.interface dependency) in your
        application directory.
    '''
    import twisted

    # prevent installing more than once
    if hasattr(twisted, '_kivy_twisted_reactor_installed'):
        return
    twisted._kivy_twisted_reactor_installed = True

    # don't let twisted handle signals, unless specifically requested
    kwargs.setdefault('installSignalHandlers', 0)

    # install threaded-select reactor, to use with own event loop
    from twisted.internet import _threadedselect
    _threadedselect.install()

    # now we can import twisted reactor as usual
    from twisted.internet import reactor
    from twisted.internet.error import ReactorNotRunning

    from collections import deque
    from kivy.base import EventLoop
    from kivy.logger import Logger
    from kivy.clock import Clock

    # will hold callbacks to twisted callbacks
    q = deque()

    # twisted will call the wake function when it needs to do work
    def reactor_wake(twisted_loop_next):
        '''Wakeup the twisted reactor to start processing the task queue
        '''

        Logger.trace("Support: twisted wakeup call to schedule task")
        q.append(twisted_loop_next)

    # called every frame, to process the reactors work in main thread
    def reactor_work(*args):
        '''Process the twisted reactor task queue
        '''
        Logger.trace("Support: processing twisted task queue")
        while len(q):
            q.popleft()()
    global _twisted_reactor_work
    _twisted_reactor_work = reactor_work

    # start the reactor, by telling twisted how to wake, and process
    def reactor_start(*args):
        '''Start the twisted reactor main loop
        '''
        Logger.info("Support: Starting twisted reactor")
        reactor.interleave(reactor_wake, **kwargs)
        Clock.schedule_interval(reactor_work, 0)

    # make sure twisted reactor is shutdown if eventloop exists
    def reactor_stop(*args):
        '''Shutdown the twisted reactor main loop
        '''
        if reactor.threadpool:
            Logger.info("Support: Stooping twisted threads")
            reactor.threadpool.stop()
        Logger.info("Support: Shutting down twisted reactor")
        reactor._mainLoopShutdown()
        try:
            reactor.stop()
        except ReactorNotRunning:
            pass

        import sys
        sys.modules.pop('twisted.internet.reactor', None)

    global _twisted_reactor_stopper
    _twisted_reactor_stopper = reactor_stop

    # start and stop the reactor along with kivy EventLoop
    Clock.schedule_once(reactor_start, 0)
    EventLoop.bind(on_stop=reactor_stop)
Exemplo n.º 7
0
def install_twisted_reactor(**kwargs):
    '''Installs a threaded twisted reactor, which will schedule one
    reactor iteration before the next frame only when twisted needs
    to do some work.

    Any arguments or keyword arguments passed to this function will be
    passed on the the threadedselect reactors interleave function. These
    are the arguments one would usually pass to twisted's reactor.startRunning.

    Unlike the default twisted reactor, the installed reactor will not handle
    any signals unless you set the 'installSignalHandlers' keyword argument
    to 1 explicitly. This is done to allow kivy to handle the signals as
    usual unless you specifically want the twisted reactor to handle the
    signals (e.g. SIGINT).

    .. note::
        Twisted is not included in iOS build by default. To use it on iOS,
        put the twisted distribution (and zope.interface dependency) in your
        application directory.
    '''
    import twisted

    # prevent installing more than once
    if hasattr(twisted, '_kivy_twisted_reactor_installed'):
        return
    twisted._kivy_twisted_reactor_installed = True

    # don't let twisted handle signals, unless specifically requested
    kwargs.setdefault('installSignalHandlers', 0)

    # install threaded-select reactor, to use with own event loop
    from twisted.internet import _threadedselect
    _threadedselect.install()

    # now we can import twisted reactor as usual
    from twisted.internet import reactor
    from twisted.internet.error import ReactorNotRunning

    from collections import deque
    from kivy.base import EventLoop
    from kivy.logger import Logger
    from kivy.clock import Clock

    # will hold callbacks to twisted callbacks
    q = deque()

    # twisted will call the wake function when it needs to do work
    def reactor_wake(twisted_loop_next):
        '''Wakeup the twisted reactor to start processing the task queue
        '''

        Logger.trace("Support: twisted wakeup call to schedule task")
        q.append(twisted_loop_next)

    # called every frame, to process the reactors work in main thread
    def reactor_work(*args):
        '''Process the twisted reactor task queue
        '''
        Logger.trace("Support: processing twisted task queue")
        while len(q):
            q.popleft()()

    global _twisted_reactor_work
    _twisted_reactor_work = reactor_work

    # start the reactor, by telling twisted how to wake, and process
    def reactor_start(*args):
        '''Start the twisted reactor main loop
        '''
        Logger.info("Support: Starting twisted reactor")
        reactor.interleave(reactor_wake, **kwargs)
        Clock.schedule_interval(reactor_work, 0)

    # make sure twisted reactor is shutdown if eventloop exists
    def reactor_stop(*args):
        '''Shutdown the twisted reactor main loop
        '''
        if reactor.threadpool:
            Logger.info("Support: Stooping twisted threads")
            reactor.threadpool.stop()
        Logger.info("Support: Shutting down twisted reactor")
        reactor._mainLoopShutdown()
        try:
            reactor.stop()
        except ReactorNotRunning:
            pass

        import sys
        sys.modules.pop('twisted.internet.reactor', None)

    global _twisted_reactor_stopper
    _twisted_reactor_stopper = reactor_stop

    # start and stop the reactor along with kivy EventLoop
    Clock.schedule_once(reactor_start, 0)
    EventLoop.bind(on_stop=reactor_stop)
Exemplo n.º 8
0
def install_twisted_reactor(**kwargs):
    '''Installs a threaded twisted reactor, which will schedule one
    reactor iteration before the next frame only when twisted needs
    to do some work.

    any arguments or keyword arguments passed to this function will be
    passed on the the threadedselect reactors interleave function, these
    are the arguments one would usually pass to twisted's reactor.startRunning

    Unlike the default twisted reactor, the installed reactor will not handle
    any signals unnless you set the 'installSignalHandlers' keyword argument
    to 1 explicitly.  This is done to allow kivy to handle teh signals as
    usual, unless you specifically want the twisted reactor to handle the
    signals (e.g. SIGINT).'''
    import twisted

    # prevent installing more than once
    if hasattr(twisted, '_kivy_twisted_reactor_installed'):
        return
    twisted._kivy_twisted_reactor_installed = True

    # dont let twisted handle signals, unless specifically requested
    kwargs.setdefault('installSignalHandlers', 0)

    # install threaded-select reactor, to use with own event loop
    from twisted.internet import _threadedselect
    _threadedselect.install()

    # now we can import twisted reactor as usual
    from twisted.internet import reactor
    from collections import deque
    from kivy.base import EventLoop
    from kivy.logger import Logger
    from kivy.clock import Clock

    # will hold callbacks to twisted callbacks
    q = deque()

    # twisted will call the wake function when it needsto do work
    def reactor_wake(twisted_loop_next):
        Logger.trace("Support: twisted wakeup call to schedule task")
        q.append(twisted_loop_next)

    # called every frame, to process the reactors work in main thread
    def reactor_work(*args):
        Logger.trace("Support: processing twisted task queue")
        while len(q):
            q.popleft()()

    # start the reactor, by telling twisted how to wake, and process
    def reactor_start(*args):
        Logger.info("Support: Starting twisted reactor")
        reactor.interleave(reactor_wake, **kwargs)
        Clock.schedule_interval(reactor_work, 0)

    # make sure twisted reactor is shutdown if eventloop exists
    def reactor_stop(*args):
        '''will shutdown the twisted reactor main loop
        '''
        if reactor.threadpool:
            Logger.info("Support: Stooping twisted threads")
            reactor.threadpool.stop()
        Logger.info("Support: Shutting down twisted reactor")
        reactor._mainLoopShutdown()

    # start and stop teh reactor along with kivy EventLoop
    EventLoop.bind(on_start=reactor_start)
    EventLoop.bind(on_stop=reactor_stop)
Exemplo n.º 9
0
def install_twisted_reactor(**kwargs):
    '''Installs a threaded twisted reactor, which will schedule one
    reactor iteration before the next frame only when twisted needs
    to do some work.

    any arguments or keyword arguments passed to this function will be
    passed on the the threadedselect reactors interleave function, these
    are the arguments one would usually pass to twisted's reactor.startRunning

    Unlike the default twisted reactor, the installed reactor will not handle
    any signals unnless you set the 'installSignalHandlers' keyword argument
    to 1 explicitly.  This is done to allow kivy to handle teh signals as
    usual, unless you specifically want the twisted reactor to handle the
    signals (e.g. SIGINT).'''
    import twisted

    # prevent installing more than once
    if hasattr(twisted, '_kivy_twisted_reactor_installed'):
        return
    twisted._kivy_twisted_reactor_installed = True

    # dont let twisted handle signals, unless specifically requested
    kwargs.setdefault('installSignalHandlers', 0)

    # install threaded-select reactor, to use with own event loop
    from twisted.internet import _threadedselect
    _threadedselect.install()

    # now we can import twisted reactor as usual
    from twisted.internet import reactor
    from collections import deque
    from kivy.base import EventLoop
    from kivy.logger import Logger
    from kivy.clock import Clock

    # will hold callbacks to twisted callbacks
    q = deque()

    # twisted will call the wake function when it needsto do work
    def reactor_wake(twisted_loop_next):
        Logger.trace("Support: twisted wakeup call to schedule task")
        q.append(twisted_loop_next)

    # called every frame, to process the reactors work in main thread
    def reactor_work(*args):
        Logger.trace("Support: processing twisted task queue")
        while len(q):
            q.popleft()()

    # start the reactor, by telling twisted how to wake, and process
    def reactor_start(*args):
        Logger.info("Support: Starting twisted reactor")
        reactor.interleave(reactor_wake, **kwargs)
        Clock.schedule_interval(reactor_work, 0)

    # make sure twisted reactor is shutdown if eventloop exists
    def reactor_stop(*args):
        '''will shutdown the twisted reactor main loop
        '''
        if reactor.threadpool:
            Logger.info("Support: Stooping twisted threads")
            reactor.threadpool.stop()
        Logger.info("Support: Shutting down twisted reactor")
        reactor._mainLoopShutdown()

    # start and stop teh reactor along with kivy EventLoop
    EventLoop.bind(on_start=reactor_start)
    EventLoop.bind(on_stop=reactor_stop)