Commits

Anonymous committed 692cbe5

Adding more widgets and modules

Comments (0)

Files changed (9)

 
 import gtk
 from widgets import message
+from widgets import guiwidgets
 
 
 __author__ = 'Moises Henriquez'
 
 def _(str): return str
 
+class ModFrame(gtk.Frame):
+    '''A preset frame widget to be used for all module sets'''
+    def __init__(self, label):
+        gtk.Frame.__init__(self, label)
+    
+
 class Gui(gtk.Window):
     '''Main GUI interface for the controlcenter.
     This window will incorporate modules and launch them using
         self.set_title(_('Control Center'))
         self.set_position(gtk.WIN_POS_CENTER)
         self.connect('destroy', gtk.main_quit)
+        body = gtk.VBox()
+        self.add(body)
+        users = guiwidgets.ModuleSection(label = _('Users'))
+        bt1 = gtk.Button('OK')
+        users.body.pack_start(bt1, False, False, 2)
+        body.pack_start(users, False, False, 2)
+        syst = guiwidgets.ModuleSection( label = _('System'))
+        bt2 = gtk.Button('System')
+        syst.body.pack_start(bt2, False, False, 2)
+        body.pack_start(syst, False, False, 2)
+
 
     
 if __name__ == '__main__':

user_add/user_add.py

         self.shell = shell
         return
     
-
+if n_account is None: n_account = Account()
 
 class MainWin(gtk.Window):
-    '''Main window for user add module'''
-    def __init__(self):
+    '''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()

user_add/user_add.pyc

Binary file modified.

user_add/user_add.py~

 import gtk
 import os
 
-n_account = None
-tabs_ = []
-g_btOK = None
+def __init__(self):
+        
+    n_account = None
+    tabs_ = []
+    g_btOK = None
 
 def _(str): return str
 
 
 
 class MainWin(gtk.Window):
