Example #1
0
def prompt_output(wizard, parameter, auto=True):
    """Prompts for the setting up of model output for the specified parameter.
    """
    target = _find_target(wizard, parameter)
    if not auto:
        #Give the user the option of overriding previous choices.
        if target.compareto is not None:
            msg.gen("This parameter is already being compared to model output.")
            remodel = wizard.input("Would you like to re-specify the details?")[0].lower() == 'y'
            msg.blank(1,0)
        else:
            remodel = True
    else:
        #We only care about getting new things that we haven't got already
        remodel = target.compareto is None

    if remodel:
        _prompt_model(wizard, parameter, target)
Example #2
0
def prompt_target(wizard, parameter, auto=True):
    """Prompts the user whether to save the output parameter's values to file.
    """
    target = _find_target(wizard, parameter)
    if not auto:
        #Give the user the option of overriding previous choices.
        if target is not None:
            msg.gen("This parameter is being saved already.")
            retarg = wizard.input("Would you like to re-specify the details?")[0].lower() == 'y'
            msg.blank(1,0)
        else:
            retarg = True
    else:
        #We only care about getting new things that we haven't got already
        retarg = target is None

    if retarg:
        _prompt_target(wizard, parameter, target)    
Example #3
0
def prompt_input(wizard, parameter):
    """Prompts for the location of the input for the specified parameter.
    """
    if _has_input(wizard, parameter):
        msg.gen("This parameter has input specified already.")
        reset = wizard.input("Would you like to add another? ").lower()[0] == 'y'
        if not reset:
            return
        else:
            msg.blank(1,0)

    skeys = ["Unit Test Output", "Existing File", "Known Function", "Constant"]
    sources = {
        0: _input_testsource,
        1: _input_existing,
        2: _input_function,
        3: _input_constant,
    }
    _prompt_general("Choose an input source:", skeys, sources, (wizard, parameter))
Example #4
0
def _complete_general(prompt="$ ", options=None, completer=None, leader=None,
                      regex=None, cast=None, current=None):
    """Prompts the user for input from the specified options.
    """
    import readline
    readline.parse_and_bind("tab: complete")
    if completer is not None:
        readline.set_completer(SimpleCompleter(None, completer).complete)
    elif options is not None:
        readline.set_completer(SimpleCompleter(options).complete)
    if leader is not None:
        msg.okay(leader)
    if current is not None:
        msg.gen("The current value is set as '{}'.".format(current))
        
    choice = input(prompt)
    if choice.strip() == '?':
        return choice.strip()
    if choice.strip() == '':
        return None    
    
    if regex is not None:
        import re
        if not re.match(regex, choice):
            msg.warn("'{}' is not a valid choice.".format(choice))
            return None

    if cast is not None:
        try:
            result = cast(choice.strip())
        except ValueError:
            return None
    else:
        result = choice

    return result