Skip to content

geosoft.project.get_user_input with kind='list' should constrain result #146

@TheZappie

Description

@TheZappie

Currently the dialog given by geosoft.project.get_user_input with kind='list' allows the user the enter any string, and does not raise an error. Other dropdown entries in Oasis Montaj tools do not have this behavior, they constrain the input to a choice.
A workaround is to check the result directly after the dialog, like this:

def get_from_dropdown(prompt: str, items: Iterable, title="Input required...", default=''):
    """Ensures that the user input is a member from given items"""
    items = list(items)
    while True:
        result = gxproj.get_user_input(
            title=title,
            prompt=prompt,
            default=default,
            kind='list',
            items=items)
        if result in set(items):
            break
    return result

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions