Package topo :: Package param :: Class Boolean
[hide private]
[frames] | no frames]

Class Boolean

source code

             object --+    
                      |    
parameterized.Parameter --+
                          |
                         Boolean


An attribute descriptor for declaring parameters.

Parameters are a special kind of class attribute.  Setting a
Parameterized class attribute to be a Parameter instance causes
that attribute of the class (and the class's instances) to be
treated as a Parameter.  This allows special behavior, including
dynamically generated parameter values, documentation strings,
constant and read-only parameters, and type or range checking at
assignment time.

For example, suppose someone wants to define two new kinds of
objects Foo and Bar, such that Bar has a parameter delta, Foo is a
subclass of Bar, and Foo has parameters alpha, sigma, and gamma
(and delta inherited from Bar).  She would begin her class
definitions with something like this:

class Bar(Parameterized):
    delta = Parameter(default=0.6, doc='The difference between steps.')
    ...
    
class Foo(Bar):
    alpha = Parameter(default=0.1, doc='The starting value.')
    sigma = Parameter(default=0.5, doc='The standard deviation.',
                      constant=True)
    gamma = Parameter(default=1.0, doc='The ending value.')
    ...

Class Foo would then have four parameters, with delta defaulting
to 0.6.

Parameters have several advantages over plain attributes:

1. Parameters can be set automatically when an instance is
   constructed: The default constructor for Foo (and Bar) will
   accept arbitrary keyword arguments, each of which can be used
   to specify the value of a Parameter of Foo (or any of Foo's
   superclasses).  E.g., if a script does this:

       myfoo = Foo(alpha=0.5)

   myfoo.alpha will return 0.5, without the Foo constructor
   needing special code to set alpha.

   If Foo implements its own constructor, keyword arguments will
   still be accepted if the constructor accepts a dictionary of
   keyword arguments (as in ``def __init__(self,**params):``), and
   then each class calls its superclass (as in
   ``super(Foo,self).__init__(**params)``) so that the
   Parameterized constructor will process the keywords.

2. A Parameterized class need specify only the attributes of a
   Parameter whose values differ from those declared in
   superclasses; the other values will be inherited.  E.g. if Foo
   declares

    delta = Parameter(default=0.2) 

   the default value of 0.2 will override the 0.6 inherited from
   Bar, but the doc will be inherited from Bar.

3. The Parameter descriptor class can be subclassed to provide
   more complex behavior, allowing special types of parameters
   that, for example, require their values to be numbers in
   certain ranges, generate their values dynamically from a random
   distribution, or read their values from a file or other
   external source.

4. The attributes associated with Parameters provide enough
   information for automatically generating property sheets in
   graphical user interfaces, allowing Parameterized instances to
   be edited by users.

Note that Parameters can only be used when set as class attributes
of Parameterized classes. Parameters used as standalone objects,
or as class attributes of non-Parameterized classes, will not have
the behavior described here.

Nested Classes [hide private]

Inherited from parameterized.Parameter: __metaclass__

Instance Methods [hide private]
 
__init__(self, default=False, bounds=(0, 1), allow_None=False, **params)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__set__(self, obj, val)
Set the value for this Parameter.
source code

Inherited from parameterized.Parameter: __delete__, __get__, __getstate__, __setstate__

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

Properties [hide private]
  allow_None
  bounds

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

Inherited from object: __class__

Method Details [hide private]

__init__(self, default=False, bounds=(0, 1), allow_None=False, **params)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

__set__(self, obj, val)

source code 

Set the value for this Parameter.

If called for a Parameterized class, set that class's value (i.e. set this Parameter object's 'default' attribute).

If called for a Parameterized instance, set the value of this Parameter on that instance (i.e. in the instance's __dict__, under the parameter's internal_name).

If the Parameter's constant attribute is True, only allows the value to be set for a Parameterized class or on uninitialized Parameterized instances.

If the Parameter's readonly attribute is True, only allows the value to be specified in the Parameter declaration inside the Parameterized source code. A read-only parameter also cannot be set on a Parameterized class.

Note that until we support some form of read-only object, it is still possible to change the attributes of the object stored in a constant or read-only Parameter (e.g. the left bound of a BoundingBox).

Overrides: parameterized.Parameter.__set__
(inherited documentation)