Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.group_list.Group_list Class Reference

List of all members.

Public Member Functions

def __init__
def reload_group
def add_group_in_model
def on_add_group_clicked
def on_remove_group_clicked
def on_cell_group_edited
def get_active_text
def on_edit_group_clicked
def group_changed_cb
def class_changed_cb

Public Attributes

 cur
 con
 current_class_id
 class_list
 current_group_id
 group_model
 combo_class
 button_add
 button_edit
 button_remove
 group_user
 group_data

Private Member Functions

def __create_model_group
def __add_columns_group

Detailed Description

GCompris Group List Table

Definition at line 44 of file group_list.py.


Constructor & Destructor Documentation

def admin.group_list.Group_list.__init__ (   self,
  frame,
  db_connect,
  db_cursor 
)

Definition at line 49 of file group_list.py.

00049 
00050   def __init__(self, frame, db_connect, db_cursor):
00051 
00052       self.cur = db_cursor
00053       self.con = db_connect
00054 
00055       # The class_id to work on
00056       self.current_class_id = 0
00057       self.class_list = []
00058 
00059       # The group_id selected
00060       self.current_group_id = 0
00061 
00062       # ---------------
00063       # Group Management
00064       # ---------------
00065 
00066       # create tree model
00067       self.group_model = self.__create_model_group()
00068 
00069       # Main box is vertical
00070       top_box = gtk.VBox(False, 8)
00071       top_box.show()
00072       frame.add(top_box)
00073 
00074       # First line label and combo
00075       label_box = gtk.HBox(False, 8)
00076       label_box.show()
00077       top_box.pack_start(label_box, False, False, 0)
00078 
00079 
00080       # Let the user select the class to work on
00081       #
00082       # Grab the class list and put it in a combo
00083       class_box = gtk.HBox(False, 8)
00084       class_box.show()
00085       label_box.pack_start(class_box, False, False, 0)
00086 
00087       class_label = gtk.Label(_('Select a class:'))
00088       class_label.show()
00089       label_box.pack_start(class_label, False, False, 0)
00090 
00091       self.cur.execute('SELECT * FROM class WHERE class_id>1 ORDER BY name')
00092       class_list = self.cur.fetchall()
00093 
00094       self.combo_class = gtk.combo_box_new_text()
00095       self.combo_class.show()
00096       for aclass in class_list:
00097         self.combo_class.append_text(aclass[1])
00098         # Save in a list the combo index => the class_id
00099         self.class_list.append(aclass[0])
00100 
00101       self.combo_class.set_active(self.current_class_id)
00102       label_box.pack_end(self.combo_class, True, True, 0)
00103 
00104       # Second line groups and button
00105       group_hbox = gtk.HBox(False, 8)
00106       group_hbox.show()
00107       top_box.add(group_hbox)
00108 
00109       grouplist_box = gtk.VBox(False, 8)
00110       grouplist_box.show()
00111       group_hbox.add(grouplist_box)
00112 
00113       vbox_button = gtk.VBox(False, 8)
00114       vbox_button.show()
00115       group_hbox.add(vbox_button)
00116 
00117 
00118       # Create the table
00119       sw = gtk.ScrolledWindow()
00120       sw.show()
00121       sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00122       sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00123 
00124       # create tree view
00125       treeview_group = gtk.TreeView(self.group_model)
00126       treeview_group.show()
00127       treeview_group.set_rules_hint(True)
00128       treeview_group.set_search_column(COLUMN_NAME)
00129 
00130       sw.add(treeview_group)
00131 
00132       grouplist_box.pack_start(sw, True, True, 0)
00133 
00134 
00135       # add columns to the tree view
00136       self.__add_columns_group(treeview_group)
00137 
00138       # Add buttons
00139       self.button_add = gtk.Button(stock='gtk-add')
00140       self.button_add.connect("clicked", self.on_add_group_clicked, self.group_model)
00141       vbox_button.pack_start(self.button_add, False, False, 0)
00142       self.button_add.show()
00143       self.button_add.set_sensitive(False)
00144 
00145       self.button_edit = gtk.Button(stock='gtk-edit')
00146       self.button_edit.connect("clicked", self.on_edit_group_clicked, treeview_group)
00147       vbox_button.pack_start(self.button_edit, False, False, 0)
00148       self.button_edit.show()
00149       self.button_edit.set_sensitive(False)
00150 
00151       self.button_remove = gtk.Button(stock='gtk-remove')
00152       self.button_remove.connect("clicked", self.on_remove_group_clicked, treeview_group)
00153       vbox_button.pack_start(self.button_remove, False, False, 0)
00154       self.button_remove.show()
00155       self.button_remove.set_sensitive(False)
00156 
00157       # User list for the group
00158       user_hbox = gtk.HBox(False, 8)
00159       user_hbox.show()
00160       top_box.add(user_hbox)
00161 
00162       self.group_user = group_user_list.Group_user_list(user_hbox,
00163                                                         self.con, self.cur,
00164                                                         self.current_group_id)
00165 
00166       # Missing callbacks
00167       self.combo_class.connect('changed', self.class_changed_cb)
00168       selection = treeview_group.get_selection()
00169       selection.connect('changed', self.group_changed_cb, self.group_user)
00170 
00171       # Load lists
00172       self.class_changed_cb(self.combo_class)
00173       self.reload_group()


