add Event
[enigma2.git] / lib / python / Tools / Event.py
1
2 class Event:
3         def __init__(self, start = None, stop = None):
4                 self.list = [ ]
5                 self.start = start
6                 self.stop = stop
7         
8         def __call__(self, *args, **kwargs):
9                 for x in self.list:
10                         x(*args, **kwargs)
11
12         def listen(self, fnc):
13                 was_empty = len(self.list) == 0
14                 self.list.append(fnc)
15                 if was_empty:
16                         if self.start:
17                                 self.start()
18
19         def unlisten(self, fnc):
20                 self.list.remove(fnc)
21                 if len(self.list) == 0:
22                         if self.stop:
23                                 self.stop()