From 10c60652633e62cf120102f36b9354c7d330147c Mon Sep 17 00:00:00 2001 From: Felix Domke Date: Thu, 15 Jun 2006 17:34:39 +0000 Subject: [PATCH] add Event --- lib/python/Tools/Event.py | 23 +++++++++++++++++++++++ lib/python/Tools/Makefile.am | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 lib/python/Tools/Event.py diff --git a/lib/python/Tools/Event.py b/lib/python/Tools/Event.py new file mode 100644 index 00000000..6b96bff4 --- /dev/null +++ b/lib/python/Tools/Event.py @@ -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() diff --git a/lib/python/Tools/Makefile.am b/lib/python/Tools/Makefile.am index a2160d8a..2521cd97 100644 --- a/lib/python/Tools/Makefile.am +++ b/lib/python/Tools/Makefile.am @@ -3,5 +3,4 @@ installdir = $(LIBDIR)/enigma2/python/Tools install_DATA = \ FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py \ KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py \ - RedirectOutput.py DreamboxHardware.py - + RedirectOutput.py DreamboxHardware.py Import.py Event.py -- 2.30.2