Skip to content

Dropdown

Dropdown type as a replacement for Choice.

They are functionally equivalent, but the Dropdown type provides a default value of a read only field when there are no options to choose from.

Dropdown = Choice | Any module-attribute

Dropdown type definition.

"... or Any" makes for a very weak type definition, admittedly. However, this is what we get when combining Choice and read_only_field.

generate_dropdown(label, options)

Generate a dropdown menu using the choice class.

If there are no options, this method instead returns a read only field that tells the user that there are no options available.

Source code in gso/utils/types/dropdown.py
def generate_dropdown(label: str, options: dict[str, tuple]) -> Dropdown:
    """Generate a dropdown menu using the choice class.

    If there are no options, this method instead returns a read only field that tells the user that there are no
    options available.
    """
    if options:
        return Choice.__call__(label, options)
    return read_only_field(f"{label} - No options available.")