Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes | Private Member Functions
admin.profile_edit.ProfileEdit Class Reference

List of all members.

Public Member Functions

def __init__
def add_group_in_model
def add_group
def remove_group
def close
def ok

Public Attributes

 cur
 con
 profile_id
 profile_list
 new_profile
 entry_profile
 entry_description
 model_left
 model_right

Private Member Functions

def __create_model
def __add_columns

Detailed Description

Definition at line 41 of file profile_edit.py.


Constructor & Destructor Documentation

def admin.profile_edit.ProfileEdit.__init__ (   self,
  db_connect,
  db_cursor,
  profile_id,
  profile_name,
  profile_description,
  profile_list 
)

Definition at line 45 of file profile_edit.py.

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


Member Function Documentation

def admin.profile_edit.ProfileEdit.__add_columns (   self,
  treeview 
) [private]

Definition at line 262 of file profile_edit.py.

00262 
00263     def __add_columns(self, treeview):
00264 
00265         model = treeview.get_model()
00266         
00267         # columns for class name
00268         renderer = gtk.CellRendererText()
00269         renderer.set_data("column", COLUMN_CLASSNAME)
00270         column = gtk.TreeViewColumn(_('Class'), renderer,
00271                                     text=COLUMN_CLASSNAME)
00272         column.set_sort_column_id(COLUMN_CLASSNAME)
00273         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00274         column.set_fixed_width(constants.COLUMN_WIDTH_CLASSNAME)
00275         treeview.append_column(column)
00276 
00277         # columns for group name
00278         renderer = gtk.CellRendererText()
00279         renderer.set_data("column", COLUMN_GROUPNAME)
00280         column = gtk.TreeViewColumn(_('Group'), renderer,
00281                                     text=COLUMN_GROUPNAME)
00282         column.set_sort_column_id(COLUMN_GROUPNAME)
00283         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00284         column.set_fixed_width(constants.COLUMN_WIDTH_GROUPNAME)
00285         treeview.append_column(column)
00286 
00287         # column for description
00288         renderer = gtk.CellRendererText()
00289         renderer.set_data("column", COLUMN_DESCRIPTION)
00290         column = gtk.TreeViewColumn(_('Description'), renderer,
00291                                     text=COLUMN_DESCRIPTION)
00292         column.set_sort_column_id(COLUMN_DESCRIPTION)
00293         column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00294         column.set_fixed_width(constants.COLUMN_WIDTH_GROUPDESCRIPTION_EDIT)
00295         treeview.append_column(column)
00296 

def admin.profile_edit.ProfileEdit.__create_model (   self,
  with,
  profile_id 
) [private]

Definition at line 226 of file profile_edit.py.

00226 
00227     def __create_model(self, with, profile_id):
00228 
00229         model = gtk.ListStore(
00230             gobject.TYPE_INT,
00231             gobject.TYPE_STRING,
00232             gobject.TYPE_STRING,
00233             gobject.TYPE_STRING)
00234 
00235         # Grab the all the groups
00236         self.cur.execute('SELECT group_id,name,description FROM groups ORDER BY name')
00237         group_data = self.cur.fetchall()
00238 
00239         for group in group_data:
00240 
00241             group_id = group[0]
00242             # Check our group is already in the profile
00243             self.cur.execute('SELECT * FROM list_groups_in_profiles ' +
00244                              'WHERE profile_id=? AND group_id=?',
00245                              (profile_id, group_id))
00246             group_is_already = self.cur.fetchall()
00247 
00248             # Extract the class name of this group
00249             class_name = constants.get_class_name_for_group_id(self.con,
00250                                                                self.cur,
00251                                                                group_id)
00252 
00253             # Insert the class name in the group
00254             group = (group[0], class_name, group[1], group[2])
00255             
00256             if(with and group_is_already):
00257                 self.add_group_in_model(model, group)
00258             elif(not with and not group_is_already):
00259                 self.add_group_in_model(model, group)
00260 
00261         return model

Here is the call graph for this function:

def admin.profile_edit.ProfileEdit.add_group (   self,
  button,
  treeview 
)

Definition at line 299 of file profile_edit.py.

00299 
00300     def add_group(self, button, treeview):
00301 
00302         model = treeview.get_model()
00303         
00304         treestore, paths = treeview.get_selection().get_selected_rows()
00305         
00306         paths.reverse()
00307         
00308         for path in paths:
00309             
00310             iter = treestore.get_iter(path)
00311             
00312             path = model.get_path(iter)[0]
00313             group_id           = model.get_value(iter, COLUMN_GROUPID)
00314             class_name         = model.get_value(iter, COLUMN_CLASSNAME)
00315             group_name         = model.get_value(iter, COLUMN_GROUPNAME)
00316             group_description  = model.get_value(iter, COLUMN_DESCRIPTION)
00317             model.remove(iter)
00318 
00319             # Add in the the right view
00320             self.add_group_in_model(self.model_right,
00321                                     (group_id, class_name, group_name, group_description))
00322             
00323             # Save the change in the base
00324             self.cur.execute('INSERT OR REPLACE INTO list_groups_in_profiles ' +
00325                              '(profile_id, group_id) VALUES (?, ?)',
00326                              (self.profile_id, group_id))
00327             self.con.commit()
00328 

