home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / pyshared / GdmGreeter / optionswindow.py < prev    next >
Encoding:
Python Source  |  2013-01-10  |  3.4 KB  |  95 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright 2012 Tails developers <tails@boum.org>
  4. # Copyright 2011 Max <govnototalitarizm@gmail.com>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. #  it under the terms of the GNU General Public License as published by
  8. #  the Free Software Foundation, either version 3 of the License, or
  9. #  (at your option) any later version.
  10. #
  11. #  This program is distributed in the hope that it will be useful,
  12. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #  GNU General Public License for more details.
  15. #
  16. #  You should have received a copy of the GNU General Public License
  17. #  along with this program.  If not, see <http://www.gnu.org/licenses/>
  18. #
  19. """Second screen
  20.  
  21. """
  22.  
  23. import logging, gtk, gettext, os
  24. _ = gettext.gettext
  25. import GdmGreeter
  26. from GdmGreeter.language import TranslatableWindow
  27.  
  28. class OptionsWindow(TranslatableWindow):
  29.     """Display a pre-login window"""
  30.  
  31.     def __init__(self, greeter):
  32.         self.greeter = greeter
  33.  
  34.         builder = gtk.Builder()
  35.         builder.set_translation_domain(GdmGreeter.__appname__)
  36.         builder.add_from_file(os.path.join(GdmGreeter.GLADE_DIR, "optionswindow.glade"))
  37.         builder.connect_signals(self)
  38.         self.entry_password = builder.get_object("password_entry")
  39.         self.entry_password2 = builder.get_object("password_entry2")
  40.         self.warning_label = builder.get_object("warning_label")
  41.         self.warning_area = builder.get_object("warning_area")
  42.         self.camouflage_checkbox = builder.get_object("camouflage_checkbox")
  43.  
  44.         TranslatableWindow.__init__(self, builder.get_object("options_dialog"))
  45.         self.window.set_visible(False)
  46.  
  47.         self.warning_area.hide()
  48.         self.entry_password.set_visibility(False)
  49.         self.entry_password2.set_visibility(False)
  50.  
  51.     def set_password(self):
  52.         """Set root access password"""
  53.         password = self.entry_password.get_text()
  54.         if password:
  55.             self.greeter.rootaccess.password = password
  56.  
  57.     def set_camouflage(self):
  58.         """Set camouflage theme"""
  59.         if self.camouflage_checkbox.get_active():
  60.             self.greeter.camouflage.os = 'winxp'
  61.  
  62.     def validate_options(self):
  63.         """Validate the selected options"""
  64.         auth_password = self.entry_password.get_text()
  65.         test_password = self.entry_password2.get_text()
  66.         passwords_match = test_password == auth_password
  67.         if not passwords_match:
  68.             self.warning_label.set_markup(_('<i>Passwords do not match</i>'))
  69.             self.warning_area.show()
  70.         return passwords_match
  71.  
  72.     def set_options_and_login(self):
  73.         """Activate the selected options if they are valid"""
  74.         if self.validate_options():
  75.             self.greeter.login()
  76.             self.set_password()
  77.             self.set_camouflage()
  78.  
  79.     def cb_login_clicked(self, widget, data=None):
  80.         """Login button click handler"""
  81.         self.set_options_and_login()
  82.  
  83.     def key_press_event_cb(self, widget, event=None):
  84.         """Handle key press"""
  85.         if event:
  86.             if event.keyval in [ gtk.keysyms.Return, gtk.keysyms.KP_Enter ]:
  87.                 if self.entry_password.is_focus():
  88.                     self.entry_password2.grab_focus()
  89.                 else:
  90.                     self.set_options_and_login()
  91.  
  92.     def delete_event_cb(self, widget, event=None):
  93.         """Ignore delete event (Esc)"""
  94.         return True
  95.