views.actions: Add a command wrapper for run_command and use it
[git-cola.git] / cola / notification.py
blob84ae3c8e6d2d7d929889a66c7d129eecd68862af
1 import os
2 from PyQt4 import QtCore
4 from cola.compat import set
6 debug = os.environ.get('COLA_NOTIFIER_DEBUG', False)
7 _instance = None
8 def notifier():
9 global _instance
10 if _instance:
11 return _instance
12 _instance = Notifier()
13 return _instance
16 class Notifier(object):
17 """A pure-python re-implementation of QObject."""
18 def __init__(self):
19 self.channels = {}
21 def broadcast(self, signal, *args, **opts):
22 if debug:
23 print ('broadcast: %s(%s, %s)' % (name,
24 args or '<empty>',
25 kwargs or '<empty>'))
26 self.emit(signal, *args, **opts)
28 def emit(self, signal, *args, **opts):
29 subscribers = self.channels.get(signal, None)
30 if subscribers:
31 for fxn in subscribers:
32 fxn(*args, **opts)
34 def connect(self, signal, callback):
35 subscribers = self.channels.setdefault(signal, set())
36 subscribers.add(callback)