Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.group_edit.GroupEdit Class Reference

List of all members.

Public Member Functions

def __init__
def add_user_in_model
def add_user
def remove_user
def close
def ok

Public Attributes

 cur
 con
 group_id
 class_id
 group_user
 group_name
 new_group
 entry_group
 entry_description
 model_left
 model_right

Private Member Functions

def __create_model
def __add_columns

Detailed Description

Definition at line 41 of file group_edit.py.


Constructor & Destructor Documentation

def admin.group_edit.GroupEdit.__init__ (   self,
  db_connect,
  db_cursor,
  class_id,
  class_name,
  group_id,
  group_name,
  group_description,
  group_user 
)

Definition at line 46 of file group_edit.py.

00046 
00047                  group_user):
00048         # Create the toplevel window
00049         gtk.Window.__init__(self)
00050 
00051         self.cur = db_cursor
00052         self.con = db_connect
00053 
00054         self.group_id = group_id
00055         self.class_id = class_id
00056         
00057         # A pointer to the group_user_list class
00058         # Will be called to refresh the list when edit is done
00059         self.group_user = group_user
00060         
00061         self.set_title(_("Editing a Group"))
00062         self.set_border_width(8)
00063         self.set_default_size(320, 350)
00064 
00065         self.group_name = group_name
00066         if(self.group_name):
00067             frame = gtk.Frame(_("Editing group: ") + self.group_name +
00068                               _(" for class: ") + class_name)
00069             self.new_group = False
00070         else:
00071             frame = gtk.Frame(_("Editing a new group"))
00072             self.new_group = True
00073             self.group_name =""
00074             group_description = ""
00075 
00076 
00077         self.add(frame)
00078         
00079         # Main VBOX
00080         vbox = gtk.VBox(False, 8)
00081         vbox.set_border_width(8)
00082         frame.add(vbox)
00083 
00084         # Label and Entry for the group and description
00085         table = gtk.Table(2, 2, homogeneous=False)
00086         table.set_border_width(0)
00087         table.set_row_spacings(0)
00088         table.set_col_spacings(20)
00089         vbox.pack_start(table, True, True, 0)
00090         
00091         label = gtk.Label(_('Group:'))
00092         label.set_alignment(0, 0)
00093         table.attach(label, 0, 1, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00094         self.entry_group = gtk.Entry()
00095         self.entry_group.set_max_length(20)
00096         self.entry_group.insert_text(self.group_name, position=0)
00097         table.attach(self.entry_group, 1, 2, 0, 1,
00098                      xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00099 
00100         # FIXME: How to remove the selection
00101         
00102         # Label and Entry for the first name
00103         label = gtk.Label(_('Description:'))
00104         label.set_alignment(0, 0)
00105         table.attach(label, 0, 1, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00106         self.entry_description = gtk.Entry()
00107         self.entry_description.set_max_length(30)
00108         self.entry_description.insert_text(group_description, position=0)
00109         table.attach(self.entry_description, 1, 2, 1, 2,
00110                      xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00111 
00112 
00113         # Top message gives instructions
00114         label = gtk.Label(_('Assign all the users belonging to this group'))
00115         vbox.pack_start(label, False, False, 0)
00116         vbox.pack_start(gtk.HSeparator(), False, False, 0)
00117 
00118         # Lower area
00119         hbox = gtk.HBox(False, 8)
00120         vbox.pack_start(hbox, True, True, 0)
00121 
00122         # Left list
00123         # ---------
00124 
00125         # Create the table
00126         sw = gtk.ScrolledWindow()
00127         sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00128         sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00129 
00130         # create tree model
00131         self.model_left = self.__create_model(False, class_id, group_id)
00132 
00133         # create tree view
00134         treeview = gtk.TreeView(self.model_left)
00135         treeview.set_rules_hint(True)
00136         treeview.set_search_column(COLUMN_FIRSTNAME)
00137         treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
00138         
00139         sw.add(treeview)
00140         
00141         # add columns to the tree view
00142         self.__add_columns(treeview)
00143 
00144         hbox.pack_start(sw, True, True, 0)
00145 
00146 
00147         # Middle Button
00148         # -------------
00149         vbox2 = gtk.VBox(False, 8)
00150         vbox2.set_border_width(8)
00151         hbox.pack_start(vbox2, True, True, 0)
00152 
00153         button = gtk.Button(stock='gtk-add')
00154         button.connect("clicked", self.add_user, treeview)
00155         vbox2.pack_start(button, False, False, 0)
00156         button.show()
00157 
00158         button_delete = gtk.Button(stock='gtk-remove')
00159         vbox2.pack_start(button_delete, False, False, 0)
00160         button_delete.show()
00161 
00162 
00163         # Right List
00164         # ----------
00165 
00166         # Create the table
00167         sw2 = gtk.ScrolledWindow()
00168         sw2.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00169         sw2.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00170 
00171         # create tree model
00172         self.model_right = self.__create_model(True, class_id, group_id)
00173 
00174         # create tree view
00175         treeview2 = gtk.TreeView(self.model_right)
00176         treeview2.set_rules_hint(True)
00177         treeview2.set_search_column(COLUMN_FIRSTNAME)
00178         treeview2.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
00179 
00180         sw2.add(treeview2)
00181         
00182         # add columns to the tree view
00183         self.__add_columns(treeview2)
00184 
00185         hbox.pack_start(sw2, True, True, 0)
00186 
00187         # Confirmation Buttons
00188         # --------------------
00189         vbox.pack_start(gtk.HSeparator(), False, False, 0)
00190 
00191         bbox = gtk.HBox(homogeneous=False, spacing=8)
00192         
00193         button = gtk.Button(stock='gtk-help')
00194         bbox.pack_start(button, expand=False, fill=False, padding=0)
00195 
00196         button = gtk.Button(stock='gtk-ok')
00197         bbox.pack_end(button, expand=False, fill=False, padding=0)
00198         button.connect("clicked", self.ok)
00199 
00200         button = gtk.Button(stock='gtk-close')
00201         bbox.pack_end(button, expand=False, fill=False, padding=0)
00202         button.connect("clicked", self.close)
00203 
00204         vbox.pack_start(bbox, False, False, 0)
00205 
00206 
00207         # Missing callbacks
00208         button_delete.connect("clicked", self.remove_user, treeview2)
00209 
00210         # Ready GO
00211         self.show_all()
00212 


Member Function Documentation

def admin.group_edit.GroupEdit.__add_columns (   self,
  treeview 
) [private]

Definition at line 258 of file group_edit.py.

00258 
00259     def __add_columns(self, treeview):
00260 
00261         model = treeview.get_model()
00262         
00263         # columns for first name
00264         renderer = gtk.CellRendererText()
00265         renderer.set_data("column", COLUMN_FIRSTNAME)
00266         column = gtk.TreeViewColumn(_('First Name'), renderer,
00267                                     text=COLUMN_FIRSTNAME,
00268                                     editable=COLUMN_USER_EDITABLE)
00269         column.set_sort_column_id(COLUMN_FIRSTNAME)
00270         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00271         column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
00272         treeview.append_column(column)
00273 
00274         # column for last name
00275         renderer = gtk.CellRendererText()
00276         renderer.set_data("column", COLUMN_LASTNAME)
00277         column = gtk.TreeViewColumn(_('Last Name'), renderer,
00278                                     text=COLUMN_LASTNAME,
00279                                     editable=COLUMN_USER_EDITABLE)
00280         column.set_sort_column_id(COLUMN_LASTNAME)
00281         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00282         column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
00283         treeview.append_column(column)
00284 

def admin.group_edit.GroupEdit.__create_model (   self,
  with,
  class_id,
  group_id 
) [private]

Definition at line 231 of file group_edit.py.

00231 
00232     def __create_model(self, with, class_id, group_id):
00233 
00234         model = gtk.ListStore(
00235             gobject.TYPE_INT,
00236             gobject.TYPE_STRING,
00237             gobject.TYPE_STRING,
00238             gobject.TYPE_BOOLEAN)
00239 
00240         # Grab the all the users from this class
00241         self.cur.execute('SELECT user_id,firstname,lastname FROM users WHERE class_id=? ORDER BY login', (class_id,))
00242         user_data = self.cur.fetchall()
00243 
00244         for user in user_data:
00245 
00246             # Check our user is already in the group
00247             self.cur.execute('SELECT * FROM list_users_in_groups WHERE group_id=? AND user_id=?',
00248                              (group_id, user[0]))
00249             user_is_already = self.cur.fetchall()
00250             
00251             if(with and user_is_already):
00252                 self.add_user_in_model(model, user)
00253             elif(not with and not user_is_already):
00254                 self.add_user_in_model(model, user)
00255 
00256 
00257         return model

Here is the call graph for this function:

def admin.group_edit.GroupEdit.add_user (   self,
  button,
  treeview 
)

Definition at line 287 of file group_edit.py.

00287 
00288     def add_user(self, button, treeview):
00289 
00290         model = treeview.get_model()
00291         
00292         treestore, paths = treeview.get_selection().get_selected_rows()
00293         
00294         paths.reverse()
00295         
00296         for path in paths:
00297             
00298             iter = treestore.get_iter(path)
00299             
00300             path = model.get_path(iter)[0]
00301             user_id        = model.get_value(iter, COLUMN_USERID)
00302             user_firstname = model.get_value(iter, COLUMN_FIRSTNAME)
00303             user_lastname  = model.get_value(iter, COLUMN_LASTNAME)
00304             model.remove(iter)
00305 
00306             # Add in the the right view
00307             self.add_user_in_model(self.model_right, (user_id, user_firstname, user_lastname))
00308             
00309             # Save the change in the base
00310             self.cur.execute('INSERT OR REPLACE INTO list_users_in_groups (group_id, user_id) VALUES (?, ?)',
00311                              (self.group_id, user_id))
00312             self.con.commit()
00313 

Here is the call graph for this function:

def admin.group_edit.GroupEdit.add_user_in_model (   self,
  model,
  user 
)

Definition at line 218 of file group_edit.py.

00218 
00219     def add_user_in_model(self, model, user):
00220         iter = model.append()
00221         model.set (iter,
00222                    COLUMN_USERID,    user[COLUMN_USERID],
00223                    COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
00224                    COLUMN_LASTNAME,  user[COLUMN_LASTNAME],
00225                    COLUMN_USER_EDITABLE,  False
00226                    )

Here is the caller graph for this function:

def admin.group_edit.GroupEdit.close (   self,
  button 
)

Definition at line 346 of file group_edit.py.

00346 
00347     def close(self, button):
00348         self.group_user.reload_group()
00349         self.destroy()
        

Here is the call graph for this function:

def admin.group_edit.GroupEdit.ok (   self,
  button 
)

Definition at line 352 of file group_edit.py.

00352 
00353     def ok(self, button):
00354 
00355         # Tell the user he must provide enough information
00356         if(self.entry_group.get_text() == ""):
00357             dialog = gtk.MessageDialog(None,
00358                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00359                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00360                                        _("You need to provide at least a name for your group"))
00361             dialog.run()
00362             dialog.destroy()
00363             return
00364 
00365         # If the group name as changed, check it does not exists already
00366         if(self.entry_group.get_text() != self.group_name):
00367             # Check the group does not exist already
00368             self.cur.execute('SELECT name FROM groups WHERE name=?',
00369                              (self.entry_group.get_text(),))
00370             if(self.cur.fetchone()):
00371                 dialog = gtk.MessageDialog(None,
00372                                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00373                                            gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00374                                            _("There is already a group with this name"))
00375                 dialog.run()
00376                 dialog.destroy()
00377                 return
00378 
00379         #
00380         # Now everything is correct, create the group
00381         #
00382 
00383         group_data = (self.group_id,
00384                       self.entry_group.get_text(),
00385                       self.class_id,
00386                       self.entry_description.get_text()
00387                       )
00388 
00389         if(self.new_group):
00390             # Create the new group
00391             group_id = constants.get_next_group_id(self.con, self.cur)
00392             self.cur.execute('INSERT INTO groups (group_id, name, class_id, description) ' +
00393                              'VALUES ( ?, ?, ?, ?)',
00394                              (group_data));
00395         else:
00396             # Save the group changes
00397             self.cur.execute('UPDATE groups SET name=?, description=? where group_id=?',
00398                              (self.entry_group.get_text(),
00399                               self.entry_description.get_text(),
00400                               self.group_id));
00401         self.con.commit()
00402 
00403         # Close the dialog window now
00404         self.group_user.reload_group()
00405 
00406         self.destroy()
00407 

Here is the call graph for this function:

def admin.group_edit.GroupEdit.remove_user (   self,
  button,
  treeview 
)

Definition at line 316 of file group_edit.py.

00316 
00317     def remove_user(self, button, treeview):
00318 
00319         model = treeview.get_model()
00320         
00321         treestore, paths = treeview.get_selection().get_selected_rows()
00322         
00323         paths.reverse()
00324         
00325         for path in paths:
00326             
00327             iter = treestore.get_iter(path)
00328             
00329             path = model.get_path(iter)[0]
00330             user_id        = model.get_value(iter, COLUMN_USERID)
00331             user_firstname = model.get_value(iter, COLUMN_FIRSTNAME)
00332             user_lastname  = model.get_value(iter, COLUMN_LASTNAME)
00333             model.remove(iter)
00334 
00335             # Add in the the left view
00336             self.add_user_in_model(self.model_left, (user_id, user_firstname, user_lastname))
00337             
00338             # Save the change in the base
00339             self.cur.execute('delete from list_users_in_groups where group_id=? and user_id=?',
00340                              (self.group_id, user_id))
00341             self.con.commit()
00342 
00343 

Here is the call graph for this function:


Member Data Documentation

Definition at line 54 of file group_edit.py.

Definition at line 51 of file group_edit.py.

Definition at line 50 of file group_edit.py.

Definition at line 105 of file group_edit.py.

Definition at line 93 of file group_edit.py.

Definition at line 53 of file group_edit.py.

Definition at line 64 of file group_edit.py.

Definition at line 58 of file group_edit.py.

Definition at line 130 of file group_edit.py.

Definition at line 171 of file group_edit.py.

Definition at line 68 of file group_edit.py.


The documentation for this class was generated from the following file: