add Event
[enigma2.git] / lib / python / Tools / Event.py
diff --git a/lib/python/Tools/Event.py b/lib/python/Tools/Event.py
new file mode 100644 (file)
index 0000000..6b96bff
--- /dev/null
@@ -0,0 +1,23 @@
+
+class Event:
+       def __init__(self, start = None, stop = None):
+               self.list = [ ]
+               self.start = start
+               self.stop = stop
+       
+       def __call__(self, *args, **kwargs):
+               for x in self.list:
+                       x(*args, **kwargs)
+
+       def listen(self, fnc):
+               was_empty = len(self.list) == 0
+               self.list.append(fnc)
+               if was_empty:
+                       if self.start:
+                               self.start()
+
+       def unlisten(self, fnc):
+               self.list.remove(fnc)
+               if len(self.list) == 0:
+                       if self.stop:
+                               self.stop()