main.view: Fix interactive diff font setting
[git-cola.git] / cola / notification.py
blobbc3644119d40f56f623c9067d98899bda7f07b47
1 import os
3 from cola.compat import set
4 from cola.decorators import memoize
7 debug = os.environ.get('COLA_NOTIFIER_DEBUG', False)
10 @memoize
11 def notifier():
12 return Notifier()
15 class Notifier(object):
16 """Object for sending and receiving notification messages"""
18 def __init__(self):
19 self.channels = {}
21 def broadcast(self, signal, *args, **opts):
22 if debug:
23 print ('broadcast: %s(%s, %s)' % (signal,
24 args or '<empty>',
25 opts or '<empty>'))
26 self.emit(signal, *args, **opts)
28 def emit(self, signal, *args, **opts):
29 subscribers = self.channels.get(signal, None)
30 if not subscribers:
31 return
32 for fxn in subscribers:
33 fxn(*args, **opts)
35 def connect(self, signal, callback):
36 subscribers = self.channels.setdefault(signal, set())
37 subscribers.add(callback)