Commit 297af575 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

Reworked the class module to use a single canvas item

	Now layout is managed by GTK
	Bottom user list now follow the top class list selection
parent bb19f7ce
2005-07-13 Bruno coudoin <bruno.coudoin@free.fr>
Reworked the class module to use a single canvas item
Now layout is managed by GTK
Bottom user list now follow the top class list selection
* src/boards/python/admin/class_list.py:
* src/boards/python/admin/group_user_list.py:
* src/boards/python/admin/module_users.py:
* src/boards/python/admin/user_list.py:
2005-07-12 Bruno coudoin <bruno.coudoin@free.fr>
Completed implementation of the group module. Should be usable now
......
......@@ -31,6 +31,7 @@ from gettext import gettext as _
from pysqlite2 import dbapi2 as sqlite
import class_edit
import user_list
# Class Management
(
......@@ -51,88 +52,100 @@ class Class_list:
self.cur = db_cursor
self.con = db_connect
self.class_data = []
# ---------------
# Class Management
# ---------------
# Grab the class data
self.cur.execute('select * from class')
self.class_data = self.cur.fetchall()
frame = gtk.Frame(_("User"))
frame.show()
# create tree model
model = self.__create_model_class()
# Main box is vertical
top_box = gtk.VBox(False, 8)
top_box.show()
frame.add(top_box)
# First line
group_hbox = gtk.HBox(False, 8)
group_hbox.show()
top_box.add(group_hbox)
left_box = gtk.VBox(False, 8)
left_box.show()
group_hbox.add(left_box)
right_box = gtk.VBox(False, 8)
right_box.show()
group_hbox.add(right_box)
# Create the table
sw = gtk.ScrolledWindow()
sw.show()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
# create tree model
model = self.__create_model_class()
# create tree view
treeview_class = gtk.TreeView(model)
treeview_class.show()
treeview_class.set_rules_hint(True)
treeview_class.set_search_column(COLUMN_NAME)
sw.add(treeview_class)
# Some constants for the layout
but_height = hgap * 2
but_width = hgap * 6
left_box.pack_start(sw, True, True, 0)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=sw,
x=area[0] + hgap,
y=area[1],
width=area[2]-area[0]-hgap*2-but_width,
height=area[3]-area[1],
anchor=gtk.ANCHOR_NW,
size_pixels=False)
sw.show()
treeview_class.show()
# add columns to the tree view
self.__add_columns_class(treeview_class)
# Add buttons
button_add = gtk.Button(_("Add class"))
button_add.connect("clicked", self.on_add_class_clicked, model)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_add,
x=area[2]-but_width,
y=area[1],
width=100,
height=but_height,
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_add.show()
button = gtk.Button(stock='gtk-add')
button.connect("clicked", self.on_add_class_clicked, model)
right_box.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(stock='gtk-delete')
button.connect("clicked", self.on_remove_class_clicked, treeview_class)
right_box.pack_start(button, False, False, 0)
button.show()
button_rem = gtk.Button(_("Remove class"))
button_rem.connect("clicked", self.on_remove_class_clicked, treeview_class)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_rem,
x=area[2]-but_width,
y=area[1] + but_height + vgap,
width=100,
height=but_height,
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_rem.show()
button = gtk.Button(stock='gtk-edit')
button.connect("clicked", self.on_edit_class_clicked, treeview_class)
right_box.pack_start(button, False, False, 0)
button.show()
button_rem = gtk.Button(_("Edit class"))
button_rem.connect("clicked", self.on_edit_class_clicked, treeview_class)
# User list for the group
user_hbox = gtk.HBox(False, 8)
user_hbox.show()
top_box.add(user_hbox)
list_user = user_list.User_list(user_hbox,
self.con, self.cur)
# Missing callbacks
selection = treeview_class.get_selection()
selection.connect('changed', self.class_changed_cb, list_user)
# Pack it all
# -----------
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_rem,
x=area[2]-but_width,
y=area[1] + but_height*2 + vgap*2,
width=100,
height=but_height,
widget=frame,
x=area[0] + hgap,
y=area[1],
width=area[2]-area[0] - hgap*2,
height=area[3]-area[1],
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_rem.show()
# -------------------
# Class Management
......@@ -145,6 +158,10 @@ class Class_list:
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN)
# Grab the class data
self.cur.execute('select * from class')
self.class_data = self.cur.fetchall()
for item in self.class_data:
iter = model.append()
model.set(iter,
......@@ -267,3 +284,16 @@ class Class_list:
_("You must first select a class in the list"))
dialog.run()
dialog.destroy()
def class_changed_cb(self, selection, user_list):
print "class_changed_cb"
model, iter = selection.get_selected()
if iter:
path = model.get_path(iter)[0]
class_id = model.get_value(iter, COLUMN_CLASSID)
user_list.reload(class_id)
print "current class_id = " + str(class_id)
......@@ -47,9 +47,7 @@ class Group_user_list:
"""GCompris Group User List Table"""
# area is the drawing area for the list
#
# return the list item
# The created list will be packed in the given container
#
def __init__(self, container, db_connect, db_cursor, group_id):
......
......@@ -31,7 +31,6 @@ from gettext import gettext as _
from pysqlite2 import dbapi2 as sqlite
import module
import user_list
import class_list
class Users(module.Module):
......@@ -70,29 +69,15 @@ class Users(module.Module):
vgap = 15
# Define the area percent for each list
class_percent = 0.45
user_percent = 1.0-class_percent
class_percent = 1.0
origin_y = area[1]+vgap
class_height = (area[3]-area[1])*class_percent - vgap*2
class_height = (area[3]-area[1])*class_percent - vgap
list_area = ( area[0], origin_y, area[2], class_height)
class_list.Class_list(self.rootitem,
self.con, self.cur,
list_area, hgap, vgap)
origin_y = origin_y + class_height + vgap
user_height = origin_y + (area[3]-area[1])*user_percent - vgap*2
list_area = ( area[0], origin_y, area[2], user_height)
# FIXME: Need to rearange this code. The two list are linked and we need
# to pass the class_id in the user list
self.class_id = 0
user_list.User_list(self.rootitem,
self.con, self.cur,
list_area, hgap, vgap,
self.class_id)
......
......@@ -18,7 +18,6 @@
#
import gnome
import gnome.canvas
import gcompris
import gcompris.utils
import gcompris.skin
......@@ -44,105 +43,94 @@ class User_list:
"""GCompris Users List Table"""
# area is the drawing area for the list
# Display the users for the givent class_id in a table
def __init__(self, canvas, db_connect, db_cursor, area, hgap, vgap, class_id):
# The created list will be packed in the given container
#
# Display the users for a given class_id in a table
# The class_id to display must be passed to the reload function
def __init__(self, container, db_connect, db_cursor):
self.rootitem = canvas
self.cur = db_cursor
self.con = db_connect
self.class_id = class_id
# ---------------
# User Management
# ---------------
# Grab the user data
self.cur.execute('select user_id,login,firstname,lastname,birthdate from users where class_id=?',
(class_id,))
self.user_data = self.cur.fetchall()
self.user_data = []
# create tree model
self.model = self.__create_model()
# First line
group_hbox = gtk.HBox(False, 8)
group_hbox.show()
container.add(group_hbox)
left_box = gtk.VBox(False, 8)
left_box.show()
group_hbox.add(left_box)
right_box = gtk.VBox(False, 8)
right_box.show()
group_hbox.add(right_box)
# Create the table
sw = gtk.ScrolledWindow()
sw.show()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
# create tree model
model = self.__create_model()
# create tree view
treeview = gtk.TreeView(model)
treeview = gtk.TreeView(self.model)
treeview.show()
treeview.set_rules_hint(True)
treeview.set_search_column(COLUMN_FIRSTNAME)
sw.add(treeview)
# Some constants for the layout
but_height = hgap * 2
but_width = hgap * 6
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=sw,
x=area[0] + hgap,
y=area[1],
width=area[2]-area[0]-hgap*2-but_width,
height=area[3]-area[1],
anchor=gtk.ANCHOR_NW,
size_pixels=False)
sw.show()
treeview.show()
left_box.pack_start(sw, True, True, 0)
# add columns to the tree view
self.__add_columns(treeview)
# Add buttons
button_add = gtk.Button(_("Add user"))
button_add.connect("clicked", self.on_add_item_clicked, model)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_add,
x=area[2]-but_width,
y=area[1],
width=100,
height=but_height,
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_add.show()
button = gtk.Button(stock='gtk-add')
button.connect("clicked", self.on_add_item_clicked, self.model)
right_box.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(stock='gtk-delete')
button.connect("clicked", self.on_remove_item_clicked, treeview)
right_box.pack_start(button, False, False, 0)
button.show()
button_rem = gtk.Button(_("Remove user"))
button_rem.connect("clicked", self.on_remove_item_clicked, treeview)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_rem,
x=area[2]-but_width,
y=area[1] + but_height + vgap,
width=100,
height=but_height,
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_rem.show()
button_imp = gtk.Button(_("Import file"))
button_imp.connect("clicked", self.on_import_cvs_clicked, treeview)
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=button_imp,
x=area[2]-but_width,
y=area[1] + (but_height + vgap) * 2,
width=100,
height=but_height,
anchor=gtk.ANCHOR_NW,
size_pixels=False)
button_imp.show()
button = gtk.Button(stock='gtk-open')
button.connect("clicked", self.on_import_cvs_clicked, treeview)
right_box.pack_start(button, False, False, 0)
button.show()
# -------------------
# User Management
# -------------------
# Retrieve data from the database for the given class_id
def reload(self, class_id):
print "Reloading users for class_id=" + str(class_id)
self.class_id = class_id
# Remove all entries in the list
self.model.clear()
# Grab the user data
self.cur.execute('select user_id,login,firstname,lastname,birthdate from users where class_id=?',
(class_id,))
self.user_data = self.cur.fetchall()
for user in self.user_data:
self.add_user_in_model(self.model, user)
# Add user in the model
def add_user_in_model(self, model, user):
iter = model.append()
......@@ -166,9 +154,6 @@ class User_list:
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN)
for user in self.user_data:
self.add_user_in_model(model, user)
return model
......@@ -346,4 +331,3 @@ class User_list:
user_data)
self.con.commit()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment