diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-01-27 15:44:45 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-01-27 15:44:45 +0100 |
commit | 2ea569c7ed70a40cccaaf32b3f8ea2e7127ac062 (patch) | |
tree | 239898333a7523d19e2f47cb9688e6948249983b /Locker.py | |
download | pylock-2ea569c7ed70a40cccaaf32b3f8ea2e7127ac062.tar pylock-2ea569c7ed70a40cccaaf32b3f8ea2e7127ac062.zip |
Initial commit
Diffstat (limited to 'Locker.py')
-rw-r--r-- | Locker.py | 38 |
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) |