Add build script for Linux.
[matthijs/upstream/mobilegtd.git] / src / model / observable.py
1
2 class ObservableItem(object):
3     
4     def __init__(self):
5         self.observers = []
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)
11
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)
16
17
18
19 class ObservableList(list,ObservableItem):
20     def __init__(self):
21         ObservableItem.__init__(self)
22
23     def append(self,item):
24         super(ObservableList,self).append(item)
25         self.notify_observers('add_item', item, None)   
26
27     def remove(self,item):
28         super(ObservableList,self).remove(item)
29         self.notify_observers('remove_item', item, None)   
30
31 __all__ = ["ObservableItem","ObservableList"]