Package topo :: Package base :: Module parameterizedobject :: Class ParameterizedObject
[hide private]
[frames] | no frames]

Class ParameterizedObject

source code

object --+
         |
        ParameterizedObject
Known Subclasses:
simulation.EPConnection, simulation.EventProcessor, simulation.Simulation, simulation.SomeTimer, misc.numbergenerators.BoundedNumber, misc.numbergenerators.RandomDistribution, misc.numbergenerators.ExponentialDecay, patterngenerator.PatternGenerator, misc.traces.ActivityMovie, misc.traces.Trace, misc.traces.TraceGroup, tkgui.tkparameterizedobject.TkParameterizedObjectBase, plotting.plotgroup.PlotGroup, tkgui.topoconsole.PlotsMenuEntry, cf.CFPResponseFn, cf.CFPOutputFn, cf.ConnectionField, analysis.featureresponses.DistributionMatrix, analysis.featureresponses.FeatureResponses, analysis.featureresponses.FullMatrix, patterns.image.FastPatternSampler, patterns.image.PatternSampler, functionfamilies.LearningFn, cf.CFPLearningFn, projection.SheetMask, plotting.bitmap.Bitmap, plotting.palette.Palette, plotting.palette.StringBasedPalette, plotting.plot.Plot, plotting.plotfilesaver.PlotGroupSaver, commands.analysis.PatternPresenter, commands.analysis.Subplotting, boundingregion.BoundingRegion, sheetview.SheetView, functionfamilies.CoordinateMapperFn, functionfamilies.ResponseFn, functionfamilies.OutputFn

Base class for named objects that support Parameters and message formatting.

Automatic object naming: Every ParameterizedObject has a name parameter. If the user doesn't designate a name=<str> argument when constructing the object, the object will be given a name consisting of its class name followed by a unique 5-digit number.

Automatic parameter setting: The ParameterizedObject __init__ method will automatically read the list of keyword parameters. If any keyword matches the name of a Parameter (see Parameter class) defined in the object's class or any of its superclasses, that parameter in the instance will get the value given as a keyword argument. For example:

class Foo(ParameterizedObject):
xx = Parameter(default=1)

foo = Foo(xx=20)

in this case foo.xx gets the value 20.

Message formatting: Each ParameterizedObject has several methods for optionally printing output according to the current 'print level', such as SILENT, WARNING, MESSAGE, VERBOSE, or DEBUG. Each successive level allows more messages to be printed. For example, when the level is VERBOSE, all warning, message, and verbose output will be printed. When it is WARNING, only warnings will be printed. When it is SILENT, no output will be printed.

For each level (except SILENT) there's an associated print method: ParameterizedObject.warning(), .message(), .verbose(), and .debug().

Each line printed this way is prepended with the name of the object that printed it. The ParameterizedObject parameter print_level, and the module global variable min_print_level combine to determine what gets printed. For example, if foo is a ParameterizedObject:

foo.message('The answer is',42)

is equivalent to:

if max(foo.print_level,base.min_print_level) >= MESSAGE:
print foo.name+':', 'The answer is', 42


Nested Classes [hide private]
  __metaclass__
The metaclass of ParameterizedObject (and all its descendents).
Instance Methods [hide private]
 
__db_print(self, level=100, *args)
Print each of the given args iff print_level or self.db_print_level is greater than or equal to the given level.
source code
 
__generate_name(self, *args, **kw)
Set name to a gensym formed from the object's type name and the object_count.
source code
 
__getstate__(self)
Save the object's state: return a dictionary that is a shallow copy of the object's __dict__.
source code
 
__init__(self, **params)
Initialize this ParameterizedObject.
source code
 
__repr__(self)
Provide a nearly valid Python representation that could be used to recreate the item with its parameters, if executed in the appropriate environment.
source code
 
__setstate__(self, state)
Restore objects from the state dictionary to this object.
source code
 
__str__(self)
Return a short representation of the name and class of this object.
source code
 
_check_params(self, params)
Print a warning if params contains something that is not a Parameter of this object.
source code
 
_instantiate_param(self, param_obj, dict_=None, key=None) source code
 
_set_name(self, *args, **kw) source code
 
_setup_params(self, *args, **kw)
Initialize default and keyword parameter values.
source code
 
as_uninitialized(fn)
Decorator: call fn with the instance's initialization flag set to False, then revert the flag.
source code
 
debug(self, *args)
Print the arguments as a debugging statement.
source code
 
defaults(self)
Return {parameter_name:parameter.default} for all non-constant Parameters.
source code
 
force_new_dynamic_value(cls_or_slf, name)
'optional @classmethod'
source code
 
