def __init__(self, getter): def newgetter(slf): #return None when the property does not exist yet try: return getter(slf) except AttributeError: return None getter = clrtype.accepts()(getter) clrtype.propagate_attributes(getter, newgetter) super(notify_property, self).__init__(newgetter)
def setter(self, setter): def newsetter(slf, newvalue): # do not change value if the new value is the same # trigger PropertyChanged event when value changes oldvalue = self.fget(slf) if oldvalue != newvalue: setter(slf, newvalue) slf.OnPropertyChanged(setter.__name__) setter = clrtype.returns()(setter) clrtype.propagate_attributes(setter, newsetter) return property( fget=self.fget, fset=newsetter, fdel=self.fdel, doc=self.__doc__)