diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-02 14:55:11 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-02-02 14:55:11 +0100 |
commit | fdce6479b90dbeef5ca1857b58e6a37ec21978fd (patch) | |
tree | 27c86550345ffecebae49cdbb07b6699b9113d13 | |
parent | 9981f9f6a2205ed56f16989b590d939d5dac974a (diff) | |
download | pylock-fdce6479b90dbeef5ca1857b58e6a37ec21978fd.tar pylock-fdce6479b90dbeef5ca1857b58e6a37ec21978fd.zip |
Added logout function
-rw-r--r-- | LockWindow.py | 39 | ||||
-rw-r--r-- | Locker.py | 7 | ||||
-rw-r--r-- | pylock.py | 3 |
3 files changed, 37 insertions, 12 deletions
diff --git a/LockWindow.py b/LockWindow.py index 89d7576..25d7546 100644 --- a/LockWindow.py +++ b/LockWindow.py @@ -9,6 +9,7 @@ _ = locale.gettext class LockWindow(Gtk.Window): __gsignals__ = { + 'logout': (GObject.SIGNAL_RUN_FIRST, None, ()), 'tryUnlock': (GObject.SIGNAL_RUN_FIRST, None, (str,)) } @@ -44,40 +45,56 @@ class LockWindow(Gtk.Window): self.unlockWindow.connect('delete-event', lambda w, e: True) self.promptEntry.connect('activate', lambda w: self._tryUnlock()) + self.logoutButton.connect('clicked', lambda w: self._logout()) self.unlockButton.connect('clicked', lambda w: self._tryUnlock()) - self.reset() + self.reset(True) + + def _logout(self): + self.promptEntry.set_sensitive(False) + self.unlockButton.set_sensitive(False) + self.logoutButton.set_sensitive(False) + GLib.idle_add(lambda: self.emit('logout')) def _tryUnlock(self): self.promptEntry.set_sensitive(False) self.unlockButton.set_sensitive(False) + self.logoutButton.set_sensitive(False) GLib.idle_add(lambda: self.emit('tryUnlock', self.promptEntry.get_text())) - def reset(self): - self.promptEntry.set_text('') - self.promptEntry.set_sensitive(True) - self.promptEntry.grab_focus() + def _update(self): + self.promptEntry.set_sensitive(self._enablePromptEntry) + self.logoutButton.set_sensitive(self._enableLogoutButton) + self.unlockButton.set_sensitive(self._enableUnlockButton) - self.unlockButton.set_sensitive(True) + def reset(self, resetButtons = False): + if resetButtons: + self._enablePromptEntry = True + self._enableLogoutButton = False + self._enableUnlockButton = True + self.promptEntry.set_text('') self.messageLabel.set_label('') + self._update() + + self.promptEntry.grab_focus() - self.logoutButton.set_sensitive(False) def updateLockMessage(self, username, logoutTime = None): if logoutTime is None: self.lockLabel.set_markup(_('This computer is currently locked by the user <i>{username}</i>.').format(username=GLib.markup_escape_text(username))) - self.logoutButton.set_sensitive(False) + self._enableLogoutButton = False elif logoutTime > 0: self.lockLabel.set_markup( _('This computer is currently locked by the user <i>{username}</i>.\nThe user can be logged out in {minutes:02}:{seconds:02} minutes.').format( username=GLib.markup_escape_text(username), minutes=logoutTime//60, seconds=logoutTime%60)) - self.logoutButton.set_sensitive(False) + self._enableLogoutButton = False else: self.lockLabel.set_markup( _('This computer is currently locked by the user <i>{username}</i>.\nThe user can be logged out now.').format( username=GLib.markup_escape_text(username))) - self.logoutButton.set_sensitive(True) + self._enableLogoutButton = True + self._update() def setAuthMessage(self, message): self.messageLabel.set_label(message) @@ -92,4 +109,4 @@ class LockWindow(Gtk.Window): self.unlockWindow.hide() self.hide() - self.reset() + self.reset(True) @@ -50,3 +50,10 @@ class Locker(object): self.locked = False GLib.timeout_add_seconds(1, self._checkLock) + + def _canLogout(self): + return (self.locked and self.doLogout is not None and self.currentLogoutTimeout <= 0) + + def logout(self): + if self._canLogout(): + self.doLogout() @@ -46,7 +46,7 @@ def lock(timeLeft): window.lock() def logout(): - pass + exit() def updateTimeout(timeLeft): window.updateLockMessage(username, timeLeft) @@ -64,6 +64,7 @@ def tryUnlock(w, password): return True +window.connect('logout', lambda w: locker.logout()) window.connect('tryUnlock', tryUnlock) Gtk.main() |