Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.class_edit.ClassEdit 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
def create_class

Public Attributes

 cur
 con
 class_id
 class_name
 teacher_name
 list_class
 new_class
 entry_class
 entry_teacher
 model_left
 model_right

Private Member Functions

def __create_model
def __add_columns

Detailed Description

Definition at line 41 of file class_edit.py.


Constructor & Destructor Documentation

def admin.class_edit.ClassEdit.__init__ (   self,
  db_connect,
  db_cursor,
  class_id,
  class_name,
  teacher_name,
  list_class 
)

Definition at line 45 of file class_edit.py.

00045 
00046                  list_class):
00047         # Create the toplevel window
00048         gtk.Window.__init__(self)
00049 
00050         self.cur = db_cursor
00051         self.con = db_connect
00052 
00053         self.class_id = class_id
00054         self.class_name = class_name
00055         self.teacher_name = teacher_name
00056         
00057         # A pointer to the user_list class
00058         # Will be called to refresh the list when edit is done
00059         self.list_class = list_class
00060         
00061         self.set_title(_("Editing a Class"))
00062         self.set_border_width(8)
00063         self.set_default_size(320, 350)
00064 
00065         if(self.class_name):
00066             frame = gtk.Frame(_("Editing class: ") + self.class_name)
00067             self.new_class = False
00068         else:
00069             frame = gtk.Frame(_("Editing a new class"))
00070             self.new_class = True
00071             
00072         # Connect the "destroy" event to close
00073         # FIXME: This makes the close code beeing called twice
00074         #        because the close destroy also call close again.
00075         frame.connect("destroy", self.close)
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 class name
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(_('Class:'))
00092         label.set_alignment(0, 0)
00093         table.attach(label, 0, 1, 0, 1, xoptions=gtk.SHRINK,
00094                      yoptions=gtk.EXPAND)
00095         self.entry_class = gtk.Entry()
00096         self.entry_class.set_max_length(20)
00097         self.entry_class.insert_text(self.class_name, position=0)
00098         table.attach(self.entry_class, 1, 2, 0, 1,
00099                      xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00100 
00101         # FIXME: How to remove the default selection
00102         
00103         # Label and Entry for the teacher name
00104         label = gtk.Label(_('Teacher:'))
00105         label.set_alignment(0, 0)
00106         table.attach(label, 0, 1, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00107         self.entry_teacher = gtk.Entry()
00108         self.entry_teacher.set_max_length(30)
00109         self.entry_teacher.insert_text(self.teacher_name, position=0)
00110         table.attach(self.entry_teacher, 1, 2, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
00111 
00112         # Top message gives instructions
00113         vbox.pack_start(gtk.HSeparator(), False, False, 0)
00114         label = gtk.Label(_('Assign all the users belonging to this class'))
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)
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_add = gtk.Button(stock='gtk-add')
00154         button_add.connect("clicked", self.add_user, treeview)
00155         vbox2.pack_start(button_add, False, False, 0)
00156 
00157         button_delete = gtk.Button(stock='gtk-remove')
00158         vbox2.pack_start(button_delete, False, False, 0)
00159 
00160         # Right List
00161         # ----------
00162 
00163         # Create the table
00164         sw2 = gtk.ScrolledWindow()
00165         sw2.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00166         sw2.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00167 
00168         # create tree model
00169         self.model_right = self.__create_model(True, class_id)
00170 
00171         # create tree view
00172         treeview2 = gtk.TreeView(self.model_right)
00173         treeview2.set_rules_hint(True)
00174         treeview2.set_search_column(COLUMN_FIRSTNAME)
00175         treeview2.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
00176 
00177         sw2.add(treeview2)
00178         
00179         # add columns to the tree view
00180         self.__add_columns(treeview2)
00181 
00182         hbox.pack_start(sw2, True, True, 0)
00183 
00184         # Confirmation Buttons
00185         # --------------------
00186         vbox.pack_start(gtk.HSeparator(), False, False, 0)
00187 
00188         bbox = gtk.HBox(homogeneous=False, spacing=8)
00189         
00190         button = gtk.Button(stock='gtk-help')
00191         bbox.pack_start(button, expand=False, fill=False, padding=0)
00192 
00193         button = gtk.Button(stock='gtk-ok')
00194         bbox.pack_end(button, expand=False, fill=False, padding=0)
00195         button.connect("clicked", self.ok)
00196 
00197         button = gtk.Button(stock='gtk-close')
00198         bbox.pack_end(button, expand=False, fill=False, padding=0)
00199         button.connect("clicked", self.close)
00200 
00201         vbox.pack_start(bbox, False, False, 0)
00202         
00203         # Missing callbacks
00204         button_delete.connect("clicked", self.remove_user, treeview2)
00205 
00206         # Ready GO
00207         self.show_all()
00208 


Member Function Documentation

def admin.class_edit.ClassEdit.__add_columns (   self,
  treeview 
) [private]

Definition at line 246 of file class_edit.py.

00246 
00247     def __add_columns(self, treeview):
00248 
00249         model = treeview.get_model()
00250 
00251         # columns for first name
00252         renderer = gtk.CellRendererText()
00253         renderer.set_data("column", COLUMN_FIRSTNAME)
00254         column = gtk.TreeViewColumn(_('First Name'), renderer,
00255                                     text=COLUMN_FIRSTNAME,
00256                                     editable=COLUMN_USER_EDITABLE)
00257         column.set_sort_column_id(COLUMN_FIRSTNAME)
00258         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00259         column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
00260         treeview.append_column(column)
00261 
00262         # column for last name
00263         renderer = gtk.CellRendererText()
00264         renderer.set_data("column", COLUMN_LASTNAME)
00265         column = gtk.TreeViewColumn(_('Last Name'), renderer,
00266                                     text=COLUMN_LASTNAME,
00267                                     editable=COLUMN_USER_EDITABLE)
00268         column.set_sort_column_id(COLUMN_LASTNAME)
00269         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00270         column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
00271         treeview.append_column(column)
00272 

def admin.class_edit.ClassEdit.__create_model (   self,
  with,
  class_id 
) [private]

Definition at line 226 of file class_edit.py.

00226 
00227     def __create_model(self, with, class_id):
00228 
00229         # Grab the user data
00230         if(with):
00231             self.cur.execute('SELECT user_id,firstname,lastname FROM users where class_id=? ORDER BY login', (class_id,))
00232         else:
00233             self.cur.execute('SELECT user_id,firstname,lastname FROM users WHERE class_id!=? ORDER BY login', (class_id,))
00234         user_data = self.cur.fetchall()
00235 
00236         model = gtk.ListStore(
00237             gobject.TYPE_INT,
00238             gobject.TYPE_STRING,
00239             gobject.TYPE_STRING,
00240             gobject.TYPE_BOOLEAN)
00241 
00242         for user in user_data:
00243             self.add_user_in_model(model, user)
00244 
00245         return model

Here is the call graph for this function:

def admin.class_edit.ClassEdit.add_user (   self,
  button,
  treeview 
)

Definition at line 275 of file class_edit.py.

00275 
00276     def add_user(self, button, treeview):
00277         model = treeview.get_model()
00278         treestore, paths = treeview.get_selection().get_selected_rows()
00279         paths.reverse()
00280 
00281         if(len(paths)>0 and self.new_class):
00282             self.create_class()
00283 
00284         for path in paths:
00285             iter = treestore.get_iter(path)
00286             path = model.get_path(iter)[0]
00287             user_id        = model.get_value(iter, COLUMN_USERID)
00288             user_firstname = model.get_value(iter, COLUMN_FIRSTNAME)
00289             user_lastname  = model.get_value(iter, COLUMN_LASTNAME)
00290             model.remove(iter)
00291 
00292             # Add in the the right view
00293             self.add_user_in_model(self.model_right, (user_id, user_firstname, user_lastname))
00294             
00295             # Save the change in the base
00296             self.cur.execute('UPDATE users SET class_id=? WHERE user_id=?',
00297                              (self.class_id, user_id))
00298             self.con.commit()
00299             print "UPDATE users SET class_id=%d" %self.class_id

Here is the call graph for this function:

def admin.class_edit.ClassEdit.add_user_in_model (   self,
  model,
  user 
)

Definition at line 214 of file class_edit.py.

00214 
00215     def add_user_in_model(self, model, user):
00216         iter = model.append()
00217         model.set (iter,
00218                    COLUMN_USERID,    user[COLUMN_USERID],
00219                    COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
00220                    COLUMN_LASTNAME,  user[COLUMN_LASTNAME],
00221                    COLUMN_USER_EDITABLE,  False
00222                    )

Here is the caller graph for this function:

def admin.class_edit.ClassEdit.close (   self,
  button 
)

Definition at line 325 of file class_edit.py.

00325 
00326     def close(self, button):
00327 
00328         self.list_class.reload(self.class_id,
00329                                self.class_name,
00330                                self.teacher_name)
00331         self.destroy()
        

Here is the call graph for this function:

Definition at line 378 of file class_edit.py.

00378 
00379     def create_class(self):
00380                 
00381         # Check the login do not exist already
00382         self.cur.execute('SELECT name FROM class WHERE name=?',
00383                          (self.entry_class.get_text(),))
00384         if(self.cur.fetchone()):
00385             dialog = gtk.MessageDialog(None,
00386                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00387                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00388                                        _("There is already a class with this name"))
00389             dialog.run()
00390             dialog.destroy()
00391             return
00392 
00393         # Create its Whole group
00394         group_id = constants.get_next_group_id(self.con, self.cur)
00395         self.cur.execute('INSERT INTO groups (group_id, name, class_id, description) ' +
00396                          'VALUES ( ?, "All", ?, "All users")',
00397                          (group_id, self.class_id));
00398 
00399         class_data = (self.class_id,
00400                       self.entry_class.get_text(),
00401                       self.entry_teacher.get_text(),
00402                       group_id
00403                       )
00404 
00405         self.cur.execute('INSERT OR REPLACE INTO class (class_id, name, teacher, wholegroup_id) ' +
00406                          'values (?, ?, ?, ?)', class_data)
00407 
00408         # No more need to create this class, it's done
00409         self.new_class = False

Here is the caller graph for this function:

def admin.class_edit.ClassEdit.ok (   self,
  button 
)

Definition at line 334 of file class_edit.py.

00334 
00335     def ok(self, button):
00336 
00337         # Tell the user he must provide enough information
00338         if(self.entry_class.get_text() == ""):
00339             dialog = gtk.MessageDialog(None,
00340                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00341                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00342                                        _("You need to provide at least a name for your class"))
00343             dialog.run()
00344             dialog.destroy()
00345             return
00346 
00347         #
00348         # Now everything is correct, create the class
00349         #
00350 
00351         class_data = (self.class_id,
00352                       self.entry_class.get_text(),
00353                       self.entry_teacher.get_text()
00354                       )
00355 
00356         if(self.new_class):
00357             self.create_class()
00358 
00359         # Save the changes in the base
00360         self.cur.execute('UPDATE class set name=?,teacher=? where class_id=?',
00361                          (self.entry_class.get_text(),
00362                           self.entry_teacher.get_text(),
00363                           self.class_id));
00364         self.con.commit()
00365 
00366         # Close the dialog window now
00367         # (The close code will refresh the class_list)
00368         self.class_name   = self.entry_class.get_text()
00369         self.teacher_name = self.entry_teacher.get_text()
00370 
00371         print "class_edit done"
00372         self.destroy()
00373 

Here is the call graph for this function:

def admin.class_edit.ClassEdit.remove_user (   self,
  button,
  treeview 
)

Definition at line 302 of file class_edit.py.

00302 
00303     def remove_user(self, button, treeview):
00304         model = treeview.get_model()
00305         treestore, paths = treeview.get_selection().get_selected_rows()
00306         paths.reverse()
00307         
00308         for path in paths:
00309             iter = treestore.get_iter(path)
00310             path = model.get_path(iter)[0]
00311             user_id        = model.get_value(iter, COLUMN_USERID)
00312             user_firstname = model.get_value(iter, COLUMN_FIRSTNAME)
00313             user_lastname  = model.get_value(iter, COLUMN_LASTNAME)
00314             model.remove(iter)
00315 
00316             # Add in the the left view
00317             self.add_user_in_model(self.model_left, (user_id, user_firstname, user_lastname))
00318             
00319             # Save the change in the base (1 Is the 'Unselected user' class)
00320             self.cur.execute('UPDATE users SET class_id=? where user_id=?', (1, user_id))
00321             self.con.commit()
00322             print "UPDATE users SET class_id=1"

Here is the call graph for this function:


Member Data Documentation

Definition at line 52 of file class_edit.py.

Definition at line 53 of file class_edit.py.

Definition at line 50 of file class_edit.py.

Definition at line 49 of file class_edit.py.

Definition at line 94 of file class_edit.py.

Definition at line 106 of file class_edit.py.

Definition at line 58 of file class_edit.py.

Definition at line 130 of file class_edit.py.

Definition at line 168 of file class_edit.py.

Definition at line 66 of file class_edit.py.

Definition at line 54 of file class_edit.py.


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