Beispiel #1
0
def menu(defaults):
    """
    Provides the top level user interface.
    Prompts for what to do and then calls the appropriate
    function or method.
    Creating a new entity or choosing an existing one, if successful,
    begins the accounting process with that entity.
    """
    entities = E.Entities(*E.get_file_info(defaults),
                            defaults=defaults)
#   print("'entities' is of type '{}'.".format(type(entities)))
#   print("Initializing 'entities' with the following values:")
#   print("\t", entities.lst)
#   print("\t", entities.default)
    while True:
        listing = entities.show_entities(indent=8)
        if listing:
            listing = (
"""\n    (Currently existing entities are:\n{}          )"""
                    .format(listing))
        else: listing = "\n    (No entities currently exist.)"
#       print("listing is '{}'.".format(listing))
        option = input("""
Main Menu:
    [Working dir: {}]{}
    1. Create a new entity.
    2. Choose an existing entity.
    3. Delete an entity.
    9. Change arguments.
    0. Exit
Choice: """.format(defaults['home'], listing))
        print("You've chosen: '{}'.".format(option))
        if option in ('', '_', '0'):
            break
        try:
            option = int(option)
        except ValueError:
            print(
                "Invalid main menu choice: {} (must be an integer.)"
                        .format(option))
            continue
        if option == 1:
            entity = create_new(entities)
        elif option == 2:
            entity = choose_existing(defaults, entities)
        elif option == 3:
            delete_option(defaults, entities)
            entity = ''
        elif option == 9:
            change_args_option(defaults)
        else:
            print("BAD CHOICE '{}'- try again....".format(option))
            entity = None
        if entity:
            defaults["entity"] = entity
            work_with(defaults)
Beispiel #2
0
def choose_existing(defaults, entities):
    """
    A main menu response function.
    A wrapper for choose_entity().
    """
    print("Picked 'Choose an existing entity.'")
    chosen_entity = choose_entity(entities, 4)
    if chosen_entity:
        defaults['entity'] = chosen_entity
        work_with(defaults)