Commits

Anonymous committed b6158f1

adjusting user_add window so that it can be used for new and existing accounts

  • Participants
  • Parent commits 692cbe5

Comments (0)

Files changed (5)

File user_add/user_add.py

     available. These will be all set to None on a new account, or will
     default to the stored values on an existing account.
     '''
-    def __init__(self):
+    def __init__(self, new = True):
+        self.is_new = new
         self.name = None
         self.homedir = None
         self.uid = None
         self.shell = None
+        self.pass1 = None
+        self.pass2 = None
         self.password = None
         self.maingroup = None
         self.groups = []

File user_add/user_add.pyc

Binary file modified.

File user_add/user_add.py~

-#!/usr/bin/env python
-
-#    This file is part of controlcenter.
-#
-#    controlcenter is free software: you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License v2 as published by
-#    the Free Software Foundation.
-#
-#    controlcenter 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 controlcenter.  If not, see <http://www.gnu.org/licenses/>.
-
-
-__author__ = 'Moises Henriquez'
-__author_email__ = 'moc.liamg]ta[xnl.E0M'.replace(']ta[', '@')[::-1]
-
-import gtk
-import os
-
-def __init__(self):
-        
-    n_account = None
-    tabs_ = []
-    g_btOK = None
-
-def _(str): return str
-
-class Account(object):
-    '''Object for a user account. This object will have several properties
-    available. These will be all set to None on a new account, or will
-    default to the stored values on an existing account.
-    '''
-    def __init__(self):
-        self.name = None
-        self.homedir = None
-        self.uid = None
-        self.shell = None
-        self.password = None
-        self.maingroup = None
-        self.groups = []
-        self.login = None
-    
-    def preview(self):
-        '''Prints out the information stored about the user account. This 
-        information will reflect any changes that have been made and is 
-        for mere testing purposes, to make sure all required fields are 
-        filled'''
-        print _('Login Name:'), self.login
-        print _('User Name:'), self.name
-        print _('User ID:'), self.uid
-        print _('Home Directory:'), self.homedir
-        print _('Login Shell:'), self.shell
-        print _('Main Group:'), self.maingroup
-        print _('Groups List:'), ','.join(self.groups)
-        print _('Password: ****** '), 
-        
-    
-    def load(self, login):
-        '''Load the information stored in the system about a user account.
-        Required arguments:
-            login = String representing a valid user name in the system.
-        '''
-        passfile = '/etc/passwd'
-        groupfile = '/etc/group'
-        self.login = login
-        f = open(passfile, 'r')
-        passinfo = f.readlines()
-        f.close()
-        for line in passinfo:
-            if line.startswith(login):
-                spl = line.split(':')
-                uid = spl[2]
-                gid = spl[3]
-                rname = spl[4]
-                homedir = spl[5]
-                shell = spl[6]
-        self.uid = uid
-        self.name = rname
-        self.homedir = homedir
-        self.shell = shell
-        return
-    
-
-
-class MainWin(gtk.Window):
-    '''Main window for user add module
-    Arguments:
-        account:    An Account object. Defaults to None for a new account.'''
-    def __init__(self, account = None):
-        print account
-        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
-        if account: n_account = account
-        self.connect('destroy', gtk.main_quit)
-        self.set_property('title', _('Create User Account'))
-        body = gtk.VBox()
-        self.add(body)
-        self.tabstrip = gtk.Notebook()
-        btnbar = gtk.HBox()
-        
-        body.pack_start(self.tabstrip, True, True, 4)
-        body.pack_start(btnbar, False, False, 4)
-        
-        bt_OK = gtk.Button(_('OK'), gtk.STOCK_OK)
-        bt_OK.connect('clicked', self.preview_account)
-        self.OK = bt_OK
-        bt_Cancel = gtk.Button(_('Cancel'), gtk.STOCK_CANCEL)
-        bt_Cancel.connect('clicked', gtk.main_quit)
-        
-        btnbar.pack_end(bt_OK, False, False, 2)
-        btnbar.pack_end(bt_Cancel, False, False, 2)
-
-        self.set_default_size(400,450)
-        self.set_position(gtk.WIN_POS_CENTER)
-        
-        ## Create tab objects.
-        tab_basic= BasicSettingsTab()
-        tab_privileges = PrivilegesTab()
-        tab_advanced = AdvancedTab()
-        tabs_.append(tab_basic)
-        tabs_.append(tab_privileges)
-        tabs_.append(tab_advanced)
-        
-        ## Add the tabs to the window
-        for tab in tabs_:
-            self.tabstrip.append_page(tab, tab.label)
-    def preview_account(self, widget):
-        '''Trigger account preview'''
-        return n_account.preview()
-        
-    
-    def load_account(self, account):
-        self.n_account.load(account)
-        
-        
-        
-class Tab(gtk.VBox):
-    '''Abstract class for a tab in the user add module 
-    Required Arguments:
-        title:  Title to be used for this tab
-                Title is available after creating the object
-                via tab.label and is returned as a gtk.Label'''
-    def __init__(self, title):
-        gtk.VBox.__init__(self)
-        self.label = gtk.Label(title)
-        
-    def refresh_info(self):
-        ''' This method can be called to refresh the information displayed
-        in this tab. Information is read from the account object'''
-        pass
-    
-    def load_existing_data(self):
-        '''This method will read the data for an existing user account
-        and display it on the tabstrip. This will allow the same tabstrip to be
-        used when creating a new account as well as when editing an existing account'''
-        pass
-
-class SectionLabel(gtk.Label):
-    '''Pre-set widget based on gtk.Label preformatted to be used as a
-    section banner within tabs'''
-    def __init__(self, text):
-        gtk.Label.__init__(self)
-        self.set_property('use-markup', True)
-        self.set_property('label', '<b>%s</b>'% text)
-        self.set_property('xalign', 0.0)
-        self.set_property('xpad', 12)
-        
-class LineLabel(gtk.Label):
-    '''Pre-set widget based on gtk.Label pre-formatted to be used as a 
-    label in instances where a label is needed before another widget'''
-    def __init__(self, text):
-        gtk.Label.__init__(self)
-        self.set_property('use-markup', True)
-        self.set_property('label', text)
-        self.set_property('xalign', 0.0)
-        self.set_property('width-chars', 13)    ## Fixme: Fixed width for these?
-        
-
-class BasicSettingsTab(Tab):
-    '''Tab displaying the basic settings for the user add module'''
-    def load_existing_data(self):
-        '''Loads the existing data about the user account to the appropriate widgets'''
-        self.login_txt.set_text(n_account.login)
-        self.login_txt.set_sensitive(False)
-        self.name_txt.set_text(n_account.name)
-        return
-    
-    def update_login(self, widget):
-        '''Update login name field for user account'''
-        n_account.login = widget.get_text().strip() ## FIXME: strip this??
-        ## Also update the home directory
-        n_account.homedir = os.path.join('/home', n_account.login)
-        
-        ## Display this value on the advanced tab
-        for tab in tabs_:
-            tab.refresh_info()
-    
-    def update_realname(self, widget):
-        '''Update the real name field for user account'''
-        n_account.name = widget.get_text().strip()  ## FIXME: strip this??
-    def set_pass_1(self, widget):
-        '''Set the first password entry for user account'''
-        n_account.password = widget.get_text()
-        
-    def verify_password(self, pass2):
-        ''' Make sure both password entires match'''
-        if pass2 == n_account.password:
-            return True
-        return False
-    def set_pass_2(self, widget):
-        '''Set the second password for the user account. Just to make sure'''
-        if g_btOK:
-            g_btOK.set_sensitive(self.verify_password(widget.get_text()))
-        else:
-            print 'no OK button'
-            
-        
-    def __init__(self):
-        Tab.__init__(self, _('Basic Settings'))
-        banner = SectionLabel(_('Basic Information'))
-        self.pack_start(banner, False, False, 4)
-        
-        spacer = gtk.Label()
-        self.pack_start(spacer, False, False, 4)
-        line_name = gtk.HBox()
-        login_label = LineLabel(_('Login Name'))
-        login_txtbox = gtk.Entry()
-        login_txtbox.connect('changed', self.update_login)
-        self.login_txt = login_txtbox
-        line_name.pack_start(login_label, False, False, 2)
-        line_name.pack_start(login_txtbox, True, True, 2)
-        self.pack_start(line_name, False, False, 4)
-        
-        rname_box = gtk.HBox()
-        rname_label = LineLabel(_('Real Name'))
-        rname_txt = gtk.Entry()
-        rname_txt.connect('changed', self.update_realname)
-        self.name_txt = rname_txt
-        rname_box.pack_start(rname_label, False, False, 2)
-        rname_box.pack_start(rname_txt, True, True, 2)
-        self.pack_start(rname_box, False, False, 4)
-        
-        spacer = gtk.Label()
-        self.pack_start(spacer, False, False, 4)
-        
-        banner1 = SectionLabel(_('Password'))
-        self.pack_start(banner1, False, False, 4)
-        pass1_box = gtk.HBox()
-        pass2_box = gtk.HBox()
-        pass1_label = LineLabel(_('User Password'))
-        pass1_txt = gtk.Entry()
-        pass1_txt.connect('changed', self.set_pass_1)
-        self.pass1_box = pass1_txt
-        pass1_txt.set_property('visibility', False)
-        pass1_box.pack_start(pass1_label, False, False, 2)
-        pass1_box.pack_start(pass1_txt, True, True, 2)
-        
-        pass2_label = LineLabel(_('Confirm Password'))
-        pass2_txt = gtk.Entry()
-        pass2_txt.connect('changed', self.set_pass_2)
-        self.pass2_box = pass2_txt
-        pass2_txt.set_property('visibility', False)
-        pass2_box.pack_start(pass2_label, False, False, 2)
-        pass2_box.pack_start(pass2_txt, True, True, 2)
-        
-        self.pack_start(pass1_box, False, False, 4)
-        self.pack_start(pass2_box, False, False, 4)
-    
-
-class PrivilegesTab(Tab):
-    '''User privileges tab that allows the administrator to pick and choose what
-    the user is allowed to do on the system'''
-    def __init__(self):
-        Tab.__init__(self, _('Privileges'))
-        banner = SectionLabel(_('User Privileges'))
-        self.pack_start(banner, False, False, 4)
-        self.rights_values = [
-        ('lpadmin', True,  _('Manage system printers')), \
-        ('scaner', False, _('Use scanners')), \
-        ('video', True, _('Capture video from TV or webcam'))
-        ]
-        
-        ## set default grouplist
-        for entry in self.rights_values:
-            if entry[1]:
-                n_account.groups.append(entry[0])
-        
-        sw = gtk.ScrolledWindow()
-        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
-        tv = self._get_tree()
-        sw.add(tv)
-        self.pack_start(sw, True, True, 4)
-    
-    def _get_tree(self):
-        '''Internal function that pvides a treeview with a list of
-        checkbuttons to check off user access'''
-        rights = self.rights_values
-        store = gtk.ListStore(str, bool, str)
-        for right in rights:
-            store.append([right[0], right[1], right[2]])
-        
-        tree = gtk.TreeView(store)
-        cell0 = gtk.CellRendererToggle()
-        cell0.set_property('activatable', True)
-        cell0.connect('toggled', self.checkbox_toggle, tree.get_model())
-        col0 = gtk.TreeViewColumn(None, cell0)
-        col0.add_attribute(cell0, 'active', 1)
-        
-        cell1 = gtk.CellRendererText()
-        col1 = gtk.TreeViewColumn(None, cell1, text=2)
-        tree.append_column(col0)
-        tree.append_column(col1)
-        
-        return tree
-    
-    def checkbox_toggle(self, widget, path, model):
-        model[path][1] = not model[path][1]
-        for item in model:
-            if item[1]:
-                if not item[0] in n_account.groups:
-                    n_account.groups.append(item[0].strip())
-            else:
-                if item[0] in n_account.groups:
-                    n_account.groups.remove(item[0].strip())
-                
-        print n_account.groups
-
-
-class AdvancedTab(Tab):
-    '''Advanced settings tab.
-    This tab will provide advanced settings for creating a user account.
-    These settings are optional and default to the system defaults.
-    '''
-    
-    def refresh_info(self):
-        '''Reflect changes made to the home directory especially from the
-        basic settings tab.'''
-        self.homedir_box.set_text(n_account.homedir)
-        
-    def load_existing_data(self):
-        self.homedir_box.set_text(n_account.homedir)
-        self.homedir_box.set_sensitive(False)
-        self.uid_spinner.set_value(float(n_account.uid))
-        self.uid_spinner.set_sensitive(False)
-        model = self.shell_sel_combo.get_model()
-        n = 0
-        for item in model:
-            n += 1
-        for x in range(0, n):
-            if model[x][0].strip() == n_account.shell.strip():
-                #print 'found %s in combobox. Setting as active'% n_account.shell.strip()
-                self.shell_sel_combo.set_active(x)
-                self.shell_sel_combo.set_sensitive(False) ## Fixme: Disabled for now
-                break
-    
-    def update_homedir(self, widget):
-        '''Update the home directory on the account to the value specified in the
-        advanced tab'''
-        n_account.homedir = widget.get_text()
-    
-    def update_maingroup(self, widget):
-        '''Update the user's main group to the value selected from the
-        advanced tab'''
-        n_account.maingroup = widget.get_active_text()
-    
-    def update_shell(self, widget):
-        '''Update the user's login shell to the value selected from the
-        advanced tab'''
-        n_account.shell = widget.get_active_text()
-    
-    def update_uid(self, widget):
-        '''Update the uid value to the value selected from the advanced tab'''
-        n_account.uid = int(widget.get_value())
-        
-        
-
-    def __init__(self):
-        Tab.__init__(self, _('Advanced'))
-        banner = SectionLabel(_('Advanced Settings'))
-        spacer = gtk.Label()
-        self.pack_start(banner, False, False, 4)
-        self.pack_start(spacer, False, False, 4)
-        
-        homedir_line = gtk.HBox()
-        homedir_label = LineLabel(_('Home Directory'))
-        homedir_txt = gtk.Entry()
-        homedir_txt.connect('changed', self.update_homedir)
-        self.homedir_box = homedir_txt
-        homedir_line.pack_start(homedir_label, False, False, 2)
-        homedir_line.pack_start(homedir_txt, True, True, 2)
-        self.pack_start(homedir_line, False, False, 4)
-        
-        maingroup_line = gtk.HBox()
-        maingroup_label = LineLabel(_('Main Group'))
-        ulist = gtk.ListStore(str)
-        ## Read /etc/group and list all groups =< 100  <-- FIXME:
-        f = open('/etc/group', 'r')
-        glist = f.readlines()
-        f.close()
-        ulist.append(['Default (username)']) ## Defaults to user name
-        for line in glist:
-            spl = line.split(':')
-            if int(spl[2]) > 0 and int(spl[2]) <= 100:
-                ulist.append([spl[0].strip()])
-        ## FIXME: ^^ User group policy?
-        maingroup_sel = gtk.ComboBox(ulist)
-        maingroup_sel.connect('changed', self.update_maingroup)
-        self.main_group_combo = maingroup_sel
-        cell0 = gtk.CellRendererText()
-        maingroup_sel.pack_start(cell0, True)
-        maingroup_sel.add_attribute(cell0, 'text', 0)
-        maingroup_sel.set_active(0)
-        maingroup_line.pack_start(maingroup_label, False, False, 2)
-        maingroup_line.pack_start(maingroup_sel, True, True, 2)
-        self.pack_start(maingroup_line, False, False, 4)
-        
-        shell_line = gtk.HBox()
-        shell_label = LineLabel('Login Shell')
-        shell_list = gtk.ListStore(str)
-        shell_sel = gtk.ComboBox(shell_list)
-        shell_sel.connect('changed', self.update_shell)
-
-        self.shell_sel_combo = shell_sel
-        
-        ## Read /etc/shells if it exists to get the default shells available
-        if os.path.exists('/etc/shells'):
-            f = open('/etc/shells', 'r')
-            shells = f.readlines()
-            f.close()
-            for shell in shells:
-                shell_list.append([shell.strip()])
-        elif os.path.exists('/bin/bash'):
-            ## if /etc/shells doesn't exist, but /bin/bash does
-            shell_list.append(['/bin/bash'])
-        else:
-            ## No shells available???
-            shell_sel.set_sensitive(False)
-        cell = gtk.CellRendererText()
-        shell_sel.pack_start(cell, True)
-        shell_sel.add_attribute(cell, 'text', 0)
-        
-        shell_sel.set_active(0)
-        
-        shell_line.pack_start(shell_label, False, False, 2)
-        shell_line.pack_start(shell_sel, True, True, 2)
-        self.pack_start(shell_line, False, False, 4)
-        
-        uid_line = gtk.HBox()
-        uid_label = LineLabel(_('User ID'))
-        min_ = 1000
-        n_list = []
-        f = open('/etc/passwd', 'r')
-        entries = f.readlines()
-        f.close()
-        for line in entries:
-            spl = line.split(':')
-            if int(spl[2]) >= 1000:
-                n_list.append(int(spl[2]))
-        n_list.sort()
-        min_ = max(n_list)+1
-        ## Set default value to the user account
-        n_account.uid = int(min_)
-        adj = gtk.Adjustment(1000, min_, 10000, 1, 10, 0)
-        uid_spinner = gtk.SpinButton(adj, 0, 0)
-        uid_spinner.connect('value-changed', self.update_uid)
-        self.uid_spinner = uid_spinner
-        uid_line.pack_start(uid_label, False, False, 2)
-        uid_line.pack_start(uid_spinner, True, True, 2)
-        self.pack_start(uid_line, False, False, 4)
-    
-if __name__ == '__main__':
-    n_account = Account()
-    w = MainWin()
-    g_btOK = w.OK
-    g_btOK.set_sensitive(False) ## Disable the OK button until the password is provided
-    w.show_all()
-    gtk.main()

File user_add/user_mod.py

 __author_email__ = 'moc.liamg]ta[xnl.E0M'.replace(']ta[', '@')[::-1]
 
 import gtk
+import os
 from user_add import Account as Account
 from user_add import Tab as Tab
 from user_add import SectionLabel as SectionLabel
 from user_add import LineLabel as LineLabel
 
+__tabs__ = []
+
 def _(str): return str
+
 class Win(gtk.Window):
     '''User add/edit window
         Arguments:
             account:    An Account object representing the account to be edited'''
     def __init__(self, account = None):
-        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        #gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        gtk.Window.__init__(self)
+        self.set_position(gtk.WIN_POS_CENTER)
+        self.set_default_size(400, 350)
         self.account = account
         if not self.account: self.account = Account()
-        body = gtk.VBox()
+        body = gtk.VBox()   
+        
+        #if not __tabs__:
+
         self.add(body)
         self.notebook = gtk.Notebook()
         body.pack_start(self.notebook, True, True, 2)
-        self.load_basic_information()
-        self.load_privilege_information()
+
+        basic = BasicInfo(account = self.account)
+        privilege = PrivilegeInfo(account = self.account)
+        advanced = AdvancedInfo(account = self.account)
+        __tabs__.append(basic)
+        __tabs__.append(privilege)
+        __tabs__.append(advanced)
         
-    def load_basic_information(self):
-        tab = BasicInfo(account = self.account)
-        self.notebook.append_page(tab, tab.label)
-    def load_privilege_information(self):
-        tab = PrivilegeInfo(account = self.account)
-        self.notebook.append_page(tab, tab.label)
+        for tab in __tabs__:
+            self.notebook.append_page(tab, tab.label)
+
+    ## Bottom toolbar
+        toolbar = gtk.HBox()
+        btCancel = gtk.Button('Cancel', gtk.STOCK_CANCEL)
+        btCancel.connect('clicked', self._do_exit)
+        btOK = gtk.Button('OK', gtk.STOCK_OK)
         
-class PrivilegeInfo(Tab):
+        toolbar.pack_end(btOK, False, False, 4)
+        toolbar.pack_end(btCancel, False, False, 4)
+        body.pack_start(toolbar, False, False, 4)
+
     
+    def _do_exit(self, widget=None):
+        #print self.notebook.get_n_pages()
+        self.hide()
+        
+            
+
+class AdvancedInfo(Tab):
+    def __init__(self, account = None):
+        self.account = account
+        Tab.__init__(self, _('Advanced'))
+        banner = SectionLabel(_('Advanced Options'))
+        self.pack_start(banner, False, False, 4)
+        spacer = gtk.Label()
+        self.pack_start(spacer, False, False, 4)
+        
+        line_homedir = gtk.HBox()
+        homedir_label = LineLabel(_('Home Directory'))
+        homedir_txt = gtk.Entry()
+        self._homedir_entry = homedir_txt
+        homedir_txt.connect('changed', self.set_account_homedir)
+        if not account.is_new: homedir_txt.set_text(self.account.homedir)
+        homedir_txt.set_property('sensitive', self.account.is_new)
+        line_homedir.pack_start(homedir_label, False, False, 2)
+        line_homedir.pack_start(homedir_txt, True, True, 2)
+        self.pack_start(line_homedir, False, False, 4)
+        maingroup = self._show_maingroup_line()
+        self.pack_start(maingroup, False, False, 4)
+        shell_line = self._show_shell_line()
+        self.pack_start(shell_line, False, False, 4)
+        uid_line = self._show_uid_spinner()
+        self.pack_start(uid_line, False, False, 4)
+    
+    def _show_maingroup_line(self):
+        line = gtk.HBox()
+        label = LineLabel(_('Main Group'))
+        line.pack_start(label, False, False, 2)
+        f = open('/etc/group', 'r')
+        data = f.readlines()
+        f.close()
+        
+        if not self.account.is_new:
+            ## Just look for the main group in /etc/group
+            for item in data:
+                if item.startswith(self.account.login):
+                    maingroup = self.account.login
+            drop = gtk.combo_box_entry_new_text()
+            drop.append_text(maingroup)
+            drop.connect('changed', self.set_account_maingroup)
+            drop.set_active(0)
+            drop.set_property('sensitive', self.account.is_new)
+        else:
+            ulist = gtk.ListStore(str)
+            ulist.append(['Default (username)']) ## Defaults to user name
+            for item in data:
+                spl = item.split(':')
+                if int(spl[2]) > 0 and int(spl[2]) <= 100:
+                    ulist.append([spl[0].strip()])
+                ## Fixme ^^ User group policy???
+                drop = gtk.ComboBox(ulist)
+                cell0 = gtk.CellRendererText()
+                drop.pack_start(cell0, True)
+                drop.add_attribute(cell0, 'text', 0)
+                drop.set_active(0)
+                drop.set_property('sensitive', self.account.is_new)                   
+            
+        line.pack_start(drop, True, True, 2)
+        return line
+
+    def _show_shell_line(self):
+        section = gtk.HBox()
+        label = LineLabel(_('Login Shell'))
+        section.pack_start(label, False, False, 2)
+        no_etc_shells = None
+        if os.path.exists('/etc/shells'):
+            f = open('/etc/shells', 'r')
+            data = f.readlines()
+            f.close()
+        else:
+            no_etc_shells = True
+        
+        shell_list = gtk.ListStore(str)
+        if no_etc_shells is True:
+            if os.path.exists('/bin/bash'):
+                shell_list.append(['/bin/bash'])
+            else:
+                ## FIXME: No shells? what here?
+                pass
+        else:
+            for line in data:
+                shell_list.append([line.strip()])
+        
+        drop = gtk.ComboBox(shell_list)
+        cell0 = gtk.CellRendererText()
+        drop.connect('changed', self.set_account_shell)
+        drop.pack_start(cell0, True)
+        drop.add_attribute(cell0, 'text', 0)
+        
+        if self.account.is_new:
+            drop.set_active(0)
+        else:
+            # Find the shell from /etc/passwd and pre-select it here
+            x = open('/etc/passwd', 'r')
+            udata = x.readlines()
+            x.close()
+            for line in udata:
+                if line.startswith(self.account.login):
+                    ushell = line.split(':')[-1]
+            
+            n = 0
+            model = drop.get_model()
+            for item in model:
+                n += 1
+            for x in range(0, n):
+                if model[x][0].strip() == self.account.shell.strip():
+                    drop.set_active(x)
+                    break
+            
+    
+        drop.set_property('sensitive', True)
+        section.pack_start(drop, True, True, 2)
+        
+        return section
+
+    def _show_uid_spinner(self):
+        section = gtk.HBox()
+        
+        label = LineLabel(_('User ID'))
+        section.pack_start(label, False, False, 2)
+        
+        f = open('/etc/passwd', 'r')
+        data = f.readlines()
+        f.close()
+        min_ = 1000
+        n_list = []
+        
+        for line in data:
+            spl = line.split(':')
+            if int(spl[2]) >= 1000:
+                n_list.append(int(spl[2]))
+        n_list.sort()
+        min_ = max(n_list) + 1
+        
+        adj = gtk.Adjustment(1000, min_, 10000, 1, 10, 0)
+        spinner = gtk.SpinButton(adj, 0, 0)
+        spinner.connect('value-changed', self.set_account_uid)
+        if not self.account.is_new:
+            ## find the uid for the existing user and pre-select it
+            if self.account.login == 'root':
+                adj.set_all(0,0,10000,1,10,0)
+                spinner.set_value(0.0)
+                spinner.set_property('sensitive', False)
+            else:
+                for line in data:
+                    if line.startswith(self.account.login):
+                        spl1 = line.split(':')
+                        uid = int(spl[2])
+                        spinner.set_value(uid)
+                        spinner.set_property('sensitive', False) ## Disable this for existing accounts.
+                        break
+            
+        section.pack_start(spinner, True, True, 2)
+        
+        return section
+    def set_account_homedir(self, widget):
+        self.account.homedir = widget.get_text()
+    def set_account_shell(self, widget):
+        self.account.shell = widget.get_active_text()
+    def set_account_maingroup(self, widget):
+        self.account.maingroup = widget.get_active_text()
+    def set_account_uid(self, widget):
+        self.account.uid = int(widget.get_value())
+    def refresh_info(self):
+        self._homedir_entry.set_text(self.account.homedir)
+    
+        
+class PrivilegeInfo(Tab):  
+ 
     def __init__(self, account = None):
         Tab.__init__(self, _('Account Privileges'))
         banner = SectionLabel(_('User Privileges'))
         self.pack_start(banner, False, False, 2)
+        self.account = account
+        if self.account.is_new:
+            self.rights_values = self._get_grouplist_with_default_values()
+        else:
+            self.rights_values = self._get_user_group_list()
+        ## set default grouplist
+        for entry in self.rights_values:
+            if entry[1]:
+                self.account.groups.append(entry[0])
         
+        sw = gtk.ScrolledWindow()
+        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        tv = self._get_tree()
+        sw.add(tv)
+        self.pack_start(sw, True, True, 4)
+    
         
+    def _get_user_group_list(self):
+        defaults = self._get_grouplist_with_default_values()
+        new = []
+        f = open('/etc/group', 'r')
+        data = f.readlines()
+        f.close()
+        grplist = []
+        for item in defaults:
+            member = False # Unless we find out differently later
+            if item[0] == 'users': pass
+            if item[0] == self.account.login: pass
+            for line in data:
+                if line.startswith(item[0]):
+                    member = self.account.login in line
+                    
+            new.append([item[0], member, item[2]])
+        return new
+        
+
+    def _get_grouplist_with_default_values(self):
+        values = [
+        ('disk', True, _('Access system storage devices')), \
+        ('lp', True,  _('Manage system printers')), \
+        ('floppy', True, _('Use Floppy drive')), \
+        ('audio', True, _('Use audio devices')), \
+        ('video', True, _('Capture video from TV or webcam')), \
+        ('scanner', True, _('Use scanners')), \
+        ('cdrom', True, _('Use CD/DVD-ROM devices')), \
+        ('games', True, _('Play games')), \
+        ('slocate', True, _('Find files on the system')), \
+        ('plugdev', True, _('Use external storage devices')), \
+        ('power', True, _('Suspend and hibernate the system')), \
+        ('netdev', True, _('Modify system network connections'))        
+        ]
+        return values
+    def _get_tree(self):
+        '''Internal function that pvides a treeview with a list of
+        checkbuttons to check off user access'''
+        rights = self.rights_values
+        store = gtk.ListStore(str, bool, str)
+        for right in rights:
+            store.append([right[0], right[1], right[2]])
+        
+        tree = gtk.TreeView(store)
+        cell0 = gtk.CellRendererToggle()
+        cell0.set_property('activatable', True)
+        cell0.connect('toggled', self.checkbox_toggle, tree.get_model())
+        col0 = gtk.TreeViewColumn(None, cell0)
+        col0.add_attribute(cell0, 'active', 1)
+        
+        cell1 = gtk.CellRendererText()
+        col1 = gtk.TreeViewColumn(None, cell1, text=2)
+        tree.append_column(col0)
+        tree.append_column(col1)
+        
+        return tree
+
+    def checkbox_toggle(self, widget, path, model):
+        model[path][1] = not model[path][1]
+        for item in model:
+            if item[1]:
+                if not item[0] in self.account.groups:
+                    self.account.groups.append(item[0].strip())
+            else:
+                if item[0] in self.account.groups:
+                    self.account.groups.remove(item[0].strip())
+                
+        print self.account.groups
+
 
 class BasicInfo(Tab):
     def __init__(self, account = None):
         line_login = gtk.HBox()
         login_label = LineLabel(_('Login Name'))
         login_txt = gtk.Entry()
-        login_txt.set_property('sensitive', False)
-        login_txt.set_text(self.account.login)
+        login_txt.connect('changed', self.set_login_name)
+        login_txt.set_property('sensitive', self.account.is_new)
+        if not account.is_new: login_txt.set_text(self.account.login)
         line_login.pack_start(login_label, False, False, 2)
         line_login.pack_start(login_txt, True, True, 2)
         self.pack_start(line_login, False, False, 4)
         line_name = gtk.HBox()
         name_label = LineLabel(_('Real Name'))
         name_txt = gtk.Entry()
-        name_txt.set_text(self.account.name)
+        name_txt.connect('changed', self.set_user_real_name)
+        if not account.is_new: name_txt.set_text(self.account.name)
         
         self.pack_start(line_name, False, False, 4)
         line_name.pack_start(name_label, False, False, 2)
         spacer = gtk.Label()
         self.pack_start(spacer, False, False, 4)
         
-        pass_sec = SectionLabel(_('Change Password'))
+        if self.account.is_new:
+            ptxt = _('User Password')
+        else:
+            ptxt = _('Change Password')
+        pass_sec = SectionLabel(ptxt)
         self.pack_start(pass_sec, False, False, 4)
         
         line_pass1 = gtk.HBox()
         pass1_label = LineLabel(_('Enter Password'))
         pass1_txt = gtk.Entry()
         pass1_txt.set_property('visibility', False)
+        pass1_txt.connect('changed', self.pass1_change)
         line_pass1.pack_start(pass1_label, False, False, 2)
         line_pass1.pack_start(pass1_txt, True, True, 2)
         self.pack_start(line_pass1, False, False, 4)
         pass2_label = LineLabel(_('Verify Password'))
         pass2_txt = gtk.Entry()
         pass2_txt.set_property('visibility', False)
+        pass2_txt.connect('changed', self.pass2_change)
         line_pass2.pack_start(pass2_label, False, False, 2)
         line_pass2.pack_start(pass2_txt, True, True, 2)
         self.pack_start(line_pass2, False, False, 4)
+    def pass1_change(self, widget):
+        self.account.pass1 = widget.get_text()
+        if self.account.pass1 == self.account.pass2: 
+            self.account.password = self.account.pass1
+        else:
+            self.account.password = None
+    def pass2_change(self, widget):
+        self.account.pass2 = widget.get_text()
+        if self.account.pass1 == self.account.pass2:
+            self.account.password = self.account.pass1
+        else:
+            self.account.password = None
+    def set_login_name(self, widget):
+        ''' Set the login name on the account'''
+        self.account.login = widget.get_text()
+        ## Set the home dir too
+        self.account.homedir = os.path.join('/home', self.account.login)
+        ## Update the advanced tab
+        for tab in __tabs__:
+            tab.refresh_info()
+    def set_user_real_name(self, widget):
+        ''' Set the comment or real name on the account '''
+        self.account.name = widget.get_text()
         
         
         

File user_add/users_manage.py

 import user_mod
 
 def _(str): return str
+
+
 class Win(gtk.Window):
     '''Main users management window'''
     def __init__(self):
         pane.pack_start(sw, True, True, 2)
         right = gtk.VBox()
         bt_add = gtk.Button(_('Add User'))
+        bt_add.connect('clicked', self.add_user)
         img1 = gtk.Image()
         img1.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
         bt_add.set_image(img1)
         right.pack_start(btHelp, False, False, 4)
         right.pack_start(btClose, False, False, 4)
 
-        
-        
         pane.pack_start(right, False, False, 4)
         
         self.statusbar = gtk.Statusbar()
         self.body.pack_start(self.statusbar, False, False, 2)
         self.statusbar.push(0, _('Welcome to controlcenter'))
         
+        self.__modwin = None
+        
     def edit_user(self, widget):
         ''' Show properties for selected user from the treeview'''
         
         if not self._selected_user: return
         
-        sel_user = user_add.Account()
+        sel_user = user_add.Account(new = False)
         sel_user.load(self._selected_user)
-        propw = user_mod.Win(account = sel_user)
+        if not self.__modwin: self.__modwin = user_mod.Win(sel_user)
+        
+        self.__modwin = user_mod.Win(sel_user)
+        self.__modwin.set_title(sel_user.login + ' '+ _('Account Properties'))
+        self.__modwin.show_all()
+        #propw = user_mod.Win(account = sel_user)
         #propw = user_add.MainWin(account=sel_user)
-        propw.set_modal(True)
-        propw.show_all()
+        #propw.set_modal(True)
+        #propw.set_default_size(350, 450)
+        #propw.set_title(sel_user.login + ' ' +  _('Account Properties'))
+        #propw.show_all()
         
     def _get_user_lists(self):
         '''Returns a list of 3-tuples containing (user real name, login, homedir)'''
         sel_row = widget.get_cursor()[0][0]
         #print sel_row
         self._selected_user = widget.get_model()[sel_row][1]
+
+    def add_user(self, widget):
+        ''' Launch the add user dialog.'''
+        acct = user_add.Account(new = True)
+        if not self.__modwin: self.__modwin = user_mod.Win(acct)
+        self.__modwin.set_title(_('Add new user'))
+        self.__modwin.show_all()
+