get_param_values(self, onlychanged=False)
Return a list of name,value pairs for all Parameters of this object
source code
 
get_value_generator(cls_or_slf, name)
'optional @classmethod'
source code
 
inspect_value(cls_or_slf, name)
'optional @classmethod'
source code
 
message(self, *args)
Print the arguments as a message.
source code
 
print_param_values(self)
Print the values of all this object's Parameters.
source code
 
script_repr(self, imports=[], prefix=' ')
Variant of __repr__ designed for generating a runnable script.
source code
 
verbose(self, *args)
Print the arguments as a verbose message.
source code
 
warning(self, *args)
Print the arguments as a warning, unless module variable warnings_as_exceptions is True, then raise an Exception containing the arguments.
source code

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

Class Methods [hide private]
 
params(cls)
classmethod(function) -> method
source code
 
print_param_defaults(cls)
classmethod(function) -> method
source code
Class Variables [hide private]
  name = <topo.base.parameterizedobject.Parameter object at 0x98...
String identifier for this object.
  print_level = <topo.base.parameterizedobject.Parameter object ...
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__db_print(self, level=100, *args)

source code 

Print each of the given args iff print_level or self.db_print_level is greater than or equal to the given level.

Any of args may be functions, in which case they will be called. This allows delayed execution, preventing time-consuming code from being called unless the print level requires it.

__generate_name(self, *args, **kw)

source code 
Set name to a gensym formed from the object's type name and the object_count.
Decorators:
  • @as_uninitialized

__init__(self, **params)
(Constructor)

source code 

Initialize this ParameterizedObject.

The values of parameters can be supplied as keyword arguments to the constructor (using parametername=parametervalue); these values will override the class default values for this one instance.

If no 'name' parameter is supplied, self.name defaults to the object's class name with a unique number appended to it.

Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 

Provide a nearly valid Python representation that could be used to recreate the item with its parameters, if executed in the appropriate environment.

Returns 'classname(parameter1=x,parameter2=y,...)', listing all the parameters of this object.

Overrides: object.__repr__

__setstate__(self, state)

source code 

Restore objects from the state dictionary to this object.

During this process the object is considered uninitialized.

__str__(self)
(Informal representation operator)

source code 
Return a short representation of the name and class of this object.
Overrides: object.__str__

_check_params(self, params)

source code 

Print a warning if params contains something that is not a Parameter of this object.

Typically invoked by a __call__() method that accepts keyword arguments for parameter setting.

_set_name(self, *args, **kw)

source code 
Decorators:
  • @as_uninitialized

_setup_params(self, *args, **kw)

source code 

Initialize default and keyword parameter values.

First, ensures that all Parameters with 'instantiate=True' (typically used for mutable Parameters) are copied directly into each object, to ensure that there is an independent copy (to avoid suprising aliasing errors). Then sets each of the keyword arguments, warning when any of them are not defined as parameters.

Constant Parameters can be set during calls to this method.

Decorators:
  • @as_uninitialized

defaults(self)

source code 

Return {parameter_name:parameter.default} for all non-constant Parameters.

Note that a Parameter for which instantiate==True has its default instantiated.

force_new_dynamic_value(cls_or_slf, name)

source code 

'optional @classmethod'

A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument.

Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.

Decorators:
  • @bothmethod

get_value_generator(cls_or_slf, name)

source code 

'optional @classmethod'

A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument.

Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.

Decorators:
  • @bothmethod

inspect_value(cls_or_slf, name)

source code 

'optional @classmethod'

A decorator that allows a method to receive either the class object (if called on the class) or the instance object (if called on the instance) as its first argument.

Code (but not documentation) copied from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/523033.

Decorators:
  • @bothmethod

params(cls)
Class Method

source code 

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
def f(cls, arg1, arg2, ...): ... f = classmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.

print_param_defaults(cls)
Class Method

source code 

classmethod(function) -> method

Convert a function to be a class method.

A class method receives the class as implicit first argument, just like an instance method receives the instance. To declare a class method, use this idiom:

class C:
def f(cls, arg1, arg2, ...): ... f = classmethod(f)

It can be called either on the class (e.g. C.f()) or on an instance (e.g. C().f()). The instance is ignored except for its class. If a class method is called for a derived class, the derived class object is passed as the implied first argument.

Class methods are different than C++ or Java static methods. If you want those, see the staticmethod builtin.


Class Variable Details [hide private]

name

String identifier for this object.
Value:
Parameter(default= None, constant= True, doc= """
    String identifier for this object.""")

print_level

Value:
Parameter(default= MESSAGE, precedence=-1)