From 65f9c06e00c78c382451458ea1d8a9dad1016fb0 Mon Sep 17 00:00:00 2001 From: Marek Siarkowicz Date: Mon, 15 Jun 2015 12:55:18 +0200 Subject: Refactor. Move --- parrot_zik/utils.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 parrot_zik/utils.py (limited to 'parrot_zik/utils.py') diff --git a/parrot_zik/utils.py b/parrot_zik/utils.py new file mode 100644 index 0000000..18b878d --- /dev/null +++ b/parrot_zik/utils.py @@ -0,0 +1,31 @@ +from threading import Lock + +import gtk + + +class repeat(object): + def __init__(self, f): + self.f = f + self.id = None + self.lock = Lock() + + def __call__(self, cls): + self.f(cls) + + def start(self, cls, frequency): + self.lock.acquire() + if not self.id: + def run(): + self.f(cls) + return True + + self.id = gtk.timeout_add(frequency, run) + self.lock.release() + + def stop(self): + self.lock.acquire() + if self.id: + gtk.timeout_remove(self.id) + self.id = None + self.lock.release() + -- cgit v1.2.1