Variables are values with a type, a default, and possibly a restricted
range. They also can carry documentation and know how to convert a literal
into a valid variable value.
This code incorporates ideas taken from Graphite, which was originally written
by Joseph and Michelle Strout in 1999.
accepted values for a Boolean value are 0,1 (integers),
"true","false","yes","no" (all case-insensitive) and "0","1".
All valid input is converted to False or True.
relies on operator.isMappingType to determine the validity
of a candidate value.
KEYTYPE and VALUETYPE may be set to types that will then
ensure the keys and values of this mapping will conform to
them.
an enumeration variable contains any of a finite set of
constants. values is either a list of allowed values or
a dictionary mapping allowed values to documentation strings
describing the meaning of each of the values.
Note that, by default, acceptable values defined in
base classes of an EnumVariable are added to the list of
acceptable values (via the .extend method).
note that this class subsumes the two Python types int and
long (i.e., if a value/literal is too big for a plain
int, it is automatically converted to a long).
MINQTY and MAXQTY determine the minimum and maximum length
of the sequence. With ELEMTYPE, a variable class can be
provided which then requires the sequence elements to conform
to this variable.
relies on operator.isMappingType to determine the validity
of a candidate value.
KEYTYPE and VALUETYPE may be set to types that will then
ensure the keys and values of this mapping will conform to
them.
a position has two or three coordinates. Each coordinate
(x,y,z) can have range restrictions imposed on it
(options MINX,`MAXX`,`MINY`,`MAXY`,`MINZ`,`MAXZ`).
Note that the position data are kept in a Numeric Array to
allow simple arithmetics on the variable value.
specifies a rectangle with a x,y-position and width/height
Detail:
a rectangle has a position (x- and y-coordinates of the upper
left corner) and a width and a height. Minimum/maximum
width/heihgt values can be set with the options MINWIDTH,
MAXWIDTH, MINHEIGHT, MAXHEIGHT. The position is defined
relative to the rectangle spanned by the maximum width/height
values. Valid values for this variable are either a 2-sequence
of integers
(<width>,<height>)
with the position tacitly set to (0,0), or a 4-sequence of
integers
(<left pos. x>,<top pos. y>,<width>,<height>)
Note that the sum of the x-coordinate/y-coordinate of the
position and the current width/height cannot exceed the maximum
width/height.
MINQTY and MAXQTY determine the minimum and maximum length
of the sequence. With ELEMTYPE, a variable class can be
provided which then requires the sequence elements to conform
to this variable.
checks whether value is acceptable as value for this variable.
Returns two values: first is 0/1 unacceptable/acceptable, second is
the value modified as needed to fit the value type or an error string
explaining the problem.
a static method that tries to convert value (any input value) to
the value type of the class. Raises a ValueError if the conversion
fails. If allowNA is True, None is treated as an allowed value.
checks whether literal is a valid literal representation of this
variable class. Returns INVALID (invalid literal), VALID (valid
literal), or PARTIAL (may be completed into a valid literal).
checks if value (which is of the expected value type) conforms to
whatever options are set for this variable instance. Returns a 2-tuple
(a boolean indicating success and a [possibly converted] value on
success or an error message on failure).