Here is the call graph for this function:

def admin.profile_edit.ProfileEdit.add_group_in_model (   self,
  model,
  group 
)

Definition at line 214 of file profile_edit.py.

00214 
00215     def add_group_in_model(self, model, group):
00216         iter = model.append()
00217         model.set (iter,
00218                    COLUMN_GROUPID,      group[COLUMN_GROUPID],
00219                    COLUMN_CLASSNAME,    group[COLUMN_CLASSNAME],
00220                    COLUMN_GROUPNAME,    group[COLUMN_GROUPNAME],
00221                    COLUMN_DESCRIPTION,  group[COLUMN_DESCRIPTION]
00222                    )

Here is the caller graph for this function:

def admin.profile_edit.ProfileEdit.close (   self,
  button 
)

Definition at line 364 of file profile_edit.py.

00364 
00365     def close(self, button):
00366         self.profile_list.reload_profile()
00367         self.destroy()
        

Here is the call graph for this function:

def admin.profile_edit.ProfileEdit.ok (   self,
  button 
)

Definition at line 370 of file profile_edit.py.

00370 
00371     def ok(self, button):
00372 
00373         # Tell the user he must provide enough information
00374         if(self.entry_profile.get_text().strip() == ""):
00375             dialog = gtk.MessageDialog(None,
00376                                        gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00377                                        gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00378                                        _("You need to provide at least a name for your profile"))
00379             dialog.run()
00380             dialog.destroy()
00381             return
00382 
00383         #
00384         # Now everything is correct, create the profile
00385         #
00386 
00387         profile_data = (self.profile_id,
00388                         self.entry_profile.get_text().strip(),
00389                         self.entry_description.get_text()
00390                       )
00391 
00392         if(self.new_profile):
00393             # Check the login do not exist already
00394             self.cur.execute('SELECT name FROM profiles WHERE name=?',
00395                              (self.entry_profile.get_text(),))
00396             if(self.cur.fetchone()):
00397                 dialog = gtk.MessageDialog(None,
00398                                            gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
00399                                            gtk.MESSAGE_INFO, gtk.BUTTONS_OK,
00400                                            _("There is already a profile with this name"))
00401                 dialog.run()
00402                 dialog.destroy()
00403                 return
00404 
00405             # Create the new profile
00406             profile_id = constants.get_next_profile_id(self.con, self.cur)
00407             self.cur.execute('INSERT INTO profiles (profile_id, name, description) ' +
00408                              'VALUES ( ?, ?, ?)',
00409                              (profile_data));
00410         else:
00411             # Save the profile changes
00412             self.cur.execute('UPDATE profiles SET name=?, description=? where profile_id=?',
00413                              (self.entry_profile.get_text(),
00414                               self.entry_description.get_text(),
00415                               self.profile_id));
00416         self.con.commit()
00417 
00418         # Close the dialog window now
00419         self.profile_list.reload_profile()
00420 
00421         self.destroy()
00422 

Here is the call graph for this function:

def admin.profile_edit.ProfileEdit.remove_group (   self,
  button,
  treeview 
)

Definition at line 331 of file profile_edit.py.

00331 
00332     def remove_group(self, button, treeview):
00333 
00334         model = treeview.get_model()
00335         
00336         treestore, paths = treeview.get_selection().get_selected_rows()
00337         
00338         paths.reverse()
00339         
00340         for path in paths:
00341             
00342             iter = treestore.get_iter(path)
00343             
00344             path = model.get_path(iter)[0]
00345             group_id           = model.get_value(iter, COLUMN_GROUPID)
00346             class_name         = model.get_value(iter, COLUMN_CLASSNAME)
00347             group_name         = model.get_value(iter, COLUMN_GROUPNAME)
00348             group_description  = model.get_value(iter, COLUMN_DESCRIPTION)
00349             model.remove(iter)
00350 
00351             # Add in the the left view
00352             self.add_group_in_model(self.model_left,
00353                                     (group_id, class_name, group_name, group_description))
00354             
00355             # Save the change in the base
00356             self.cur.execute('DELETE FROM list_groups_in_profiles ' +
00357                              'WHERE profile_id=? AND group_id=?',
00358                              (self.profile_id, group_id))
00359             self.con.commit()
00360 
00361 

Here is the call graph for this function:


Member Data Documentation

Definition at line 51 of file profile_edit.py.

Definition at line 50 of file profile_edit.py.

Definition at line 101 of file profile_edit.py.

Definition at line 89 of file profile_edit.py.

Definition at line 126 of file profile_edit.py.

Definition at line 167 of file profile_edit.py.

Definition at line 65 of file profile_edit.py.

Definition at line 53 of file profile_edit.py.

Definition at line 57 of file profile_edit.py.


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