~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/boards/python/admin/profile_group_list.py

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

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