aboutsummaryrefslogtreecommitdiff
path: root/parrot_zik/utils.py
diff options
context:
space:
mode:
authorm0sia <m0sia@m0sia.ru>2016-02-18 15:04:42 -0600
committerm0sia <m0sia@m0sia.ru>2016-02-18 15:04:42 -0600
commit52c1c1f9d06631b94c3b8ce8eaf816c5a36842b3 (patch)
tree020f823cf692d1ce6898649a15c7633c831dd972 /parrot_zik/utils.py
parentf57d9a8d4ebc30effbec71382cce7e0a37b697e3 (diff)
parent92e47683fc783a2dbd3d9737af40eb0b3372af61 (diff)
downloadpyParrotZikTCP-52c1c1f9d06631b94c3b8ce8eaf816c5a36842b3.tar.xz
pyParrotZikTCP-52c1c1f9d06631b94c3b8ce8eaf816c5a36842b3.zip
Merge pull request #12 from serathius/master
Rework and Zik 2.0 implementation.
Diffstat (limited to 'parrot_zik/utils.py')
-rw-r--r--parrot_zik/utils.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/parrot_zik/utils.py b/parrot_zik/utils.py
new file mode 100644
index 0000000..86f52cd
--- /dev/null
+++ b/parrot_zik/utils.py
@@ -0,0 +1,32 @@
+import functools
+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:
+ @functools.wraps(self.f)
+ 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()
+