1
# gcompris - profile_group_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 2 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, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27
from gettext import gettext as _
32
from pysqlite2 import dbapi2 as sqlite
45
class Profile_group_list:
46
"""GCompris Profile Group List Table"""
49
# The created list will be packed in the given container
51
def __init__(self, container, db_connect, db_cursor, profile_id):
56
# The profile_id to work on
57
self.profile_id = profile_id
60
# User Group Management
64
self.model = self.__create_model()
66
self.reload(self.profile_id)
69
sw = gtk.ScrolledWindow()
71
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
72
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
75
treeview_group = gtk.TreeView(self.model)
77
treeview_group.set_rules_hint(True)
78
treeview_group.set_search_column(COLUMN_GROUPNAME)
80
sw.add(treeview_group)
82
# add columns to the tree view
83
self.__add_columns(treeview_group)
85
container.pack_start(sw)
92
# clear all data in the list
96
# Retrieve data from the database for the given profile_id
97
def reload(self, profile_id):
99
self.profile_id = profile_id
101
# Remove all entries in the list
104
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',
107
groups = self.cur.fetchall()
109
self.add_group_in_model(self.model, group)
113
# Add group in the model
114
def add_group_in_model(self, model, group):
115
iter = model.append()
117
COLUMN_GROUPID, group[COLUMN_GROUPID],
118
COLUMN_CLASSNAME, group[COLUMN_CLASSNAME],
119
COLUMN_GROUPNAME, group[COLUMN_GROUPNAME],
120
COLUMN_DESCRIPTION, group[COLUMN_DESCRIPTION],
125
def __create_model(self):
126
model = gtk.ListStore(
135
def __add_columns(self, treeview):
137
model = treeview.get_model()
139
# Total column lengh must be 400
141
# columns for class name
142
renderer = gtk.CellRendererText()
143
renderer.set_data("column", COLUMN_CLASSNAME)
144
column = gtk.TreeViewColumn(_('Class'), renderer,
145
text=COLUMN_CLASSNAME)
146
column.set_sort_column_id(COLUMN_CLASSNAME)
147
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
148
column.set_fixed_width(constants.COLUMN_WIDTH_CLASSNAME)
149
treeview.append_column(column)
152
renderer = gtk.CellRendererText()
153
renderer.set_data("column", COLUMN_GROUPNAME)
154
column = gtk.TreeViewColumn(_('Group'), renderer,
155
text=COLUMN_GROUPNAME)
156
column.set_sort_column_id(COLUMN_GROUPNAME)
157
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
158
column.set_fixed_width(constants.COLUMN_WIDTH_GROUPNAME)
159
treeview.append_column(column)
161
# columns for description
162
renderer = gtk.CellRendererText()
163
renderer.set_data("column", COLUMN_DESCRIPTION)
164
column = gtk.TreeViewColumn(_('Description'), renderer,
165
text=COLUMN_DESCRIPTION)
166
column.set_sort_column_id(COLUMN_DESCRIPTION)
167
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
168
column.set_fixed_width(constants.COLUMN_WIDTH_GROUPDESCRIPTION)
169
treeview.append_column(column)