use the enum module to represent states
[~helmut/onoff.git] / onoff / gobject.py
index 73ed7d2..a2f9428 100644 (file)
@@ -18,3 +18,15 @@ def spawn_child(command, callback):
     assert pid
     GObject.child_watch_add(pid, callback)
     return pid
+
+class ScheduledFunction(object):
+    def __init__(self, interval, function):
+        """
+        @type interval: float
+        @param interval: seconds
+        """
+        self.event = GObject.timeout_add(int(1000 * interval), function)
+
+    def cancel(self):
+        ret = GObject.source_remove(self.event)
+        assert ret