Back to index

gcompris  8.2.2
group_user_list.py
Go to the documentation of this file.
00001 #  gcompris - group_user_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 # User Management
00037 (
00038   COLUMN_USERID,
00039   COLUMN_LOGIN,
00040   COLUMN_FIRSTNAME,
00041   COLUMN_LASTNAME,
00042   COLUMN_BIRTHDATE,
00043 ) = range(5)
00044 
00045 
00046 class Group_user_list:
00047   """GCompris Group User List Table"""
00048 
00049 
00050   # The created list will be packed in the given container
00051   #
00052   def __init__(self, container, db_connect, db_cursor, group_id):
00053 
00054       self.cur = db_cursor
00055       self.con = db_connect
00056 
00057       # The group_id to work on
00058       self.group_id = group_id
00059 
00060       # ---------------
00061       # User Group Management
00062       # ---------------
00063 
00064       # create tree model
00065       self.model = self.__create_model()
00066 
00067       self.reload(self.group_id)
00068 
00069       # Create the table
00070       sw = gtk.ScrolledWindow()
00071       sw.show()
00072       sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
00073       sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
00074 
00075       # create tree view
00076       treeview_group = gtk.TreeView(self.model)
00077       treeview_group.show()
00078       treeview_group.set_rules_hint(True)
00079       treeview_group.set_search_column(COLUMN_FIRSTNAME)
00080       treeview_group.get_selection().set_mode(gtk.SELECTION_NONE)
00081 
00082       sw.add(treeview_group)
00083 
00084       # add columns to the tree view
00085       self.__add_columns(treeview_group)
00086 
00087       container.pack_start(sw)
00088 
00089 
00090   # -------------------
00091   # User Management
00092   # -------------------
00093 
00094   # clear all data in the list
00095   def clear(self):
00096       self.model.clear()
00097 
00098   # Retrieve data from the database for the given group_id
00099   def reload(self, group_id):
00100       self.group_id = group_id
00101 
00102       # Remove all entries in the list
00103       self.model.clear()
00104 
00105       self.cur.execute('SELECT DISTINCT users.user_id,login,firstname,lastname,birthdate FROM users,list_users_in_groups WHERE list_users_in_groups.group_id=? AND list_users_in_groups.user_id=users.user_id ORDER BY login', (self.group_id,));
00106       users = self.cur.fetchall()
00107       for user in users:
00108         self.add_user_in_model(self.model, user)
00109 
00110 
00111   # Add user in the model
00112   def add_user_in_model(self, model, user):
00113     iter = model.append()
00114     model.set (iter,
00115                COLUMN_USERID,    user[COLUMN_USERID],
00116                COLUMN_LOGIN,     user[COLUMN_LOGIN],
00117                COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
00118                COLUMN_LASTNAME,  user[COLUMN_LASTNAME],
00119                COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE]
00120                )
00121 
00122 
00123 
00124   def __create_model(self):
00125     model = gtk.ListStore(
00126       gobject.TYPE_INT,
00127       gobject.TYPE_STRING,
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 login
00142     renderer = gtk.CellRendererText()
00143     renderer.set_data("column", COLUMN_LOGIN)
00144     column = gtk.TreeViewColumn(_('Login'), renderer,
00145                                 text=COLUMN_LOGIN)
00146     column.set_sort_column_id(COLUMN_LOGIN)
00147     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00148     column.set_fixed_width(constants.COLUMN_WIDTH_LOGIN)
00149     treeview.append_column(column)
00150 
00151     # columns for first name
00152     renderer = gtk.CellRendererText()
00153     renderer.set_data("column", COLUMN_FIRSTNAME)
00154     column = gtk.TreeViewColumn(_('First Name'), renderer,
00155                                 text=COLUMN_FIRSTNAME)
00156     column.set_sort_column_id(COLUMN_FIRSTNAME)
00157     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00158     column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
00159     treeview.append_column(column)
00160 
00161     # column for last name
00162     renderer = gtk.CellRendererText()
00163     renderer.set_data("column", COLUMN_LASTNAME)
00164     column = gtk.TreeViewColumn(_('Last Name'), renderer,
00165                                 text=COLUMN_LASTNAME)
00166     column.set_sort_column_id(COLUMN_LASTNAME)
00167     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00168     column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
00169     treeview.append_column(column)
00170 
00171     # column for birth date
00172     renderer = gtk.CellRendererText()
00173     renderer.set_data("column", COLUMN_BIRTHDATE)
00174     column = gtk.TreeViewColumn(_('Birth Date'), renderer,
00175                                 text=COLUMN_BIRTHDATE)
00176     column.set_sort_column_id(COLUMN_BIRTHDATE)
00177     column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
00178     column.set_fixed_width(constants.COLUMN_WIDTH_BIRTHDATE)
00179     treeview.append_column(column)
00180 
00181 
00182 
00183