Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

Changeset 138

Show
Ignore:
Timestamp:
01/07/06 22:38:54
Author:
fumanchu
Message:

New TriggerProperty? class, a subclass of UnitProperty? to help write triggers which should fire immediately on __set__.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/units.py

    r137 r138  
    1313 
    1414__all__ = ['UnitAssociation', 'ToMany', 'ToOne', 'UnitJoin', 
    15            'Unit', 'UnitProperty', 'MetaUnit', 
     15           'Unit', 'UnitProperty', 'TriggerProperty', 'MetaUnit', 
    1616           'UnitSequencerInteger', 'UnitSequencerNull', 
    1717           'UnitSequencerUnicode', 
     
    349349 
    350350 
     351class TriggerProperty(UnitProperty): 
     352    """UnitProperty subclass for managing immediate triggers on set. 
     353     
     354    The __set__ method will call the on_set method, which should then 
     355    deal with the new value. 
     356    """ 
     357     
     358    def __set__(self, unit, value): 
     359        if self.coerce: 
     360            value = self.coerce(unit, value) 
     361        oldvalue = unit._properties[self.key] 
     362        if oldvalue != value: 
     363            unit._properties[self.key] = value 
     364            if unit.sandbox: 
     365                self.on_set(unit, oldvalue) 
     366     
     367    def on_set(self, unit, oldvalue): 
     368        pass 
     369 
     370 
    351371class MetaUnit(type): 
    352372