Last active
December 24, 2015 12:19
-
-
Save ChadSki/6797377 to your computer and use it in GitHub Desktop.
PyNotifyPropertyChanged proposal
This file contains hidden or 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
| # Defining a class with a property | |
| class Foo(object): | |
| def __init__(self): | |
| self._bar = 0 | |
| @property | |
| def bar(self): | |
| return self._bar | |
| @bar.setter | |
| def bar(self, value): | |
| self._bar = value | |
| ########################################################### | |
| # Same thing, but define the property externally | |
| class Foo(object): | |
| def __init__(self): | |
| self._bar = 0 | |
| def fget(self): | |
| return self._bar | |
| def fset(self, value): | |
| self._bar = value | |
| setattr(Foo, 'bar', property(fget=fget, fset=fset)) | |
| ########################################################### | |
| # A class with property notifications | |
| from PyNotifyPropertyChanged import INotifyPropertyChanged, OnPropertyChanged | |
| @INotifyPropertyChanged | |
| class Foo(object): | |
| def __init__(self): | |
| self._bar = 0 | |
| def fget(self): | |
| return self._bar | |
| def fset(self, value): | |
| self._bar = value | |
| setattr(Foo, 'bar', OnPropertyChanged(property(fget=fget, fset=fset))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment