1 """
2 Observers are objects listening to EventDispatchers.
3
4 They are mostly used as bases for UIs in the context of the DC.
5 """
6
7
8
9
10
11
12
14 """is a decorator to make a method listen to a set of events.
15
16 It receives one or more event names.
17 """
18 def deco(meth):
19 meth.listensTo = args
20 return meth
21 return deco
22
23
25 """is a base class for observers.
26
27 Observers have methods listening to certain events. Use the listen
28 decorator above to make the connections. The actual event subscriptions
29 are done in the constructor.
30
31 The signature of the listeners always is::
32
33 listener(dispatcher, arg) -> ignored
34
35 dispatcher is the EventDispatcher instance propagating the event. It
36 has lots of useful attributes explained in base.event's notifyXXX docstrings.
37
38 You can listen to anything that has a notify method in the EventDispatcher.
39 """
41 self.dispatcher = dispatcher
42 for name in dir(self):
43 att = getattr(self, name)
44 if hasattr(att, "listensTo"):
45 for ev in att.listensTo:
46 dispatcher.subscribe(ev, att)
47