Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

SelectParam

Param restricted to a fixed set of choices, rendered as a select / dropdown in the interface.

This replaces the deprecated options argument of :class:StrParam, :class:IntParam and :class:FloatParam.

The options argument accepts three forms:

  • an :class:~enum.Enum class: one option per member, the member name is the displayed label and the member value is stored / returned.

  • a list mixing the two following forms:

    • a raw value ("a", 1, 2.5, ...): the value is both the stored value and the displayed label.
    • a {"label": ..., "value": ...} dict (a :class:SelectParamOption): the interface shows label but value is stored / returned.

When multiple is True, several choices can be selected and the param value is a list of the selected values. In that case, if no default_value is provided, the param defaults to an empty list [] (and is therefore optional).

Attributes
PRIVATE_VISIBILITY: LiteralPROTECTED_VISIBILITY: LiteralPUBLIC_VISIBILITY: Literaladditional_info: dict | Nonedefault_value: Optionalhuman_name: str | Noneinvalid_reason: str | Noneis_valid: booloptional: boolshort_description: str | Nonevisibility: Literal
Functions
__init__
options : type[enum.Enum] | list[typing.Union[typing.Any, gws_core.config.param.select_param.SelectParamOption]] | tuple[typing.Union[typing.Any, gws_core.config.param.select_param.SelectParamOption], ...] | None
The available choices. Either an Enum class (one option per member) or a list / tuple of raw values / ``{"label": ..., "value": ...}`` dicts.
multiple : bool - False
If True, several choices can be selected and the value is a list. Defaults to False.
default_value : Optional
Default value, if None, and optional is false, the config is mandatory. When multiple is True and no default is provided, it defaults to an empty list. An Enum member may be passed, its value is then used. When multiple is True, a list / tuple of Enum members may be passed, each member's value is then used.
optional : bool - False
See default value
visibility : Literal - public
Visibility of the param, see doc on type ParamSpecVisibilty for more info
human_name : str | None
Human readable name of the param, showed in the interface
short_description : str | None
Description of the param, showed in the interface
build

Method call before the value is used (in task or view) to apply some transformation if needed by the ParamSpec. This does not affect the value in the database.

value : Any
Return type : Any
get_default_value
Return type : Any
to_dto
Return type : ParamSpecDTO
to_simple_dto
Return type : ParamSpecSimpleDTO
validate

Validate the value of the param and return the modified value if needed. This method is called when the param is set in the config before saving it in the database. The returned value must be serializable in json.

value : Any
Return type : Any
empty @classmethod
Return type : ParamSpec
get_param_spec_type @classmethod
Return type : ParamSpecType
load_from_dto @classmethod
spec_dto : ParamSpecDTO
validate : bool - False
Return type : ParamSpec
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.