1
# gcompris - group_user_list.py
3
# Copyright (C) 2005 Bruno Coudoin and Yves Combe
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, see <http://www.gnu.org/licenses/>.
26
from gcompris import gcompris_gettext as _
32
import sqlite3 as sqlite
35
from pysqlite2 import dbapi2 as sqlite
37
raise ImportError, "no module named sqlite3 or pysqlite2.dbapi2"
51
class Group_user_list:
52
"""GCompris Group User List Table"""
55
# The created list will be packed in the given container
57
def __init__(self, container, db_connect, db_cursor, group_id):
62
# The group_id to work on
63
self.group_id = group_id
66
# User Group Management
70
self.model = self.__create_model()
72
self.reload(self.group_id)
75
sw = gtk.ScrolledWindow()
77
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
78
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
81
treeview_group = gtk.TreeView(self.model)
83
treeview_group.set_rules_hint(True)
84
treeview_group.set_search_column(COLUMN_FIRSTNAME)
85
treeview_group.get_selection().set_mode(gtk.SELECTION_NONE)
87
sw.add(treeview_group)
89
# add columns to the tree view
90
self.__add_columns(treeview_group)
92
container.pack_start(sw)
99
# clear all data in the list
103
# Retrieve data from the database for the given group_id
104
def reload(self, group_id):
105
self.group_id = group_id
107
# Remove all entries in the list
110
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,));
111
users = self.cur.fetchall()
113
self.add_user_in_model(self.model, user)
116
# Add user in the model
117
def add_user_in_model(self, model, user):
118
iter = model.append()
120
COLUMN_USERID, user[COLUMN_USERID],
121
COLUMN_LOGIN, user[COLUMN_LOGIN],
122
COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
123
COLUMN_LASTNAME, user[COLUMN_LASTNAME],
124
COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE]
129
def __create_model(self):
130
model = gtk.ListStore(
140
def __add_columns(self, treeview):
142
model = treeview.get_model()
144
# Total column lengh must be 400
147
renderer = gtk.CellRendererText()
148
renderer.set_data("column", COLUMN_LOGIN)
149
column = gtk.TreeViewColumn(_('Login'), renderer,
151
column.set_sort_column_id(COLUMN_LOGIN)
152
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
153
column.set_fixed_width(constants.COLUMN_WIDTH_LOGIN)
154
treeview.append_column(column)
156
# columns for first name
157
renderer = gtk.CellRendererText()
158
renderer.set_data("column", COLUMN_FIRSTNAME)
159
column = gtk.TreeViewColumn(_('First Name'), renderer,
160
text=COLUMN_FIRSTNAME)
161
column.set_sort_column_id(COLUMN_FIRSTNAME)
162
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
163
column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
164
treeview.append_column(column)
166
# column for last name
167
renderer = gtk.CellRendererText()
168
renderer.set_data("column", COLUMN_LASTNAME)
169
column = gtk.TreeViewColumn(_('Last Name'), renderer,
170
text=COLUMN_LASTNAME)
171
column.set_sort_column_id(COLUMN_LASTNAME)
172
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
173
column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
174
treeview.append_column(column)
176
# column for birth date
177
renderer = gtk.CellRendererText()
178
renderer.set_data("column", COLUMN_BIRTHDATE)
179
column = gtk.TreeViewColumn(_('Birth Date'), renderer,
180
text=COLUMN_BIRTHDATE)
181
column.set_sort_column_id(COLUMN_BIRTHDATE)
182
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
183
column.set_fixed_width(constants.COLUMN_WIDTH_BIRTHDATE)
184
treeview.append_column(column)