Package cells :: Module family :: Class Family
[hide private]
[frames] | no frames]

Class Family
source code

 object --+    
          |    
model.Model --+
              |
             Family

Family

A specialized Model which has kids, kid_slots, and a number of convenience functions for traversing the parent/child graph.

Nested Classes [hide private]

Inherited from model.Model: __metaclass__


Instance Methods [hide private]
  __init__(self, *args, **kwargs)
__init__(self, [<attrname>=<value, rule or dict>], ...) -> None
  _kid_instance(self, klass=None)
Creates a new instance of a Cell based on the passed class (in klass) and the overrides defined in kid_slots.
  make_kid(self, klass)
Adds a new instance of a Cell based on the passed class (in klass) and the overrides defined in kid_slots into the kids list
  _add_kid(self, kid)
Inserts the kid into this Family's kids list
  position(self)
Returns this instance's position in the enclosing Family's kids list.
  previous_sib(self)
Returns the Model previous to this Model in the enclosing Family's kids list
  next_sib(self)
Returns the Model subsequent to this Model in the enclosing Family's kids list
  grandparent(self)
Returns enclosing Family instance's enclosing Family instance, or None if no such object exists.

Inherited from model.Model: __setattr__

Inherited from model.Model (private): _buildcell, _run_observers

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


Class Methods [hide private]

Inherited from model.Model: observer


Class Variables [hide private]
_noncells  

Inherited from model.Model (private): _initialized, _observernames

Inherited from object: __class__


Instance Variables [hide private]
kids A list of Models which are guaranteed to have the attribute overrides defined in kid_slots
kid_slots An override definition for the Cells inserted into the kids list.

Inherited from model.Model: model_name, model_value, parent


Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

__init__(self, [<attrname>=<value, rule or dict>], ...) -> None

Initialize a Model with optional overrides. By passing a parameter with the same name as a cell attribute, you may override that cell attribute. For example:
>>> class A(cells.Model):
...     x = cells.makecell(value=1)
... 
>>> a1 = A()
>>> a1.x
1

>>> a2 = A(x="blah")
>>> a2.x
'blah'
This override can be arbitrarily complex; for instance, you can make a RuleCell into a ValueCell, change a attribute's celltype ... In short, anything you can do at Model defintion time you can alter at instantiation time:
>>> class B(cells.Model):
...     x = cells.makecell(rule=lambda s,p: 3 * s.y)
...     y = cells.makecell(value=2)
... 
>>> b = B()
>>> b.x
6

>>> b.y = 1
>>> b.x
3

>>> b = B(y=10)
>>> b.x
30

>>> b.y
10

>>> b = B(x={'celltype': cells.RuleThenInputCell})
>>> b.x
6

>>> b.y
2

>>> b.x = 5
>>> b.x
5

>>> b.y = 1
>>> b.x
5
Overrides: model.Model.__init__
(inherited documentation)

_kid_instance(self, klass=None)

source code 
Creates a new instance of a Cell based on the passed class (in klass) and the overrides defined in kid_slots.
Parameters:
  • klass - The base type for the new kid instance
Returns:
Cell

make_kid(self, klass)

source code 
Adds a new instance of a Cell based on the passed class (in klass) and the overrides defined in kid_slots into the kids list
Parameters:
  • klass - the base type for the new kid instance
Returns:
None

_add_kid(self, kid)

source code 
Inserts the kid into this Family's kids list
Parameters:
  • kid - the Model instance to insert
Returns:
None

position(self)

source code 
Returns this instance's position in the enclosing Family's kids list. Returns -1 if there is no enclosing Family.
Returns:
int

Raises:
  • FamilyTraversalError - Raises if there is no enclosing Family

previous_sib(self)

source code 
Returns the Model previous to this Model in the enclosing Family's kids list
Returns:
Model

Raises:
  • FamilyTraversalError - Raises if there is no enclosing Family

next_sib(self)

source code 
Returns the Model subsequent to this Model in the enclosing Family's kids list
Returns:
Model

Raises:
  • FamilyTraversalError - Raises if there is no enclosing Family

grandparent(self)

source code 
Returns enclosing Family instance's enclosing Family instance, or None if no such object exists.
Returns:
Model


Class Variable Details [hide private]

_noncells

Value:
set(['_add_kid', '__module__', 'position', '__metaclass__', 'observer'\
, 'grandparent', '_initialized', '_kid_instance', '__setattr__', 'make\
_kid', 'previous_sib', '_buildcell', '_run_observers', 'next_sib', '__\
doc__', '__init__'])                                                   
      

Instance Variable Details [hide private]

kids

A list of Models which are guaranteed to have the attribute overrides defined in kid_slots
Value:
<cells.cellattr.CellAttr object at 0x70bf50>                           
      

kid_slots

An override definition for the Cells inserted into the kids list. The attributes overridden are every attribute defined in the class in kid_slots minus the attributes defined in every Model.
Value:
<cells.cellattr.CellAttr object at 0x70bf90>