Package cells :: Module cellattr :: Class CellAttr
[hide private]
[frames] | no frames]

Class CellAttr
source code

object --+
         |
        CellAttr

CellAttr

A descriptor which auto-vivifies a new Cell in each instance of a Model, and which does the hiding of Cell.get() and Cell.set().

Instance Methods [hide private]
  __init__(self, rule=None, value=None, unchanged_if=None, celltype=None)
Sets the parameters which will be used as defaults to build a Cell when the time comes.
  __set__(self, owner, value)
Runs set(value) on the Cell in owner.
  __get__(self, owner, ownertype)
Runs get() on the Cell in owner, if owner is passed.
  getcell(owner)
Return the instance of this CellAttr's Cell in owner.
  buildcell(self, owner, rule=None, value=None, celltype=None, unchanged_if=None)
Builds an instance of a Cell into owner.

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


Class Variables [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, rule=None, value=None, unchanged_if=None, celltype=None)
(Constructor)

source code 
Sets the parameters which will be used as defaults to build a Cell when the time comes.
Parameters:
  • rule - Define a rule which backs this cell. You must only define one of rule or value. Lacking celltype, this creates a RuleCell. This must be passed a callable with the signature f(self, prev) -> value, where self is the model instance the cell is in and prev is the cell's out-of-date value.
  • value - Define a value for this cell. You must only define one of rule or value. Lacking celltype, this creates an InputCell.
  • unchanged_if - Sets a function to determine if a cell's value has changed. The signature for the passed function is f(old, new) -> bool.
  • celltype - Set the cell type to generate. You must pass rule or value correctly. Refer to cells.cell for available types.
Overrides: object.__init__

__set__(self, owner, value)

source code 
Runs set(value) on the Cell in owner.
Parameters:
  • owner - The Model instance in which to look for the Cell to run set() on.
  • value - The value to set
Returns:
None

__get__(self, owner, ownertype)

source code 
Runs get() on the Cell in owner, if owner is passed. Otherwise, return self.
Parameters:
  • owner - The Model instance in which to look for the Cell to run get() on .
  • ownertype - (unused)
Returns:
value

getcell(owner)

source code 
Return the instance of this CellAttr's Cell in owner. If an instance of the CellAttr's Cell doesn't exist in owner, first insert an instance into owner, then return it. To build it, first examine the owner for runtime overrides of this cell, and use those (if they exist) as parameters to buildcell.
Parameters:
  • owner - The Model instance in which to look for the Cell.
Returns:
Cell

buildcell(self, owner, rule=None, value=None, celltype=None, unchanged_if=None)

source code 
Builds an instance of a Cell into owner. Will automatically create the right type of Cell given the keyword arguments if celltype is not passed
Parameters:
  • owner - The Model instance in which to build the Cell.
  • rule - Define a rule which backs this cell. You must only define one of rule or value. Lacking celltype, this creates a RuleCell. This must be passed a callable with the signature f(self, prev) -> value, where self is the model instance the cell is in and prev is the cell's out-of-date value.
  • value - Define a value for this cell. You must only define one of rule or value. Lacking celltype, this creates an InputCell.
  • unchanged_if - Sets a function to determine if a cell's value has changed. The signature for the passed function is f(old, new) -> bool.
  • celltype - Set the cell type to generate. You must pass rule or value correctly. Refer to cells.cell for available types.
Returns:
Cell