2 class ObservableItem(object):
6 def __setattr__(self,name,new_value):
7 #print 'Setting %s to %s'%(name,value)
8 old_value = getattr(self,name,None)
9 super(ObservableItem,self).__setattr__(name,new_value)
10 self.notify_observers(name,new=new_value, old=old_value)
12 def notify_observers(self,name,new=None,old=None):
13 if 'observers' in self.__dict__:
14 for observer in self.observers:
15 observer.notify(self,name,new=new,old=old)
19 class ObservableList(list,ObservableItem):
21 ObservableItem.__init__(self)
23 def append(self,item):
24 super(ObservableList,self).append(item)
25 self.notify_observers('add_item', item, None)
27 def remove(self,item):
28 super(ObservableList,self).remove(item)
29 self.notify_observers('remove_item', item, None)
31 __all__ = ["ObservableItem","ObservableList"]