~ml-launchpad/ubuntu/natty/gcompris/fix-for-777349

« back to all changes in this revision

Viewing changes to src/administration-activity/admin/profile_group_list.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Gariepy, Marc Gariepy, Stephane Graber
  • Date: 2010-01-04 17:42:49 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20100104174249-7bupatd9dtxyhvs4
Tags: 9.0-0ubuntu1
[Marc Gariepy]
* New upstream release (9.0).
* Remove cache.c from POTFILES to avoid FTBFS
* Remove unneeded rm in debian/rules (file no longer exists upstream)

[Stephane Graber]
* Bump Debian standards to 3.8.3
* Add patch system (dpatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#  gcompris - profile_group_list.py
 
2
#
 
3
# Copyright (C) 2005, 2008 Bruno Coudoin and Yves Combe
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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/>.
 
17
#
 
18
 
 
19
import goocanvas
 
20
import gcompris
 
21
import gcompris.utils
 
22
import gcompris.skin
 
23
import gtk
 
24
import gtk.gdk
 
25
import gobject
 
26
from gcompris import gcompris_gettext as _
 
27
 
 
28
import constants
 
29
 
 
30
# Database
 
31
from pysqlite2 import dbapi2 as sqlite
 
32
 
 
33
#import group_edit
 
34
 
 
35
# Group Management
 
36
(
 
37
  COLUMN_GROUPID,
 
38
  COLUMN_CLASSNAME,
 
39
  COLUMN_GROUPNAME,
 
40
  COLUMN_DESCRIPTION,
 
41
) = range(4)
 
42
 
 
43
 
 
44
class Profile_group_list:
 
45
  """GCompris Profile Group List Table"""
 
46
 
 
47
 
 
48
  # The created list will be packed in the given container
 
49
  #
 
50
  def __init__(self, container, db_connect, db_cursor, profile_id):
 
51
 
 
52
      self.cur = db_cursor
 
53
      self.con = db_connect
 
54
 
 
55
      # The profile_id to work on
 
56
      self.profile_id = profile_id
 
57
 
 
58
      # ---------------
 
59
      # User Group Management
 
60
      # ---------------
 
61
 
 
62
      # create tree model
 
63
      self.model = self.__create_model()
 
64
 
 
65
      self.reload(self.profile_id)
 
66
 
 
67
      # Create the table
 
68
      sw = gtk.ScrolledWindow()
 
69
      sw.show()
 
70
      sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
 
71
      sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
72
 
 
73
      # create tree view
 
74
      treeview_group = gtk.TreeView(self.model)
 
75
      treeview_group.show()
 
76
      treeview_group.set_rules_hint(True)
 
77
      treeview_group.set_search_column(COLUMN_GROUPNAME)
 
78
 
 
79
      sw.add(treeview_group)
 
80
 
 
81
      # add columns to the tree view
 
82
      self.__add_columns(treeview_group)
 
83
 
 
84
      container.pack_start(sw)
 
85
 
 
86
 
 
87
  # -------------------
 
88
  # Group Management
 
89
  # -------------------
 
90
 
 
91
  # clear all data in the list
 
92
  def clear(self):
 
93
      self.model.clear()
 
94
 
 
95
  # Retrieve data from the database for the given profile_id
 
96
  def reload(self, profile_id):
 
97
 
 
98
      self.profile_id = profile_id
 
99
 
 
100
      # Remove all entries in the list
 
101
      self.model.clear()
 
102
 
 
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',
 
104
                       (self.profile_id, ))
 
105
 
 
106
      groups = self.cur.fetchall()
 
107
      for group in groups:
 
108
        self.add_group_in_model(self.model, group)
 
109
 
 
110
 
 
111
 
 
112
  # Add group in the model
 
113
  def add_group_in_model(self, model, group):
 
114
    iter = model.append()
 
115
    model.set (iter,
 
116
               COLUMN_GROUPID,     group[COLUMN_GROUPID],
 
117
               COLUMN_CLASSNAME,   group[COLUMN_CLASSNAME],
 
118
               COLUMN_GROUPNAME,   group[COLUMN_GROUPNAME],
 
119
               COLUMN_DESCRIPTION, group[COLUMN_DESCRIPTION],
 
120
               )
 
121
 
 
122
 
 
123
 
 
124
  def __create_model(self):
 
125
    model = gtk.ListStore(
 
126
      gobject.TYPE_INT,
 
127
      gobject.TYPE_STRING,
 
128
      gobject.TYPE_STRING,
 
129
      gobject.TYPE_STRING)
 
130
 
 
131
    return model
 
132
 
 
133
 
 
134
  def __add_columns(self, treeview):
 
135
 
 
136
    model = treeview.get_model()
 
137
 
 
138
    # Total column lengh must be 400
 
139
 
 
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)
 
149
 
 
150
    # columns for name
 
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)
 
159
 
 
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)
 
169
 
 
170