Esempio n. 1
0
def init():
    """Initialize input and output objects"""

    global config, config_path

    # Load config
    for config_path in config_paths:
        #Only try to load the config file if it's present
        #(unclutters the logs)
        if os.path.exists(config_path):
            try:
                logging.debug('Loading config from {}'.format(config_path))
                config = read_config(config_path)
            except:
                logging.exception(
                    'Failed to load config from {}'.format(config_path))
            else:
                logging.info(
                    'Successfully loaded config from {}'.format(config_path))
                break
    # After this loop, the config_path global should contain
    # path for config that successfully loaded

    if config is None:
        sys.exit('Failed to load any config files!')

    # Initialize output
    try:
        output.init(config['output'])
        o = output.screen
    except:
        logging.exception('Failed to initialize the output object')
        logging.exception(traceback.format_exc())
        sys.exit(2)

    # Initialize input
    try:
        # Now we can show errors on the display
        input.init(config['input'])
        i = input.listener
    except:
        logging.exception('Failed to initialize the input object')
        logging.exception(traceback.format_exc())
        Printer(['Oops. :(', 'y u make mistake'], None, o, 0)
        sys.exit(3)

    if hasattr(o, "set_backlight_callback"):
        o.set_backlight_callback(i)

    return i, o
Esempio n. 2
0
def init():
    """Initialize input and output objects"""

    global input_processor, screen, cm, config, config_path
    config = None

    # Load config
    for config_path in config_paths:
        #Only try to load the config file if it's present
        #(unclutters the logs)
        if os.path.exists(config_path):
            try:
                logging.debug('Loading config from {}'.format(config_path))
                config = read_config(config_path)
            except:
                logging.exception(
                    'Failed to load config from {}'.format(config_path))
            else:
                logging.info(
                    'Successfully loaded config from {}'.format(config_path))
                break
    # After this loop, the config_path global should contain
    # path for config that successfully loaded

    if config is None:
        sys.exit('Failed to load any config files!')

    # Initialize output
    try:
        screen = output.init(config['output'])
    except:
        logging.exception('Failed to initialize the output object')
        logging.exception(traceback.format_exc())
        sys.exit(2)

    # Initialize the context manager
    cm = ContextManager()

    # Initialize input
    try:
        # Now we can show errors on the display
        input_processor = input.init(config["input"], cm)
    except:
        logging.exception('Failed to initialize the input object')
        logging.exception(traceback.format_exc())
        Printer(['Oops. :(', 'y u make mistake'], None, screen, 0)
        sys.exit(3)

    # Tying objects together
    if hasattr(screen, "set_backlight_callback"):
        screen.set_backlight_callback(input_processor)
    cm.init_io(input_processor, screen)
    cm.switch_to_context("main")
    i, o = cm.get_io_for_context("main")

    return i, o
Esempio n. 3
0
def init():
    """Initialize input and output objects"""

    config = None

    # Load config
    for path in config_paths:
        try:
            logging.debug('Loading config from {}'.format(path))
            config = read_config(path)
        except:
            logging.exception('Failed to load config from {}'.format(path))
        else:
            logging.info('Successfully loaded config from {}'.format(path))
            break

    if config is None:
        sys.exit('Failed to load any config file')

    # Initialize output
    try:
        output.init(config['output'])
        o = output.screen
    except:
        logging.exception('Failed to initialize the output object')
        logging.exception(traceback.format_exc())
        sys.exit(2)

    # Initialize input
    try:
        # Now we can show errors on the display
        input.init(config['input'])
        i = input.listener
    except:
        logging.exception('Failed to initialize the input object')
        logging.exception(traceback.format_exc())
        Printer(['Oops. :(', 'y u make mistake'], None, o, 0)
        sys.exit(3)

    return i, o
Esempio n. 4
0
def init():
    """Initialize input and output objects"""

    global input_processor, input_device_manager, screen, cm, config, config_path
    config, config_path = load_config()

    if config is None:
        sys.exit('Failed to load any config files!')

    # Initialize output
    try:
        screen = output.init(config['output'])
    except:
        logging.exception('Failed to initialize the output object')
        logging.exception(traceback.format_exc())
        sys.exit(2)

    # Initialize the context manager
    cm = ContextManager()
    # Initialize input
    try:
        # Now we can show errors on the display
        input_processor, input_device_manager = input.init(config["input"], cm)
    except:
        logging.exception('Failed to initialize the input object')
        logging.exception(traceback.format_exc())
        Printer(['Oops. :(', 'y u make mistake'], None, screen, 0)
        sys.exit(3)

    # Tying objects together
    if hasattr(screen, "set_backlight_callback"):
        screen.set_backlight_callback(input_processor)
    cm.init_io(input_processor, screen)
    c = cm.contexts["main"]
    c.register_action(ContextSwitchAction("switch_main_menu", None, menu_name="Main menu"))
    cm.switch_to_context("main")
    i, o = cm.get_io_for_context("main")

    return i, o
Esempio n. 5
0
#Here, things are about i and o, which are input and output
#And we output things for debugging, so o goes first.
from output import output

#These lines are here so that welcome message stays on the screen a little longer:
output.init()
o = output.screen
from ui import Printer
Printer(["Welcome to", "pyLCI"], None, o, 0)

try:
    #All the LCI-related modules are imported here
    from input import input
    from ui import Menu
    #Now we init the input subsystem.
    input.init()
    i = input.listener
except:
    Printer(["Oops. :(", "y u make mistake"], None, o, 0) #Yeah, that's about all the debug data. 
    #import time;time.sleep(3) #u make mi sad i go to slip
    #o.clear()
    raise

#Here go all native Python modules. It's close to impossible to screw that up.
from subprocess import call
from time import sleep
import importlib
import argparse

#Now we go and import all the apps.
app_directory = "apps"
Esempio n. 6
0
            sys.exit(1)
    else:
        if os.path.exists(config_error_file): os.remove(config_error_file)
        error_file.close()
else:
    config = read_config(backup_config_path)

output.init(config["output"])
o = output.screen
from ui import Printer, Menu

try:  #If there's an internal error, we show it on display and exit
    from apps.manager import AppManager
    #Now we init the input subsystem
    from input import input
    input.init(config["input"])
    i = input.listener
    if hasattr(o, "set_backlight_callback"):
        o.set_backlight_callback(i)
except:
    Printer(["Oops. :(", "y u make mistake"], None, o,
            0)  #Yeah, that's about all the debug data.
    raise


def splash_screen():
    try:
        from splash import splash
        splash(i, o)
    except ImportError:
        pass