views.dag: Micro-optimize Node type(), shape(), boundingRect(), and glyph()
[git-cola.git] / cola / observer.py
blob407ecd92b0f6d97244d7db98aded92041f4a83f8
1 # Copyright (c) 2008 David Aguilar
2 """This module provides the Observer design pattern.
3 """
5 class Observer(object):
6 """Implements the Observer pattern for a single subject"""
8 def __init__(self, model):
9 self.model = model
10 self.model.add_observer(self)
12 def __del__(self):
13 self.model.remove_observer(self)
15 def notify(self, *attributes):
16 """Called by the model to notify Observers about changes."""
17 # We can be notified about multiple attribute changes at once
18 model = self.model
19 for attr in attributes:
20 notify = model.notification_enabled
21 model.notification_enabled = False # NOTIFY OFF
23 value = model.param(attr)
24 self.subject_changed(attr, value)
26 model.notification_enabled = notify # NOTIFY ON
28 def subject_changed(self, attr, value):
29 """
30 Updates the observer/view
32 This must be implemented by concrete observers class.
33 """
35 msg = 'Concrete Observers must override subject_changed().'
36 raise NotImplementedError(msg)