Member Function Documentation

def admin.group_list.Group_list.__add_columns_group (   self,
  treeview 
) [private]

Definition at line 206 of file group_list.py.

00206 
00207   def __add_columns_group(self, treeview):
00208 
00209     model = treeview.get_model()
00210 
00211     # columns for name
00212     renderer = gtk.CellRendererText()
00213     renderer.connect("edited", self.on_cell_group_edited, model)
00214     renderer.set_data("column", COLUMN_NAME)
00215     column = gtk.TreeViewColumn(_('Group'), renderer,
00216                                 text=COLUMN_NAME)
00217     column.set_sort_column_id(COLUMN_NAME)
00218     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00219     column.set_fixed_width(constants.COLUMN_WIDTH_GROUPNAME)
00220     treeview.append_column(column)
00221 
00222     # columns for description
00223     renderer = gtk.CellRendererText()
00224     renderer.connect("edited", self.on_cell_group_edited, model)
00225     renderer.set_data("column", COLUMN_DESCRIPTION)
00226     column = gtk.TreeViewColumn(_('Description'), renderer,
00227                                 text=COLUMN_DESCRIPTION)
00228     column.set_sort_column_id(COLUMN_DESCRIPTION)
00229     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00230     column.set_fixed_width(constants.COLUMN_WIDTH_GROUPDESCRIPTION)
00231     treeview.append_column(column)
00232 

Here is the call graph for this function:

Definition at line 196 of file group_list.py.

00196 
00197   def __create_model_group(self):
00198     model = gtk.ListStore(
00199       gobject.TYPE_INT,
00200       gobject.TYPE_STRING,
00201       gobject.TYPE_STRING,
00202       gobject.TYPE_BOOLEAN)
00203 
00204     return model
00205 

def admin.group_list.Group_list.add_group_in_model (   self,
  model,
  agroup 
)

Definition at line 234 of file group_list.py.

00234 
00235   def add_group_in_model(self, model, agroup):
00236     iter = model.append()
00237     model.set (iter,
00238                COLUMN_GROUPID,          agroup[COLUMN_GROUPID],
00239                COLUMN_NAME,             agroup[COLUMN_NAME],
00240                COLUMN_DESCRIPTION,      agroup[COLUMN_DESCRIPTION]
00241                )
00242 

Here is the caller graph for this function:

def admin.group_list.Group_list.class_changed_cb (   self,
  combobox 
)

Definition at line 351 of file group_list.py.

00351 
00352   def class_changed_cb(self, combobox):
00353     active = combobox.get_active()
00354     if active < 0:
00355       self.button_edit.set_sensitive(False)
00356       self.button_remove.set_sensitive(False)
00357       self.button_add.set_sensitive(False)
00358       return
00359 
00360     self.button_add.set_sensitive(True)
00361     self.current_class_id = self.class_list[active]
00362     self.reload_group()
00363 

Here is the call graph for this function:

def admin.group_list.Group_list.get_active_text (   self,
  combobox 
)

Definition at line 294 of file group_list.py.

00294 
00295   def get_active_text(self, combobox):
00296       model = combobox.get_model()
00297       active = combobox.get_active()
00298       if active < 0:
00299         return None
00300       return model[active][0]

Here is the caller graph for this function:

def admin.group_list.Group_list.group_changed_cb (   self,
  selection,
  group_user 
)

Definition at line 327 of file group_list.py.

00327 
00328   def group_changed_cb(self, selection, group_user):
00329     model, iter = selection.get_selected()
00330 
00331     if iter:
00332       path = model.get_path(iter)[0]
00333       self.current_group_id = model.get_value(iter, COLUMN_GROUPID)
00334 
00335       group_user.reload(self.current_group_id)
00336 
00337       # Set the default button on if needed
00338 
00339       # The wholegroup is not editable
00340       wholegroup_id = constants.get_wholegroup_id(self.con,
00341                                                   self.cur,
00342                                                   self.current_class_id)
00343 
00344       if(wholegroup_id == self.current_group_id):
00345         self.button_edit.set_sensitive(False)
00346         self.button_remove.set_sensitive(False)
00347       else:
00348         self.button_edit.set_sensitive(True)
00349         self.button_remove.set_sensitive(True)
00350 

def admin.group_list.Group_list.on_add_group_clicked (   self,
  button,
  model 
)

Definition at line 244 of file group_list.py.

00244 
00245   def on_add_group_clicked(self, button, model):
00246     group_id = constants.get_next_group_id(self.con, self.cur)
00247 
00248     group_edit.GroupEdit(self.con, self.cur,
00249                          self.current_class_id, self.get_active_text(self.combo_class),
00250                          group_id, None, None,
00251                          self)
00252 

Here is the call graph for this function:

def admin.group_list.Group_list.on_cell_group_edited (   self,
  cell,
  path_string,
  new_text,
  model 
)

Definition at line 269 of file group_list.py.

00269 
00270   def on_cell_group_edited(self, cell, path_string, new_text, model):
00271 
00272     iter = model.get_iter_from_string(path_string)
00273     path = model.get_path(iter)[0]
00274     column = cell.get_data("column")
00275 
00276     group_id = model.get_value(iter, COLUMN_GROUPID)
00277 
00278     if column == COLUMN_NAME:
00279       model.set(iter, column, new_text)
00280 
00281     elif column == COLUMN_DESCRIPTION:
00282       model.set(iter, column, new_text)
00283 
00284     group_data = (group_id,
00285                   self.current_class_id,
00286                   model.get_value(iter, COLUMN_NAME),
00287                   model.get_value(iter, COLUMN_DESCRIPTION))
00288     # Save the changes in the base
00289     self.cur.execute('insert or replace into groups (group_id, class_id, name, description) values (?, ?, ?, ?)',
00290                      group_data)
00291     self.con.commit()
00292 

Here is the caller graph for this function:

def admin.group_list.Group_list.on_edit_group_clicked (   self,
  button,
  treeview 
)

Definition at line 301 of file group_list.py.

00301 
00302   def on_edit_group_clicked(self, button, treeview):
00303 
00304     selection = treeview.get_selection()
00305     model, iter = selection.get_selected()
00306 
00307     if iter:
00308       path = model.get_path(iter)[0]
00309       group_id          = model.get_value(iter, COLUMN_GROUPID)
00310       group_name        = model.get_value(iter, COLUMN_NAME)
00311       group_description = model.get_value(iter, COLUMN_DESCRIPTION)
00312       group_edit.GroupEdit(self.con, self.cur,
00313                            self.current_class_id, self.get_active_text(self.combo_class),
00314                            group_id, group_name,
00315                            group_description,
00316                            self)
00317 
00318     else:
00319       # Tell the user to select a group first
00320       dialog = gtk.MessageDialog(None,
00321                                  gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00322                                  gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00323                                  _("You must first select a group in the list"))
00324       dialog.run()
00325       dialog.destroy()
00326 

Here is the call graph for this function:

def admin.group_list.Group_list.on_remove_group_clicked (   self,
  button,
  treeview 
)

Definition at line 253 of file group_list.py.

00253 
00254   def on_remove_group_clicked(self, button, treeview):
00255 
00256     selection = treeview.get_selection()
00257     model, iter = selection.get_selected()
00258 
00259     if iter:
00260       path = model.get_path(iter)[0]
00261       group_id = model.get_value(iter, COLUMN_GROUPID)
00262       model.remove(iter)
00263       # Remove it from the base
00264       self.cur.execute('delete from groups where group_id=?', (group_id,))
00265       self.con.commit()
00266 
00267     self.group_user.clear()
00268 

Definition at line 179 of file group_list.py.

00179 
00180   def reload_group(self):
00181 
00182     # Remove all entries in the list
00183     self.group_model.clear()
00184 
00185     # Grab the group data
00186     self.cur.execute('SELECT group_id, name, description FROM groups WHERE class_id=? ORDER BY name',
00187                      (self.current_class_id,))
00188     self.group_data = self.cur.fetchall()
00189 
00190     for agroup in self.group_data:
00191       self.add_group_in_model(self.group_model, agroup)
00192 
00193     self.group_user.reload(self.current_group_id)
00194 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 138 of file group_list.py.

Definition at line 144 of file group_list.py.

Definition at line 150 of file group_list.py.

Definition at line 56 of file group_list.py.

Definition at line 93 of file group_list.py.

Definition at line 52 of file group_list.py.

Definition at line 51 of file group_list.py.

Definition at line 55 of file group_list.py.

Definition at line 59 of file group_list.py.

Definition at line 187 of file group_list.py.

Definition at line 66 of file group_list.py.

Definition at line 161 of file group_list.py.


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