1
# gcompris - profile_group_list.py
3
# Copyright (C) 2005, 2008 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 _
31
from pysqlite2 import dbapi2 as sqlite
44
class Profile_group_list:
45
"""GCompris Profile Group List Table"""
48
# The created list will be packed in the given container
50
def __init__(self, container, db_connect, db_cursor, profile_id):
55
# The profile_id to work on
56
self.profile_id = profile_id
59
# User Group Management
63
self.model = self.__create_model()
65
self.reload(self.profile_id)
68
sw = gtk.ScrolledWindow()
70
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
71
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
74
treeview_group = gtk.TreeView(self.model)
76
treeview_group.set_rules_hint(True)
77
treeview_group.set_search_column(COLUMN_GROUPNAME)
79
sw.add(treeview_group)
81
# add columns to the tree view
82
self.__add_columns(treeview_group)
84
container.pack_start(sw)
91
# clear all data in the list
95
# Retrieve data from the database for the given profile_id
96
def reload(self, profile_id):
98
self.profile_id = profile_id
100
# Remove all entries in the list
103
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',
106
groups = self.cur.fetchall()
108
self.add_group_in_model(self.model, group)
112
# Add group in the model
113
def add_group_in_model(self, model, group):
114
iter = model.append()
116
COLUMN_GROUPID, group[COLUMN_GROUPID],
117
COLUMN_CLASSNAME, group[COLUMN_CLASSNAME],
118
COLUMN_GROUPNAME, group[COLUMN_GROUPNAME],
119
COLUMN_DESCRIPTION, group[COLUMN_DESCRIPTION],
124
def __create_model(self):
125
model = gtk.ListStore(
134
def __add_columns(self, treeview):
136
model = treeview.get_model()
138
# Total column lengh must be 400
140
# columns for class name
141
renderer = gtk.CellRendererText()
142
renderer.set_data("column", COLUMN_CLASSNAME)
143
column = gtk.TreeViewColumn(_('Class'), renderer,
144
text=COLUMN_CLASSNAME)
145
column.set_sort_column_id(COLUMN_CLASSNAME)
146
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
147
column.set_fixed_width(constants.COLUMN_WIDTH_CLASSNAME)
148
treeview.append_column(column)
151
renderer = gtk.CellRendererText()
152
renderer.set_data("column", COLUMN_GROUPNAME)
153
column = gtk.TreeViewColumn(_('Group'), renderer,
154
text=COLUMN_GROUPNAME)
155
column.set_sort_column_id(COLUMN_GROUPNAME)
156
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
157
column.set_fixed_width(constants.COLUMN_WIDTH_GROUPNAME)
158
treeview.append_column(column)
160
# columns for description
161
renderer = gtk.CellRendererText()
162
renderer.set_data("column", COLUMN_DESCRIPTION)
163
column = gtk.TreeViewColumn(_('Description'), renderer,
164
text=COLUMN_DESCRIPTION)
165
column.set_sort_column_id(COLUMN_DESCRIPTION)
166
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
167
column.set_fixed_width(constants.COLUMN_WIDTH_GROUPDESCRIPTION)
168
treeview.append_column(column)