Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.class_list.Class_list Class Reference

List of all members.

Public Member Functions

def __init__
def add_class_in_model
def on_remove_class_clicked
def on_edit_class_clicked
def on_add_class_clicked
def class_changed_cb
def reload

Public Attributes

 cur
 con
 class_data
 treeview_class
 button_edit
 button_remove
 list_user

Private Member Functions

def __create_model_class
def __add_columns_class

Detailed Description

GCompris Class List Table

Definition at line 45 of file class_list.py.


Constructor & Destructor Documentation

def admin.class_list.Class_list.__init__ (   self,
  frame,
  db_connect,
  db_cursor 
)

Definition at line 50 of file class_list.py.

00050 
00051   def __init__(self, frame, db_connect, db_cursor):
00052 
00053       self.cur = db_cursor
00054       self.con = db_connect
00055 
00056       self.class_data = []
00057 
00058       # ---------------
00059       # Class Management
00060       # ---------------
00061 
00062       # create tree model
00063       model = self.__create_model_class()
00064 
00065       # Main box is vertical
00066       top_box = gtk.VBox(False, 8)
00067       top_box.show()
00068       frame.add(top_box)
00069 
00070       # First line
00071       group_hbox = gtk.HBox(False, 8)
00072       group_hbox.show()
00073       top_box.add(group_hbox)
00074 
00075       left_box = gtk.VBox(False, 8)
00076       left_box.show()
00077       group_hbox.add(left_box)
00078 
00079       right_box = gtk.VBox(False, 8)
00080       right_box.show()
00081       group_hbox.add(right_box)
00082 
00083 
00084       # Create the table
00085       sw = gtk.ScrolledWindow()
00086       sw.show()
00087       sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00088       sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00089 
00090       # create tree view
00091       self.treeview_class = gtk.TreeView(model)
00092       self.treeview_class.show()
00093       self.treeview_class.set_rules_hint(True)
00094       self.treeview_class.set_search_column(COLUMN_NAME)
00095 
00096       sw.add(self.treeview_class)
00097 
00098       left_box.pack_start(sw, True, True, 0)
00099 
00100       # add columns to the tree view
00101       self.__add_columns_class(self.treeview_class)
00102 
00103       # Add buttons
00104 
00105       button = gtk.Button(stock='gtk-add')
00106       button.connect("clicked", self.on_add_class_clicked, self.treeview_class)
00107       right_box.pack_start(button, False, False, 0)
00108       button.show()
00109 
00110       self.button_edit = gtk.Button(stock='gtk-edit')
00111       self.button_edit.connect("clicked", self.on_edit_class_clicked, self.treeview_class)
00112       right_box.pack_start(self.button_edit, False, False, 0)
00113       self.button_edit.show()
00114       # Not editable until one class is selected
00115       self.button_edit.set_sensitive(False)
00116 
00117       self.button_remove = gtk.Button(stock='gtk-remove')
00118       self.button_remove.connect("clicked", self.on_remove_class_clicked, self.treeview_class)
00119       right_box.pack_start(self.button_remove, False, False, 0)
00120       self.button_remove.show()
00121       # Not removable until one class is selected
00122       self.button_remove.set_sensitive(False)
00123 
00124       # User list for the group
00125       user_hbox = gtk.HBox(False, 8)
00126       user_hbox.show()
00127       top_box.add(user_hbox)
00128 
00129 
00130       self.list_user = user_list.User_list(user_hbox,
00131                                            self.con, self.cur)
00132 
00133       # Missing callbacks
00134       selection = self.treeview_class.get_selection()
00135       selection.connect('changed', self.class_changed_cb, self.list_user)
00136 


Member Function Documentation

def admin.class_list.Class_list.__add_columns_class (   self,
  treeview 
) [private]

Definition at line 161 of file class_list.py.

00161 
00162   def __add_columns_class(self, treeview):
00163     model = treeview.get_model()
00164 
00165     # Total column length must be 400
00166 
00167     # columns for name
00168     renderer = gtk.CellRendererText()
00169     renderer.set_data("column", COLUMN_NAME)
00170     column = gtk.TreeViewColumn(_('Class'), renderer,
00171                                 text=COLUMN_NAME)
00172     column.set_sort_column_id(COLUMN_NAME)
00173     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00174     column.set_fixed_width(constants.COLUMN_WIDTH_CLASSNAME)
00175     treeview.append_column(column)
00176 
00177     # columns for teacher
00178     renderer = gtk.CellRendererText()
00179     renderer.set_data("column", COLUMN_TEACHER)
00180     column = gtk.TreeViewColumn(_('Teacher'), renderer,
00181                                 text=COLUMN_TEACHER)
00182     column.set_sort_column_id(COLUMN_TEACHER)
00183     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00184     column.set_fixed_width(constants.COLUMN_WIDTH_TEACHER)
00185     treeview.append_column(column)
00186 

Definition at line 141 of file class_list.py.

00141 
00142   def __create_model_class(self):
00143     model = gtk.ListStore(
00144       gobject.TYPE_INT,
00145       gobject.TYPE_STRING,
00146       gobject.TYPE_STRING,
00147       gobject.TYPE_BOOLEAN)
00148 
00149     # Grab the class data
00150     self.cur.execute('select * from class')
00151     self.class_data = self.cur.fetchall()
00152 
00153     for item in self.class_data:
00154       iter = model.append()
00155       model.set(iter,
00156                  COLUMN_CLASSID,   item[COLUMN_CLASSID],
00157                  COLUMN_NAME,      item[COLUMN_NAME],
00158                  COLUMN_TEACHER,   item[COLUMN_TEACHER])
00159     return model
00160 

