Created
May 12, 2013 07:50
-
-
Save geojeff/5562780 to your computer and use it in GitHub Desktop.
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
cdef inline void observable_list_dispatch(object self): | |
cdef Property prop = self.prop | |
obj = self.obj() | |
if obj is not None: | |
prop.dispatch(obj) | |
class ObservableList(list): | |
# Internal class to observe changes inside a native python list. | |
def __init__(self, *largs): | |
self.prop = largs[0] | |
self.obj = ref(largs[1]) | |
super(ObservableList, self).__init__(*largs[2:]) | |
def __setitem__(self, key, value): | |
list.__setitem__(self, key, value) | |
observable_list_dispatch(self) | |
def __delitem__(self, key): | |
list.__delitem__(self, key) | |
observable_list_dispatch(self) | |
def __setslice__(self, *largs): | |
list.__setslice__(self, *largs) | |
observable_list_dispatch(self) | |
def __delslice__(self, *largs): | |
list.__delslice__(self, *largs) | |
observable_list_dispatch(self) | |
def __iadd__(self, *largs): | |
list.__iadd__(self, *largs) | |
observable_list_dispatch(self) | |
def __imul__(self, *largs): | |
list.__imul__(self, *largs) | |
observable_list_dispatch(self) | |
def append(self, *largs): | |
list.append(self, *largs) | |
observable_list_dispatch(self) | |
def remove(self, *largs): | |
list.remove(self, *largs) | |
observable_list_dispatch(self) | |
def insert(self, *largs): | |
list.insert(self, *largs) | |
observable_list_dispatch(self) | |
def pop(self, *largs): | |
cdef object result = list.pop(self, *largs) | |
observable_list_dispatch(self) | |
return result | |
def extend(self, *largs): | |
list.extend(self, *largs) | |
observable_list_dispatch(self) | |
def sort(self, *largs): | |
list.sort(self, *largs) | |
observable_list_dispatch(self) | |
def reverse(self, *largs): | |
list.reverse(self, *largs) | |
observable_list_dispatch(self) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment