ui: add fetch/push/pull buttons and a spacer
[ugit.git] / ugit / observer.py
blob9e1c16988d31c636c268f44793e65d5cdaec6ac0
1 #!/usr/bin/env python
2 from pprint import pformat
4 class Observer(object):
5 '''Observers receive notify(*attributes) messages from their
6 subjects whenever new data arrives. This notify() message signifies
7 that an observer should update its internal state/view.'''
9 def __init__(self, model):
10 self.model = model
11 self.model.add_observer(self)
12 self.__debug = False
14 def __del__(self):
15 self.model.remove_observer(self)
17 def set_debug(self, enabled):
18 self.__debug = enabled
20 def notify(self, *attributes):
21 '''Called by the model to notify Observers about changes.'''
22 # We can be notified about multiple attribute changes at once
23 model = self.model
24 for attr in attributes:
25 notify = model.get_notify()
26 model.set_notify(False) # NOTIFY OFF
28 value = model.get_param(attr)
29 self.subject_changed(attr, value)
31 model.set_notify(notify) # NOTIFY ON
33 def subject_changed(self, attr, value):
34 '''This method handles updating of the observer/UI.
35 This must be implemented in each concrete observer class.'''
37 msg = 'Concrete Observers must override subject_changed().'
38 raise NotImplementedError, msg