Last active
August 29, 2015 14:02
-
-
Save SquidDev/ba82e66aec0fb8bce734 to your computer and use it in GitHub Desktop.
Property Change Notify
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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