From 9981f9f6a2205ed56f16989b590d939d5dac974a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 1 Feb 2012 19:53:29 +0100 Subject: Add logout button timeout. Add l10n support. --- LockWindow.py | 28 +++++++++++++++++++++++++++- Locker.py | 24 +++++++++++++++++++----- po/de.po | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ po/pylock.pot | 46 ++++++++++++++++++++++++++++++++++++++++++++++ pylock.py | 22 ++++++++++++++++++++-- unlock.ui | 12 ++++-------- 6 files changed, 165 insertions(+), 16 deletions(-) create mode 100644 po/de.po create mode 100644 po/pylock.pot diff --git a/LockWindow.py b/LockWindow.py index 98b8e86..89d7576 100644 --- a/LockWindow.py +++ b/LockWindow.py @@ -1,8 +1,12 @@ import sys +import locale from gi.repository import Gtk, Gdk, GObject, GLib +_ = locale.gettext + + class LockWindow(Gtk.Window): __gsignals__ = { 'tryUnlock': (GObject.SIGNAL_RUN_FIRST, None, (str,)) @@ -26,6 +30,7 @@ class LockWindow(Gtk.Window): sys.exit(1) self.unlockWindow = builder.get_object('unlock_window') + self.lockLabel = builder.get_object('lock_label') self.promptEntry = builder.get_object('prompt_entry') self.messageLabel = builder.get_object('message_label') self.logoutButton = builder.get_object('logout_button') @@ -45,15 +50,36 @@ class LockWindow(Gtk.Window): def _tryUnlock(self): self.promptEntry.set_sensitive(False) + self.unlockButton.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() + + self.unlockButton.set_sensitive(True) + self.messageLabel.set_label('') - def setMessage(self, message): + 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 {username}.').format(username=GLib.markup_escape_text(username))) + self.logoutButton.set_sensitive(False) + elif logoutTime > 0: + self.lockLabel.set_markup( + _('This computer is currently locked by the user {username}.\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) + else: + self.lockLabel.set_markup( + _('This computer is currently locked by the user {username}.\nThe user can be logged out now.').format( + username=GLib.markup_escape_text(username))) + self.logoutButton.set_sensitive(True) + + def setAuthMessage(self, message): self.messageLabel.set_label(message) def lock(self): diff --git a/Locker.py b/Locker.py index 7871307..2af8f70 100644 --- a/Locker.py +++ b/Locker.py @@ -4,17 +4,18 @@ import Idle class Locker(object): - def __init__(self, lockTimeout, doLock, doUnlock, logoutTimeout = 0, doLogout = None): + def __init__(self, lockTimeout, doLock, doUnlock, logoutTimeout = 0, doLogout = None, updateLogoutTimeout = None): self.locked = False self.lockTimeout = lockTimeout self.logoutTimeout = logoutTimeout self.doLock = doLock self.doUnlock = doUnlock self.doLogout = doLogout + self.updateLogoutTimeout = updateLogoutTimeout - GLib.timeout_add_seconds(1, self.checkLock) + GLib.timeout_add_seconds(1, self._checkLock) - def checkLock(self): + def _checkLock(self): if self.locked: return False @@ -25,14 +26,27 @@ class Locker(object): else: return True + def _checkLogout(self): + self.currentLogoutTimeout = self.currentLogoutTimeout - 1 + if self.updateLogoutTimeout is not None: + self.updateLogoutTimeout(self.currentLogoutTimeout) + + return self.currentLogoutTimeout > 0 + def lock(self): if not self.locked: - self.doLock() + self.doLock(self.logoutTimeout) self.locked = True + if self.doLogout is not None: + self.currentLogoutTimeout = self.logoutTimeout + + if self.currentLogoutTimeout > 0: + GLib.timeout_add_seconds(1, self._checkLogout) + def unlock(self): if self.locked: self.doUnlock() self.locked = False - GLib.timeout_add(100, self.checkLock) + GLib.timeout_add_seconds(1, self._checkLock) diff --git a/po/de.po b/po/de.po new file mode 100644 index 0000000..9320df1 --- /dev/null +++ b/po/de.po @@ -0,0 +1,49 @@ +# Pylock german translation +# Copyright (C) 2012 Matthias Schiffer +# This file is distributed under the same license as the pylock package. +# Matthias Schiffer , 2012. +# +msgid "" +msgstr "" +"Project-Id-Version: pylock 0.1\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-02-01 19:25+0100\n" +"PO-Revision-Date: 2012-02-01 19:30+0100\n" +"Last-Translator: Matthias Schiffer \n" +"Language-Team: German \n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: unlock.ui:115 unlock.ui:113 +msgid "Unlock" +msgstr "Entsperren" + +#: unlock.ui:132 unlock.ui:129 +msgid "Logout" +msgstr "Ausloggen" + +#: LockWindow.py:69 +msgid "This computer is currently locked by the user {username}." +msgstr "Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt." + +#: LockWindow.py:73 +msgid "" +"This computer is currently locked by the user {username}.\n" +"The user can be logged out in {minutes:02}:{seconds:02} minutes." +msgstr "" +"Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt.\n" +"Der Benutzer kann in {minutes:02}:{seconds:02} Minuten ausgeloggt werden." + +#: LockWindow.py:78 +msgid "" +"This computer is currently locked by the user {username}.\n" +"The user can be logged out now." +msgstr "" +"Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt.\n" +"Der Benutzer kann jetzt ausgeloggt werden." + +#: unlock.ui:63 +msgid "Password:" +msgstr "Passwort:" diff --git a/po/pylock.pot b/po/pylock.pot new file mode 100644 index 0000000..0cb9ab8 --- /dev/null +++ b/po/pylock.pot @@ -0,0 +1,46 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-02-01 19:25+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: unlock.ui:115 unlock.ui:113 +msgid "Unlock" +msgstr "" + +#: unlock.ui:132 unlock.ui:129 +msgid "Logout" +msgstr "" + +#: LockWindow.py:69 +msgid "This computer is currently locked by the user {username}." +msgstr "" + +#: LockWindow.py:73 +msgid "" +"This computer is currently locked by the user {username}.\n" +"The user can be logged out in {minutes:02}:{seconds:02} minutes." +msgstr "" + +#: LockWindow.py:78 +msgid "" +"This computer is currently locked by the user {username}.\n" +"The user can be logged out now." +msgstr "" + +#: unlock.ui:63 +msgid "Password:" +msgstr "" diff --git a/pylock.py b/pylock.py index d42aa46..33c389f 100644 --- a/pylock.py +++ b/pylock.py @@ -4,6 +4,7 @@ import signal import sys import os import pwd +import locale from gi.repository import Gtk, Gdk @@ -18,6 +19,7 @@ def get_username(): theme = 'UzL-login' timeout = 5 +logoutTimeout = 15 username = get_username() @@ -30,10 +32,26 @@ signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGQUIT, handler) +locale.setlocale(locale.LC_ALL, '') +locale.bindtextdomain('pylock', '/home/neoraider/Devel/Python/pylock/locale') +locale.textdomain('pylock') + Gtk.Settings.get_default().set_property('gtk-theme-name', theme) + window = LockWindow() -locker = Locker(timeout, lambda: window.lock(), lambda: window.unlock()) + +def lock(timeLeft): + window.updateLockMessage(username, timeLeft) + window.lock() + +def logout(): + pass + +def updateTimeout(timeLeft): + window.updateLockMessage(username, timeLeft) + +locker = Locker(timeout, lock, window.unlock, logoutTimeout, logout, updateTimeout) pamAuth = pam.pam() @@ -42,7 +60,7 @@ def tryUnlock(w, password): locker.unlock() else: window.reset() - window.setMessage(pamAuth.reason) + window.setAuthMessage(pamAuth.reason) return True diff --git a/unlock.ui b/unlock.ui index d958485..8b33ab7 100644 --- a/unlock.ui +++ b/unlock.ui @@ -37,13 +37,10 @@ 12 12 - + True False - [hostname] - - - + [lock] True @@ -97,10 +94,11 @@ False + 0 [message] - False + True True 1 @@ -118,7 +116,6 @@ True True False - True @@ -135,7 +132,6 @@ True True False - True -- cgit v1.2.3