Exemple #1
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import display
    import sound
    import console
    import error
    import fp
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import inputs
    interface = config.get('interface') or 'graphical'
    display.init(interface)
    sound.init('none' if config.get('nosound') else interface)
    if not state.loaded:
        console.init_mode()
    # set the output for maths error messages
    fp.init(error_stream=console)
    return backend, console
Exemple #2
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import sound
    # load backend modules
    # this can't be done in backend.py as it would create circular dependency
    import console
    import error
    import fp
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import redirect
    # hack: mark modules for inclusion by pyinstaller
    # see https://groups.google.com/forum/#!topic/pyinstaller/S8QgHXiGJ_A
    if False:
        import video_none
        import video_curses
        import video_ansi
        import video_cli
        import video_pygame
        import audio_none
        import audio_beep
        import audio_pygame
    backends = {
        'none': ('video_none', 'audio_none'),
        'cli': ('video_cli', 'audio_beep'),
        'text': ('video_curses', 'audio_beep'),
        'ansi': ('video_ansi', 'audio_beep'),
        'graphical': ('video_pygame', 'audio_pygame'),
    }
    if not config.get('interface'):
        config.options['interface'] = 'graphical'
    # select interface
    video_name, audio_name = backends[config.get('interface')]
    # initialise video backend before console
    while True:
        try:
            # __name__ global is needed when calling from setuptools package
            video = __import__(video_name, globals={"__name__": __name__})
        except ImportError as e:
            video = None
        if not video:
            if not video_name or video_name == 'video_none':
                logging.error('Failed to initialise interface.')
                raise error.Exit()
            logging.error('Could not load module %s.', video_name)
            video_name = 'video_none'
            continue
        if backend.init_video(video):
            break
        else:
            video_name = video.fallback
            if video:
                video.close()
            if video_name:
                logging.info('Falling back to %s interface.', video_name)
    if config.get('nosound'):
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
    else:
        sound.audio = __import__(audio_name, globals={"__name__": __name__})
    if not sound.init():
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
        sound.init()
        logging.warning(
            'Failed to initialise sound. Sound will be disabled.\r')
    if not state.loaded:
        console.init_mode()
    # set the output for maths error messages
    fp.init(error_stream=console)
    return backend, console
Exemple #3
0
def prepare_console():
    """ Initialise backend and console. """
    import state
    import backend
    import sound
    # load backend modules
    # this can't be done in backend.py as it would create circular dependency
    import console
    import error
    import fp
    # we need this prepared for input to work,
    # even if we don't use any function from it
    import redirect
    # hack: mark modules for inclusion by pyinstaller
    # see https://groups.google.com/forum/#!topic/pyinstaller/S8QgHXiGJ_A
    if False:
        import video_none
        import video_curses
        import video_ansi
        import video_cli
        import video_pygame
        import audio_none
        import audio_beep
        import audio_pygame
    backends = {
        'none': ('video_none', 'audio_none'),
        'cli': ('video_cli', 'audio_beep'),
        'text': ('video_curses', 'audio_beep'),
        'ansi': ('video_ansi', 'audio_beep'),
        'graphical': ('video_pygame', 'audio_pygame'),
        }
    if not config.get('interface'):
        config.options['interface'] = 'graphical'
    # select interface
    video_name, audio_name = backends[config.get('interface')]
    # initialise video backend before console
    while True:
        try:
            # __name__ global is needed when calling from setuptools package
            video = __import__(video_name, globals={"__name__": __name__})
        except ImportError as e:
            video = None
        if not video:
            if not video_name or video_name == 'video_none':
                logging.error('Failed to initialise interface.')
                raise error.Exit()
            logging.error('Could not load module %s.', video_name)
            video_name = 'video_none'
            continue
        if backend.init_video(video):
            break
        else:
            video_name = video.fallback
            if video:
                video.close()
            if video_name:
                logging.info('Falling back to %s interface.', video_name)
    if config.get('nosound'):
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
    else:
        sound.audio = __import__(audio_name, globals={"__name__": __name__})
    if not sound.init():
        sound.audio = __import__('audio_none', globals={"__name__": __name__})
        sound.init()
        logging.warning('Failed to initialise sound. Sound will be disabled.\r')
    if not state.loaded:
        console.init_mode()
    # set the output for maths error messages
    fp.init(error_stream=console)
    return backend, console