Package topo :: Package base :: Module parameterclasses :: Class Number
[hide private]
[frames] | no frames]

Class Number

source code

                   object --+        
                            |        
parameterizedobject.Parameter --+    
                                |    
                          Dynamic --+
                                    |
                                   Number
Known Subclasses:
Integer, Magnitude

Number is a numeric parameter. Numbers have a default value, and bounds. There are two types of bounds: bounds and softbounds. bounds are hard bounds: the parameter must have a value within the specified range. The default bounds are (None,None), meaning there are actually no hard bounds. One or both bounds can be set by specifying a value (e.g. bounds=(None,10) means there is no lower bound, and an upper bound of 10).

Number is also a type of Dynamic parameter, so its value can be set to a callable to get a dynamically generated number (see Dynamic).

When not being dynamically generated, bounds are checked when a Number is created or set. Using a default value outside the hard bounds, or one that is not numeric, results in an exception. When being dynamically generated, bounds are checked when a the value of a Number is requested. A generated value that is not numeric, or is outside the hard bounds, results in an exception.

A separate function set_in_bounds() is provided that will silently crop the given value into the legal range, for use in, for instance, a GUI.

softbounds are present to indicate the typical range of the parameter, but are not enforced. Setting the soft bounds allows, for instance, a GUI to know what values to display on sliders for the Number.

Example of creating a Number::
AB = Number(default=0.5, bounds=(None,10), softbounds=(0,1), doc='Distance from A to B.')


Nested Classes [hide private]

Inherited from parameterizedobject.Parameter: __metaclass__

Instance Methods [hide private]
 
__init__(self, default=0.0, bounds=None, softbounds=None, **params)
Initialize this parameter object and store the bounds.
source code
 
__get__(self, obj, objtype)
Same as the superclass's __get__, but if the value was dynamically generated, check the bounds.
source code
 
__set__(self, obj, val)
Set to the given value, raising an exception if out of bounds.
source code
 
set_in_bounds(self, obj, val)
Set to the given value, but cropped to be within the legal bounds.
source code
 
crop_to_bounds(self, val)
Return the given value cropped to be within the hard bounds for this parameter.
source code
 
_check_value(self, val)
Checks that the value is numeric and that it is within the hard bounds; if not, an exception is raised.
source code
 
get_soft_bounds(self)
For each soft bound (upper and lower), if there is a defined bound (not equal to None) then it is returned, otherwise it defaults to the hard bound.
source code

Inherited from Dynamic: time_fn

Inherited from parameterizedobject.Parameter: __delete__, __getstate__, __setstate__

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
  __classdoc = '\n Number is a numeric parameter. Numbers hav...
str(object) -> string
Properties [hide private]
  _softbounds
  bounds

Inherited from parameterizedobject.Parameter: constant, default, doc, instantiate, precedence, readonly

Inherited from object: __class__

Method Details [hide private]

__init__(self, default=0.0, bounds=None, softbounds=None, **params)
(Constructor)

source code 

Initialize this parameter object and store the bounds.

Non-dynamic default values are checked against the bounds.

Overrides: Dynamic.__init__

__get__(self, obj, objtype)

source code 
Same as the superclass's __get__, but if the value was dynamically generated, check the bounds.
Overrides: Dynamic.__get__

__set__(self, obj, val)

source code 
Set to the given value, raising an exception if out of bounds.
Overrides: Dynamic.__set__

set_in_bounds(self, obj, val)

source code 
Set to the given value, but cropped to be within the legal bounds. All objects are accepted, and no exceptions will be raised. See crop_to_bounds for details on how cropping is done.

crop_to_bounds(self, val)

source code 

Return the given value cropped to be within the hard bounds for this parameter.

If a numeric value is passed in, check it is within the hard bounds. If it is larger than the high bound, return the high bound. If it's smaller, return the low bound. In either case, the returned value could be None. If a non-numeric value is passed in, set to be the default value (which could be None). In no case is an exception raised; all values are accepted.

get_soft_bounds(self)

source code 
For each soft bound (upper and lower), if there is a defined bound (not equal to None) then it is returned, otherwise it defaults to the hard bound. The hard bound could still be None.

Class Variable Details [hide private]

__classdoc

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Value:
'''
    Number is a numeric parameter. Numbers have a default value,
    and bounds.  There are two types of bounds: ``bounds`` and
    ``softbounds``.  ``bounds`` are hard bounds: the parameter must have
    a value within the specified range.  The default bounds are
    (None,None), meaning there are actually no hard bounds.  One
    or both bounds can be set by specifying a value
    (e.g. bounds=(None,10) means there is no lower bound, and an
...