Viewing file: passwordDialog.py (7.05 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
# # passwordDialog.py - GUI front end code for setting the root password # # Brent Fox <bfox@redhat.com> # # Copyright 2002, 2003 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #
import string import gtk import gobject import libuser import sys sys.path.append('/usr/share/system-config-rootpassword')
## ## I18N ## from rhpl.translate import _, N_ import rhpl.translate as translate translate.textdomain ("system-config-rootpassword")
## ## Icon for windows ##
iconPixbuf = None try: iconPixbuf = gtk.gdk.pixbuf_new_from_file("/usr/share/system-config-rootpassword/pixmaps/system-config-rootpassword.png") except: pass
class childWindow: #You must specify a runPriority for the order in which you wish your module to run runPriority = 40 moduleName = _("Root Password") moduleClass = "reconfig" commentTag = _("Change the root password for the system")
def destroy(self, args): gtk.main_quit() def __init__(self, user=None): self.admin = libuser.ADMIN() self.user = user self.doDebug = None self.mainWindow = gtk.Window() self.mainWindow.connect("destroy", self.destroy) self.mainWindow.set_position(gtk.WIN_POS_CENTER) self.mainWindow.set_icon(iconPixbuf) self.mainWindow.set_border_width(10) self.mainWindow.set_resizable(False) self.toplevel = gtk.VBox(False) self.mainVBox = gtk.VBox(False) self.iconBox = gtk.HBox() self.passwordEntry = gtk.Entry() self.passwordEntry.set_visibility(False) self.confirmEntry = gtk.Entry() self.confirmEntry.set_visibility(False)
p = None self.icon = None try: p = gtk.gdk.pixbuf_new_from_file("../pixmaps/system-config-rootpassword.png") except: try: p = gtk.gdk.pixbuf_new_from_file("/usr/share/system-config-rootpassword/pixmaps/system-config-rootpassword.png") except: print "no image found" pass
if p: self.icon = gtk.Image() self.icon.set_from_pixbuf(p)
self.title = gtk.Label(_("Root Password")) self.title.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse ("white"))
if self.user == None: #If no user was passed in, assume that we're chaning the root password self.msgLabel = gtk.Label(_("Please set the root password for the system.")) self.user = "root" else: self.msgLabel = gtk.Label(_("Please set the password for %s.") % self.user) self.msgLabel.set_line_wrap(False) self.msgLabel.set_alignment(0.0, 0.5)
self.table = gtk.Table(2, 2) label = gtk.Label(_("Root Password:")) label.set_alignment(0.0, 0.5) self.table.attach(label, 0, 1, 0, 1, gtk.FILL) self.table.attach(self.passwordEntry, 1, 2, 0, 1, gtk.SHRINK, gtk.FILL, 5, 5) label = gtk.Label(_("Confirm:")) label.set_alignment(0.0, 0.5) self.table.attach(label, 0, 1, 1, 2, gtk.FILL) self.table.attach(self.confirmEntry, 1, 2, 1, 2, gtk.SHRINK, gtk.FILL, 5, 5)
def okClicked(self, *args): result = self.apply() if result == 0: gtk.main_quit()
def apply(self, *args): passwd1 = self.passwordEntry.get_text() passwd2 = self.confirmEntry.get_text()
if self.doDebug: print "don't change root password in debug mode" return 0
if (len(passwd1) < 6) or (len(passwd2) < 6): dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, (_("Root password must be at least 6 characters in length."))) dlg.set_position(gtk.WIN_POS_CENTER) dlg.set_modal(True) dlg.set_icon(iconPixbuf) dlg.set_has_separator(False) dlg.run() dlg.destroy() self.passwordEntry.set_text("") self.confirmEntry.set_text("") self.grabFocus() return None elif passwd1 != passwd2: dlg = gtk.MessageDialog(None, 0, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK, (_("Passwords do not match. Please try again."))) dlg.set_position(gtk.WIN_POS_CENTER) dlg.set_modal(True) dlg.set_icon(iconPixbuf) dlg.set_has_separator(False) dlg.run() dlg.destroy() self.passwordEntry.set_text("") self.confirmEntry.set_text("") self.grabFocus() return None
if self.doDebug: return 0 userEnt = self.admin.lookupUserByName(self.user) self.admin.setpassUser(userEnt, passwd1, 0) return 0
def setKickstartData(self, kickstartData): print "in setKickstartData" #Get the lang from the list of languages return 0
def setKickstartDefaults(self, kickstartData): pass
def launch(self, doDebug = None): self.doDebug = doDebug
self.internalVBox = gtk.VBox(False, 10) self.internalVBox.set_border_width(10)
self.msgLabel.set_size_request(500, -1) self.internalVBox.pack_start(self.msgLabel, False) self.internalVBox.pack_start(self.table, False) self.mainVBox.pack_start(self.internalVBox, True) self.passwordEntry.grab_focus() return self.mainVBox, self.icon, self.moduleName
def grabFocus(self): self.passwordEntry.grab_focus()
def stand_alone(self): self.mainWindow.set_title(_("Root Password")) bb = gtk.HButtonBox() bb.set_layout(gtk.BUTTONBOX_END) bb.set_spacing(10) okButton = gtk.Button(stock='gtk-ok') okButton.connect("clicked", self.okClicked) cancelButton = gtk.Button(stock='gtk-cancel') cancelButton.connect("clicked", self.destroy)
if self.icon: self.iconBox.pack_start(self.icon, False) self.iconBox.pack_start(self.msgLabel, False) self.mainWindow.add(self.toplevel) self.mainVBox.set_spacing(10) self.toplevel.pack_start(self.iconBox, False) self.toplevel.pack_start(self.mainVBox, False) self.mainVBox.pack_start(self.table, False) bb.pack_start(cancelButton) bb.pack_start(okButton) self.mainVBox.pack_start(bb, False)
self.mainWindow.show_all() self.passwordEntry.grab_focus() gtk.main()
|