Back to index

gcompris  8.2.2
profile_group_list.py
Go to the documentation of this file.
00001 #  gcompris - profile_group_list.py
00002 #
00003 # Copyright (C) 2005 Bruno Coudoin and Yves Combe
00004 #
00005 #   This program is free software; you can redistribute it and/or modify
00006 #   it under the terms of the GNU General Public License as published by
00007 #   the Free Software Foundation; either version 2 of the License, or
00008 #   (at your option) any later version.
00009 #
00010 #   This program is distributed in the hope that it will be useful,
00011 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #   GNU General Public License for more details.
00014 #
00015 #   You should have received a copy of the GNU General Public License
00016 #   along with this program; if not, write to the Free Software
00017 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 
00020 import gnomecanvas
00021 import gcompris
00022 import gcompris.utils
00023 import gcompris.skin
00024 import gtk
00025 import gtk.gdk
00026 import gobject
00027 from gettext import gettext as _
00028 
00029 import constants
00030 
00031 # Database
00032 from pysqlite2 import dbapi2 as sqlite
00033 
00034 #import group_edit
00035 
00036 # Group Management
00037 (
00038   COLUMN_GROUPID,
00039   COLUMN_CLASSNAME,
00040   COLUMN_GROUPNAME,
00041   COLUMN_DESCRIPTION,
00042 ) = range(4)
00043 
00044 
00045 class Profile_group_list:
00046   """GCompris Profile Group List Table"""
00047 
00048 
00049   # The created list will be packed in the given container
00050   #
00051   def __init__(self, container, db_connect, db_cursor, profile_id):
00052 
00053       self.cur = db_cursor
00054       self.con = db_connect
00055 
00056       # The profile_id to work on
00057       self.profile_id = profile_id
00058 
00059       # ---------------
00060       # User Group Management
00061       # ---------------
00062 
00063       # create tree model
00064       self.model = self.__create_model()
00065 
00066       self.reload(self.profile_id)
00067 
00068       # Create the table
00069       sw = gtk.ScrolledWindow()
00070       sw.show()
00071       sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00072       sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00073 
00074       # create tree view
00075       treeview_group = gtk.TreeView(self.model)
00076       treeview_group.show()
00077       treeview_group.set_rules_hint(True)
00078       treeview_group.set_search_column(COLUMN_GROUPNAME)
00079 
00080       sw.add(treeview_group)
00081 
00082       # add columns to the tree view
00083       self.__add_columns(treeview_group)
00084 
00085       container.pack_start(sw)
00086 
00087 
00088   # -------------------
00089   # Group Management
00090   # -------------------
00091 
00092   # clear all data in the list
00093   def clear(self):
00094       self.model.clear()
00095 
00096   # Retrieve data from the database for the given profile_id
00097   def reload(self, profile_id):
00098 
00099       self.profile_id = profile_id
00100 
00101       # Remove all entries in the list
00102       self.model.clear()
00103 
00104       self.cur.execute('SELECT DISTINCT groups.group_id,class.name,groups.name,groups.description FROM groups,list_groups_in_profiles,class WHERE list_groups_in_profiles.profile_id=? AND list_groups_in_profiles.group_id=groups.group_id AND class.class_id=groups.class_id ORDER BY class.name,groups.name',
00105                        (self.profile_id, ))
00106 
00107       groups = self.cur.fetchall()
00108       for group in groups:
00109         self.add_group_in_model(self.model, group)
00110 
00111 
00112 
00113   # Add group in the model
00114   def add_group_in_model(self, model, group):
00115     iter = model.append()
00116     model.set (iter,
00117                COLUMN_GROUPID,     group[COLUMN_GROUPID],
00118                COLUMN_CLASSNAME,   group[COLUMN_CLASSNAME],
00119                COLUMN_GROUPNAME,   group[COLUMN_GROUPNAME],
00120                COLUMN_DESCRIPTION, group[COLUMN_DESCRIPTION],
00121                )
00122 
00123 
00124 
00125   def __create_model(self):
00126     model = gtk.ListStore(
00127       gobject.TYPE_INT,
00128       gobject.TYPE_STRING,
00129       gobject.TYPE_STRING,
00130       gobject.TYPE_STRING)
00131 
00132     return model
00133 
00134 
00135   def __add_columns(self, treeview):
00136 
00137     model = treeview.get_model()
00138 
00139     # Total column lengh must be 400
00140 
00141     # columns for class name
00142     renderer = gtk.CellRendererText()
00143     renderer.set_data("column", COLUMN_CLASSNAME)
00144     column = gtk.TreeViewColumn(_('Class'), renderer,
00145                                 text=COLUMN_CLASSNAME)
00146     column.set_sort_column_id(COLUMN_CLASSNAME)
00147     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00148     column.set_fixed_width(constants.COLUMN_WIDTH_CLASSNAME)
00149     treeview.append_column(column)
00150 
00151     # columns for name
00152     renderer = gtk.CellRendererText()
00153     renderer.set_data("column", COLUMN_GROUPNAME)
00154     column = gtk.TreeViewColumn(_('Group'), renderer,
00155                                 text=COLUMN_GROUPNAME)
00156     column.set_sort_column_id(COLUMN_GROUPNAME)
00157     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00158     column.set_fixed_width(constants.COLUMN_WIDTH_GROUPNAME)
00159     treeview.append_column(column)
00160 
00161     # columns for description
00162     renderer = gtk.CellRendererText()
00163     renderer.set_data("column", COLUMN_DESCRIPTION)
00164     column = gtk.TreeViewColumn(_('Description'), renderer,
00165                                 text=COLUMN_DESCRIPTION)
00166     column.set_sort_column_id(COLUMN_DESCRIPTION)
00167     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00168     column.set_fixed_width(constants.COLUMN_WIDTH_GROUPDESCRIPTION)
00169     treeview.append_column(column)
00170 
00171