-    '''Main window for user add module'''
-    def __init__(self):
+    '''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()

user_add/user_mod.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
+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
+
+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)
+        self.account = account
+        if not self.account: self.account = Account()
+        body = gtk.VBox()
+        self.add(body)
+        self.notebook = gtk.Notebook()
+        body.pack_start(self.notebook, True, True, 2)
+        self.load_basic_information()
+        self.load_privilege_information()
+        
+    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)
+        
+class PrivilegeInfo(Tab):
+    
+    def __init__(self, account = None):
+        Tab.__init__(self, _('Account Privileges'))
+        banner = SectionLabel(_('User Privileges'))
+        self.pack_start(banner, False, False, 2)
+        
+        
+
+class BasicInfo(Tab):
+    def __init__(self, account = None):
+        self.account = account
+        Tab.__init__(self, _('Basic Information'))
+        banner = SectionLabel(_('Basic Information'))
+        self.pack_start(banner, False, False, 4)
+        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)
+        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)
+        
+        self.pack_start(line_name, False, False, 4)
+        line_name.pack_start(name_label, False, False, 2)
+        line_name.pack_start(name_txt, True, True, 2)
+        
+        spacer = gtk.Label()
+        self.pack_start(spacer, False, False, 4)
+        
+        pass_sec = SectionLabel(_('Change Password'))
+        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)
+        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)
+        
+        line_pass2 = gtk.HBox()
+        pass2_label = LineLabel(_('Verify Password'))
+        pass2_txt = gtk.Entry()
+        pass2_txt.set_property('visibility', False)
+        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)
+        
+        
+        
+        

user_add/users_manage.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 user_add
+import user_mod
+
+def _(str): return str
+class Win(gtk.Window):
+    '''Main users management window'''
+    def __init__(self):
+        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
+        self.set_title(_('User accounts'))
+        self.connect('destroy', gtk.main_quit)
+        self.set_position(gtk.WIN_POS_CENTER)
+        self.set_default_size(500, 300)
+        self.body = gtk.VBox()
+        self.add(self.body)
+        pane = gtk.HBox()
+
+        self.body.pack_start(pane, True, True, 2)
+        sw = gtk.ScrolledWindow()
+        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+        
+        tree = self._get_tree()
+        sw.add(tree)
+        pane.pack_start(sw, True, True, 2)
+        right = gtk.VBox()
+        bt_add = gtk.Button(_('Add User'))
+        img1 = gtk.Image()
+        img1.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
+        bt_add.set_image(img1)
+        
+        bt_delete = gtk.Button(_('Delete User'))
+        img2 = gtk.Image()
+        img2.set_from_stock(gtk.STOCK_DELETE, gtk.ICON_SIZE_BUTTON)
+        bt_delete.set_image(img2)
+        
+        bt_properties = gtk.Button(_('Properties'))
+        bt_properties.connect('clicked', self.edit_user)
+        img3 = gtk.Image()
+        img3.set_from_stock(gtk.STOCK_PROPERTIES, gtk.ICON_SIZE_BUTTON)
+        bt_properties.set_image(img3)
+
+        spacer = gtk.Label()
+        
+        btHelp = gtk.Button(_('Help'), gtk.STOCK_HELP)
+        btClose = gtk.Button(_('Close'), gtk.STOCK_CLOSE)
+        btClose.connect('clicked', gtk.main_quit)
+
+        right.pack_start(bt_add, False, False, 4)
+        right.pack_start(bt_delete, False, False, 4)
+        right.pack_start(bt_properties, False, False, 4)
+        right.pack_start(spacer, True, True, 4)
+        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'))
+        
+    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.load(self._selected_user)
+        propw = user_mod.Win(account = sel_user)
+        #propw = user_add.MainWin(account=sel_user)
+        propw.set_modal(True)
+        propw.show_all()
+        
+    def _get_user_lists(self):
+        '''Returns a list of 3-tuples containing (user real name, login, homedir)'''
+        ret = []
+        f = open('/etc/passwd', 'r')
+        data = f.readlines()
+        f.close()
+        
+        for line in data:
+            spl = line.split(':')
+            if int(spl[2]) == 0 or int(spl[2]) >= 1000:
+                ret.append((spl[4], spl[0], spl[-2]))
+        return ret
+    def _get_tree(self):
+        lst = gtk.ListStore(str, str, str)
+        users = self._get_user_lists()
+        for user in users:
+            lst.append([user[0],user[1], user[2]])
+        cell = gtk.CellRendererText()
+        self.tree = gtk.TreeView(lst)
+        
+        col0 = gtk.TreeViewColumn(_('Name'), cell)
+        col0.add_attribute(cell, 'text', 0)
+        
+        col1 = gtk.TreeViewColumn(_('Login'), cell)
+        col1.add_attribute(cell, 'text', 1)
+        
+        col2 = gtk.TreeViewColumn(_('Home Directory'), cell)
+        col2.add_attribute(cell, 'text', 2)
+        
+        self.tree.append_column(col0)
+        self.tree.append_column(col1)
+        self.tree.append_column(col2)
+        
+        self.tree.connect('cursor-changed', self.tree_select)
+        #self.tree.connect('row-activated', self.tree_select)
+        return self.tree
+    def tree_select(self, widget):
+        sel_row = widget.get_cursor()[0][0]
+        #print sel_row
+        self._selected_user = widget.get_model()[sel_row][1]
+        
+        
+
+if __name__ == '__main__':
+    w = Win()
+    w.show_all()
+    gtk.main()

widgets/guiwidgets.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
+
+def _(str): return str
+
+class ModuleSection(gtk.Frame):
+    '''Container to be used as a module section holder. This will hold several
+    ModuleIcon objects.
+    Required Arguments:
+        label:  A text string that will be used to identify the module section'''
+    def __init__(self, label):
+        gtk.Frame.__init__(self, label)
+        self.body = gtk.HBox()
+        self.add(self.body)
+        
+        
+class ModuleIcon(gtk.VBox):
+    '''Pre-set launcher to be used in the controlcenter main gui to launch
+    a perticular module.
+    Retured arguments:
+        label :  Text to be displayed
+        icon  :  Icon to display (can be a gtk.ICON constant or icon name or path)
+        target:  The target module this launcher executes
+    '''
+    def __init__(self, label, icon, target):
+        gtk.VBox.__init__(self)
+        img = gtk.Image()
+        if icon.startswith('gtk-'):
+            img.set_from_stock(icon, gtk.ICON_SIZE_DIALOG)
+        elif '.' in icon:
+            img.set_from_icon_name(icon, gtk.ICON_SIZE_DIALOG)
+        elif '/' in icon:
+            img.set_from_file(icon)
+        self.pack_start(img, False, False, 2)
+        label = gtk.Label(label)
+        self.pack_start(label, False, False, 2)

widgets/message.py

 #
 #    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
 
 def _(str): return str
 
 class Error(gtk.MessageDialog):
+    '''Pre-set gtk message dialog to display an error message'''
     def __init__(self, parent=None, text=None):
         gtk.MessageDialog.__init__(self, type=gtk.MESSAGE_ERROR, parent=parent,
         buttons = gtk.BUTTONS_OK)
         self.set_property('title', _('Error'))
     
 class Warning(gtk.MessageDialog):
+    '''Pre-set gtk dialog to display a warning message'''
     def __init__(self, parent=None, text=None):
         gtk.MessageDialog.__init__(self, type=gtk.MESSAGE_WARNING, parent=parent,
         buttons=gtk.BUTTONS_OK)
         self.set_property('title', _('Warning'))
         
 class Info(gtk.MessageDialog):
+    '''Pre-set gtk dialog to display an informational message'''
     def __init__(self, parent=None, text=None):
         gtk.MessageDialog.__init____(self, type=gtk.MESSAGE_INFO, parent=parent,
         buttons = gtk.BUTTONS_OK)
         self.set_property('text', text)
 
 class Question(gtk.MessageDialog):
+    '''Preset gtk message dialog to display a question to the user and get
+    their response via a gtk.RESPONSE constant. Response is either 
+    gtk.RESPONSE_OK or gtk.RESPONSE_CANCEL'''
     def __init__(self, parent=None, text=None):
         gtk.MessageDialog.__init__(self, type=gtk.MESSAGE_QUESTION, parent=parent,
         buttons=gtk.BUTTONS_YES_NO)
         self.set_property('title', _('Question'))
         self.set_property('text', text)
-
-
-
-
-if __name__ == '__main__':
-    box = Question(text='Questiiion')
-    if box.run():
-        box.hide()
-          
-        
+  

widgets/message.pyc

Binary file modified.