Option Objects: Specific Types

Boolean

The simplest of option types, a Boolean option is either true or false. It has no additional calling parameters, and all values are valid. Its from_str method converts the strings true, yes, y, t, or 1 to a true value, and anything else to a false value.

String

An arbitrary string. It has one additional creation parameter, match, which specifies a regular expression which is used as a validation condition. (The regular expression should be a string in the format used by the Python standard re module.)

Integer

An integer. It has two additional creation parameters, min and max, which specify a range of valid values. Either or both may be None, which means that end of the range is open.

Float

A floating point number. It has two additional creation parameters, min and max, which specify a range of valid values. Either or both may be None, which means that end of the range is open.

Choice

A single choice from a list of valid choices. A Choice option is intended to be essentially generic, but with a menu of possible values which can be presented to the user in a configuration dialog. The Choice object has two additional creation parameters: items is the list of choices, and values is an optional list of values corresponding to each choice.

The items list should contain the actual strings to be displayed to the user; if these are not the desired values of the option, the values list will translate. For example, if items is set to ['One','Two','Three'] and values is set to [1, 2, 3], then the option will take on a value of the integer 2 whenever the user selects Two from a menu, or specifies the value Two in a configuration file.

Choice objects don't do any validation at present, because they might be used for "incomplete" menus (where the listed choices are a subset of those actually available). It is likely that other variations on Choice will be added in the future, with different semantics.

Filename

A filename. This option type is basically a String, but customized to deal with filenames. It has two additional creation parameters, initialdir and filetypes, which will be used if the option is set using a GUI file selection dialog. Since it is a subclass of String, you may also pass a match keyword parameter, to validate option values against a regular expression.