def admin.class_list.Class_list.add_class_in_model (   self,
  model,
  aclass 
)

Definition at line 188 of file class_list.py.

00188 
00189   def add_class_in_model(self, model, aclass):
00190     iter = model.append()
00191     model.set (iter,
00192                COLUMN_CLASSID,    aclass[COLUMN_CLASSID],
00193                COLUMN_NAME,       aclass[COLUMN_NAME],
00194                COLUMN_TEACHER,    aclass[COLUMN_TEACHER]
00195                )
00196 

Here is the caller graph for this function:

def admin.class_list.Class_list.class_changed_cb (   self,
  selection,
  user_list 
)

Definition at line 241 of file class_list.py.

00241 
00242   def class_changed_cb(self, selection, user_list):
00243     model, iter = selection.get_selected()
00244 
00245     if iter:
00246       path = model.get_path(iter)[0]
00247       class_id = model.get_value(iter, COLUMN_CLASSID)
00248       print "class_changed_cb %d" %class_id
00249       user_list.reload(class_id)
00250 
00251       # The Unaffected class is not editable.
00252       if class_id == 1:
00253         self.button_edit.set_sensitive(False)
00254         self.button_remove.set_sensitive(False)
00255       else:
00256         self.button_edit.set_sensitive(True)
00257         self.button_remove.set_sensitive(True)
00258 

def admin.class_list.Class_list.on_add_class_clicked (   self,
  button,
  treeview 
)

Definition at line 231 of file class_list.py.

00231 
00232   def on_add_class_clicked(self, button, treeview):
00233     model = treeview.get_model()
00234     class_id = constants.get_next_class_id(self.con, self.cur)
00235 
00236     class_edit.ClassEdit(self.con, self.cur,
00237                          class_id, "", "",
00238                          self)
00239 

def admin.class_list.Class_list.on_edit_class_clicked (   self,
  button,
  treeview 
)

Definition at line 217 of file class_list.py.

00217 
00218   def on_edit_class_clicked(self, button, treeview):
00219     selection = treeview.get_selection()
00220     model, iter = selection.get_selected()
00221 
00222     if iter:
00223       path = model.get_path(iter)[0]
00224       class_id      = model.get_value(iter, COLUMN_CLASSID)
00225       class_name    = model.get_value(iter, COLUMN_NAME)
00226       teacher_name  = model.get_value(iter, COLUMN_TEACHER)
00227       class_edit.ClassEdit(self.con, self.cur,
00228                            class_id, class_name, teacher_name,
00229                            self)
00230 

def admin.class_list.Class_list.on_remove_class_clicked (   self,
  button,
  treeview 
)

Definition at line 197 of file class_list.py.

00197 
00198   def on_remove_class_clicked(self, button, treeview):
00199     selection = treeview.get_selection()
00200     model, iter = selection.get_selected()
00201 
00202     if iter:
00203       path = model.get_path(iter)[0]
00204       class_id = model.get_value(iter, COLUMN_CLASSID)
00205       model.remove(iter)
00206 
00207       #
00208       # Remove it from the base (Triggers maintains other tables)
00209       #
00210       print "Deleting class_id=" + str(class_id)
00211       self.cur.execute('DELETE FROM class WHERE class_id=?', (class_id,))
00212       self.con.commit()
00213 
00214       print "class_list:remove_class_clicked calling reload"
00215       self.list_user.reload(class_id)
00216 

def admin.class_list.Class_list.reload (   self,
  class_id,
  class_name,
  class_teacher 
)

Definition at line 260 of file class_list.py.

00260 
00261   def reload(self, class_id, class_name, class_teacher):
00262     print ">> class_list:reload %d" %class_id
00263     print "class_name %s" %class_name
00264     # We need to find the row matching this class_id.
00265     # If not found, it's a new class to create
00266     model = self.treeview_class.get_model()
00267     iter = model.get_iter_first()
00268 
00269     updated = False
00270     # Loop over each class raw
00271     while(iter):
00272       path = model.get_path(iter)[0]
00273       tmp_class_id = model.get_value(iter, COLUMN_CLASSID)
00274 
00275       if(tmp_class_id == class_id):
00276 
00277         # Now update the class_name and class_teacher if provided
00278         if class_name:
00279           print "updating %s" %class_name
00280           print dir(class_name)
00281           model.set(iter, COLUMN_NAME, class_name)
00282 
00283         if class_teacher:
00284           model.set(iter, COLUMN_TEACHER, class_teacher)
00285 
00286         updated = True
00287         # It's updated now
00288         break
00289 
00290       iter = model.iter_next(iter)
00291 
00292 
00293 
00294     # The job not done yet, it's a new class.
00295     if(not updated):
00296       new_class = [class_id, class_name, class_teacher]
00297       self.add_class_in_model(model, new_class)
00298 
00299     # Reload the selected class
00300     selection = self.treeview_class.get_selection()
00301     if(selection):
00302       print "got selection"
00303       model, iter = selection.get_selected()
00304       if iter:
00305         path = model.get_path(iter)[0]
00306         sel_class_id = model.get_value(iter, COLUMN_CLASSID)
00307         print "got selection %d" %sel_class_id
00308         self.list_user.reload(sel_class_id)
00309 
00310     print "class_list reload DONE"
00311 

Here is the call graph for this function:


Member Data Documentation

Definition at line 109 of file class_list.py.

Definition at line 116 of file class_list.py.

Definition at line 55 of file class_list.py.

Definition at line 53 of file class_list.py.

Definition at line 52 of file class_list.py.

Definition at line 129 of file class_list.py.

Definition at line 90 of file class_list.py.


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