Skip to content

Instantly share code, notes, and snippets.

@SquidDev
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SquidDev/ba82e66aec0fb8bce734 to your computer and use it in GitHub Desktop.
Save SquidDev/ba82e66aec0fb8bce734 to your computer and use it in GitHub Desktop.
Property Change Notify
from functools import wraps
class NotifyProperty(property):
def __init__(self, Get, Set = None, Del = None, Doc = None):
Setter = None
if Set != None:
@wraps(Set)
def Setter(self, Value):
Set(self, Value)
self.Notify(Set.__name__, Value)
super(NotifyProperty, self).__init__(Get, Setter, Del, Doc)
class NotifyObject(object):
def Noitfy(self, Name, Value):
pass
class Example(NotifyObject):
def __init__(self):
self._Prop = "Hello World"
@NotifyProperty
def Prop(self):
return self._Prop
@Prop.setter
def Prop(self, Value):
self._Prop = Value
def Notify(self, Name, Value):
print "Changing", Name , "to", Value
Foo = Example()
print Foo.Prop
Foo.Prop = "Goodbye"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment