summaryrefslogtreecommitdiffstats
path: root/Locker.py
diff options
context:
space:
mode:
Diffstat (limited to 'Locker.py')
-rw-r--r--Locker.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Locker.py b/Locker.py
new file mode 100644
index 0000000..7871307
--- /dev/null
+++ b/Locker.py
@@ -0,0 +1,38 @@
+from gi.repository import Gtk, GLib
+
+import Idle
+
+
+class Locker(object):
+ def __init__(self, lockTimeout, doLock, doUnlock, logoutTimeout = 0, doLogout = None):
+ self.locked = False
+ self.lockTimeout = lockTimeout
+ self.logoutTimeout = logoutTimeout
+ self.doLock = doLock
+ self.doUnlock = doUnlock
+ self.doLogout = doLogout
+
+ GLib.timeout_add_seconds(1, self.checkLock)
+
+ def checkLock(self):
+ if self.locked:
+ return False
+
+ idle = Idle.getIdleSec()
+ if (idle >= self.lockTimeout):
+ GLib.idle_add(self.lock)
+ return False
+ else:
+ return True
+
+ def lock(self):
+ if not self.locked:
+ self.doLock()
+ self.locked = True
+
+ def unlock(self):
+ if self.locked:
+ self.doUnlock()
+ self.locked = False
+
+ GLib.timeout_add(100, self.checkLock)