Package mvpa :: Package misc :: Module state :: Class StateCollection
[hide private]
[frames] | no frames]

Class StateCollection

source code


Container of StateVariables for a stateful object.
Instance Methods [hide private]
 
__init__(self, items=None, owner=None)
Initialize the state variables of a derived class
source code
 
_cls_repr(self)
Part of __repr__ for the owner object
source code
 
_is_initializable(self, index)
Checks if index could be assigned within collection via setvalue
source code
 
_initialize(self, index, value)
Initialize index (no check performed) with value
source code
 
_copy_states_(self, fromstate, index=None, deep=False)
Copy known here states from fromstate object into current object
source code
 
isEnabled(self, index)
Returns True if state index is enabled
source code
 
isActive(self, index)
Returns True if state index is known and is enabled
source code
 
enable(self, index, value=True, missingok=False)
Enable state variable given in index
source code
 
disable(self, index)
Disable state variable defined by index id
source code
 
_changeTemporarily(self, enable_states=None, disable_states=None, other=None)
Temporarily enable/disable needed states for computation
source code
 
_resetEnabledTemporarily(self)
Reset to previousely stored set of enabled states
source code
 
_getEnabled(self, nondefault=True, invert=False)
Return list of enabled states
source code
 
_setEnabled(self, indexlist)
Given `indexlist` make only those in the list enabled
source code

Inherited from Collection: __getattribute__, __getitem__, __repr__, __setattr__, __str__, add, get, isKnown, isSet, remove, reset, whichSet

Inherited from object: __delattr__, __format__, __hash__, __new__, __reduce__, __reduce_ex__, __sizeof__, __subclasshook__

Class Variables [hide private]
  enabled = property(fget= _getEnabled, fset= _setEnabled)

Inherited from Collection: items, listing, name, names, owner

Instance Variables [hide private]
  __storedTemporarily
List to contain sets of enabled states which were enabled temporarily.

Inherited from Collection (private): _items

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, items=None, owner=None)
(Constructor)

source code 
Initialize the state variables of a derived class
Parameters:
  • items (dict) - dictionary of states
  • owner (ClassWithCollections) - object which owns the collection
  • name (basestring) - literal description. Usually just attribute name for the collection, e.g. 'states'
Overrides: object.__init__

_cls_repr(self)

source code 
Part of __repr__ for the owner object
Returns:
list of items to be appended within __repr__ after a .join()
Overrides: Collection._cls_repr

_is_initializable(self, index)

source code 
Checks if index could be assigned within collection via setvalue
Returns:
bool value for a given index
Overrides: Collection._is_initializable

_initialize(self, index, value)

source code 
Initialize index (no check performed) with value
Overrides: Collection._initialize
(inherited documentation)

_copy_states_(self, fromstate, index=None, deep=False)

source code 

Copy known here states from fromstate object into current object

Crafted to overcome a problem mentioned above in the comment and is to be called from __copy__ of derived classes

Probably sooner than later will get proper __getstate__, __setstate__

Parameters:
  • fromstate (Collection or ClassWithCollections) - Source states to copy from
  • index (None or list of basestring) - If not to copy all set state variables, index provides selection of what to copy
  • deep (bool) - Optional control over the way to copy

_changeTemporarily(self, enable_states=None, disable_states=None, other=None)

source code 

Temporarily enable/disable needed states for computation

Enable or disable states which are enabled in other and listed in enable _states. Use resetEnabledTemporarily to reset to previous state of enabled.

other can be a ClassWithCollections object or StateCollection

_getEnabled(self, nondefault=True, invert=False)

source code 
Return list of enabled states
Parameters:
  • nondefault (bool) - Either to return also states which are enabled simply by default
  • invert (bool) - Would invert the meaning, ie would return disabled states

_setEnabled(self, indexlist)

source code 
Given `indexlist` make only those in the list enabled

It might be handy to store set of enabled states and then to restore
it later on. It can be easily accomplished now::

>>> from mvpa.misc.state import ClassWithCollections, StateVariable
>>> class Blah(ClassWithCollections):
...   bleh = StateVariable(enabled=False, doc='Example')
...
>>> blah = Blah()
>>> states_enabled = blah.states.enabled
>>> blah.states.enabled = ['bleh']
>>> blah.states.enabled = states_enabled