Ejemplo n.º 1
0
def test_find_correct_backend_classes():
    D = get_backend_classes('testing')
    assert D == {
        'input': testing_be.EmptyInput,
        'mainloop': testing_be.MainLoop,
        'screen': testing_be.EmptyCanvas,
    }
Ejemplo n.º 2
0
def test_find_correct_backend_classes():
    D = get_backend_classes('testing')
    assert D == {
        'input': testing_be.EmptyInput,
        'mainloop': testing_be.MainLoop,
        'screen': testing_be.EmptyCanvas,
    }
Ejemplo n.º 3
0
    def set_backend(self, backend=None):
        """
        Define backend used by FGAme.

        If called with no arguments, try to load backends in the default order.
        If argument is a list, try to load backends in the specified order.
        This method return a string with the loaded backend.
        """

        if backend is None:
            if self._backend is None:
                if 'FGAME_BACKEND' in os.environ:
                    env_be = os.environ['FGAME_BACKEND']
                    backend = env_be.split(',')
                    log.info('using backend defined by environ: %s' % env_be)
                else:
                    backend = self._backends
            else:
                return  # backend is configured!

        # Prevent changes to a configured backend
        if self._backend is not None:
            if self._backend != backend:
                raise RuntimeError(
                    'already initialized to %s, cannot change the backend' %
                    self._backend
                )
            else:
                return

        # Load backend by name
        if isinstance(backend, str):
            if not fgame_backends.supports_backend(backend):
                raise ValueError(
                    '%s backend is not supported in your system' %
                    backend)

            self._backend = backend
            self._backend_classes = fgame_backends.get_backend_classes(backend)
            log.info('conf: Backend set to %s' % backend)

        # Load backend from list
        else:
            for be in backend:
                if fgame_backends.supports_backend(be):
                    self.set_backend(be)
                    break
            else:
                msg = 'none of the requested backends are available.'
                if 'pygame' in backend:
                    msg += (
                        '\nSupported backends are:'
                        '\n    * pygame'
                        '\n    * sdl2'
                        # '\n    * kivy'
                    )
                raise RuntimeError(msg)
        return self._backend
Ejemplo n.º 4
0
def test_find_pygame_backend():
    from FGAme.backends import pygame_be

    D = get_backend_classes('pygame')
    assert D == {
        'input': pygame_be.PyGameInput,
        'mainloop': pygame_be.PyGameMainLoop,
        'screen': pygame_be.PyGameCanvas,
    }
Ejemplo n.º 5
0
def test_find_pygame_backend():
    from FGAme.backends import pygame_be

    D = get_backend_classes('pygame')
    assert D == {
        'input': pygame_be.PyGameInput,
        'mainloop': pygame_be.PyGameMainLoop,
        'screen': pygame_be.PyGameCanvas,
    }
Ejemplo n.º 6
0
    def set_backend(self, backend=None):
        """
        Define backend used by FGAme.

        If called with no arguments, try to load backends in the default order.
        If argument is a list, try to load backends in the specified order.
        This method return a string with the loaded backend.
        """

        if backend is None:
            if self._backend is None:
                if 'FGAME_BACKEND' in os.environ:
                    env_be = os.environ['FGAME_BACKEND']
                    backend = env_be.split(',')
                    log.info('using backend defined by environ: %s' % env_be)
                else:
                    backend = self._backends
            else:
                return  # backend is configured!

        # Prevent changes to a configured backend
        if self._backend is not None:
            if self._backend != backend:
                raise RuntimeError(
                    'already initialized to %s, cannot change the backend' %
                    self._backend)
            else:
                return

        # Load backend by name
        if isinstance(backend, str):
            if not fgame_backends.supports_backend(backend):
                raise ValueError('%s backend is not supported in your system' %
                                 backend)

            self._backend = backend
            self._backend_classes = fgame_backends.get_backend_classes(backend)
            log.info('conf: Backend set to %s' % backend)

        # Load backend from list
        else:
            for be in backend:
                if fgame_backends.supports_backend(be):
                    self.set_backend(be)
                    break
            else:
                msg = 'none of the requested backends are available.'
                if 'pygame' in backend:
                    msg += (
                        '\nSupported backends are:'
                        '\n    * pygame'
                        '\n    * sdl2'
                        # '\n    * kivy'
                    )
                raise RuntimeError(msg)
        return self._backend
Ejemplo n.º 7
0
def set_backend(backend=None):
    '''Define o backend a ser utilizado pela FGAme.

    Se for chamada sem nenhum argumento, tenta carregar os backends na
    ordem padrão. Se o argumento for uma lista, tenta carregar os backends na
    ordem especificada pela lista. Retorna uma string descrevendo o backend
    carregado.'''

    global _backend, _backend_classes

    # Função chamada sem argumentos
    if backend is None:
        if _backend is None:
            backend = _backends
        else:
            return  # backend já configurado!

    # Previne modificar o backend
    if _backend is not None:
        if _backend != backend:
            raise RuntimeError(
                'already initialized to %s, cannot change the backend' %
                _backend)
        else:
            return

    # Carrega backend pelo nome
    if isinstance(backend, str):
        if not _backend_module.supports_backend(backend):
            raise ValueError(
                '%s backend is not supported in your system' %
                backend)

        _backend = backend
        _backend_classes = _backend_module.get_backend_classes(backend)
        _log.info('conf: Backend set to %s' % backend)

    # Carrega backend a partir de uma lista
    else:
        for be in backend:
            if _backend_module.supports_backend(be):
                set_backend(be)
                break
        else:
            msg = 'none of the requested backends are available.'
            if 'pygame' in backend:
                msg += (
                    '\nSupported backends are:'
                    '\n    * pygame'
                    '\n    * sdl2'
                    # '\n    * kivy'
                )
            raise RuntimeError(msg)
    return _backend
Ejemplo n.º 8
0
    def set_backend(self, backend=None):
        '''Define o backend a ser utilizado pela FGAme.

        Se for chamada sem nenhum argumento, tenta carregar os backends na
        ordem dada por self.backends. Se o argumento for uma lista, tenta
        carregar os backends na ordem especificada pela lista.'''

        # Função chamada sem argumentos
        if backend is None:
            if self._backend is None:
                backend = self._backends
            else:
                return  # backend já configurado!

        # Previne modificar o backend
        if self._backend is not None:
            if self._backend != backend:
                raise RuntimeError(
                    'already initialized to %s, cannot change the backend' %
                    self._backend)
            else:
                return

        # Carrega backend pelo nome
        if isinstance(backend, str):
            if not backends.supports_backend(backend):
                raise ValueError('%s backend is not supported in your system' %
                                 backend)

            self._backend = backend
            self._backend_classes = backends.get_backend_classes(backend)
            log.info('conf: Backend set to %s' % backend)

        # Carrega backend a partir de uma lista
        else:
            for be in backend:
                if backends.supports_backend(be):
                    self.set_backend(be)
                    break
            else:
                msg = 'none of the requested backends are available.'
                if 'pygame' in backend:
                    msg += (
                        '\nSupported backends are:'
                        '\n    * pygame'
                        '\n    * sdl2'
                        # '\n    * kivy'
                    )
                raise RuntimeError(msg)