Commit c8b3e1b2 authored by Bruno Coudoin's avatar Bruno Coudoin
Browse files

Created a user edit dialog to replace in table edition.

	Added contextuality to buttons in class and profile list.
parent f7f2d95e
2005-07-27 Bruno coudoin <bruno.coudoin@free.fr>
Created a user edit dialog to replace in table edition.
Added contextuality to buttons in class and profile list.
* src/boards/python/admin/Makefile.am:
* src/boards/python/admin/class_edit.py:
* src/boards/python/admin/profile_list.py:
* src/boards/python/admin/user_edit.py:
* src/boards/python/admin/user_list.py:
2005-07-27 Bruno coudoin <bruno.coudoin@free.fr>
Improved class management. Now the class editor really
......
......@@ -9,6 +9,7 @@ dist_python_DATA= \
module_groups.py \
module_profiles.py \
module_boards.py \
user_edit.py \
user_list.py \
group_edit.py \
group_list.py \
......
......@@ -39,7 +39,7 @@ import constants
class ClassEdit(gtk.Window):
counter = 1
def __init__(self, db_connect, db_cursor,
class_id, class_name, teacher_name,
list_user):
......
......@@ -114,20 +114,23 @@ class Profile_list:
vbox_button.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(stock='gtk-edit')
button.connect("clicked", self.on_edit_profile_clicked, treeview_profile)
vbox_button.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(stock='gtk-remove')
button.connect("clicked", self.on_remove_profile_clicked, treeview_profile)
vbox_button.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(_("Default"))
button.connect("clicked", self.on_default_profile_clicked, treeview_profile)
vbox_button.pack_start(button, False, False, 0)
button.show()
self.button_edit = gtk.Button(stock='gtk-edit')
self.button_edit.connect("clicked", self.on_edit_profile_clicked, treeview_profile)
vbox_button.pack_start(self.button_edit, False, False, 0)
self.button_edit.show()
self.button_edit.set_sensitive(False)
self.button_remove = gtk.Button(stock='gtk-remove')
self.button_remove.connect("clicked", self.on_remove_profile_clicked, treeview_profile)
vbox_button.pack_start(self.button_remove, False, False, 0)
self.button_remove.show()
self.button_remove.set_sensitive(False)
self.button_default = gtk.Button(_("Default"))
self.button_default.connect("clicked", self.on_default_profile_clicked, treeview_profile)
vbox_button.pack_start(self.button_default, False, False, 0)
self.button_default.show()
self.button_default.set_sensitive(False)
# Group list for the profile
group_hbox = gtk.HBox(False, 8)
......@@ -351,8 +354,15 @@ class Profile_list:
model, iter = selection.get_selected()
if iter:
path = model.get_path(iter)[0]
self.current_profile_id = model.get_value(iter, COLUMN_PROFILEID)
profile_group.reload(self.current_profile_id)
self.button_edit.set_sensitive(True)
self.button_remove.set_sensitive(True)
# Set the default button on if needed
if(self.default_profile_id == self.current_profile_id):
self.button_default.set_sensitive(False)
else:
self.button_default.set_sensitive(True)
# gcompris - user_edit.py
#
# Copyright (C) 2005 Bruno Coudoin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
import gtk
import gobject
from gettext import gettext as _
# Database
from pysqlite2 import dbapi2 as sqlite
import user_list
import constants
class UserEdit(gtk.Window):
def __init__(self, db_connect, db_cursor,
user_id, login, firstname, lastname, birthdate, class_id,
list_user):
# Create the toplevel window
gtk.Window.__init__(self)
self.cur = db_cursor
self.con = db_connect
self.user_id = user_id
self.class_id = class_id
# A pointer to the user_list class
# Will be called to refresh the list when edit is done
self.list_user = list_user
self.set_title(_("User Edition"))
self.set_border_width(8)
self.set_default_size(320, 250)
if(firstname and lastname):
frame = gtk.Frame(_("Editing user ") +
lastname + " " +
firstname)
else:
frame = gtk.Frame(_("Editing a new user"))
self.add(frame)
# Main VBOX
vbox = gtk.VBox(False, 8)
vbox.set_border_width(8)
frame.add(vbox)
# Label and Entry for the user name
table = gtk.Table(2, 5, homogeneous=False)
table.set_border_width(0)
table.set_row_spacings(0)
table.set_col_spacings(20)
vbox.pack_start(table, True, True, 0)
label = gtk.Label(_('Login:'))
label.set_alignment(0, 0)
table.attach(label, 0, 1, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
self.entry_login = gtk.Entry()
self.entry_login.set_max_length(20)
self.entry_login.insert_text(login, position=0)
table.attach(self.entry_login, 1, 2, 0, 1, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
# FIXME: How to remove the selection
# Label and Entry for the first name
label = gtk.Label(_('First name:'))
label.set_alignment(0, 0)
table.attach(label, 0, 1, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
self.entry_firstname = gtk.Entry()
self.entry_firstname.set_max_length(30)
self.entry_firstname.insert_text(firstname, position=0)
table.attach(self.entry_firstname, 1, 2, 1, 2, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
# Label and Entry for the last name
label = gtk.Label(_('Last name:'))
label.set_alignment(0, 0)
table.attach(label, 0, 1, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
self.entry_lastname = gtk.Entry()
self.entry_lastname.set_max_length(30)
self.entry_lastname.insert_text(lastname, position=0)
table.attach(self.entry_lastname, 1, 2, 2, 3, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
# Label and Entry for the birth date
label = gtk.Label(_('Birth date:'))
label.set_alignment(0, 0)
table.attach(label, 0, 1, 3, 4, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
self.entry_birthdate = gtk.Entry()
self.entry_birthdate.set_max_length(30)
self.entry_birthdate.insert_text(birthdate, position=0)
table.attach(self.entry_birthdate, 1, 2, 3, 4, xoptions=gtk.SHRINK, yoptions=gtk.EXPAND)
# Confirmation Buttons
# --------------------
vbox.pack_start(gtk.HSeparator(), False, False, 0)
bbox = gtk.HBox(homogeneous=False, spacing=8)
button = gtk.Button(stock='gtk-help')
bbox.pack_start(button, expand=False, fill=False, padding=0)
button = gtk.Button(stock='gtk-ok')
bbox.pack_end(button, expand=False, fill=False, padding=0)
button.connect("clicked", self.ok)
button = gtk.Button(stock='gtk-close')
bbox.pack_end(button, expand=False, fill=False, padding=0)
button.connect("clicked", self.close)
vbox.pack_start(bbox, False, False, 0)
# Ready GO
self.show_all()
# -------------------
# User Management
# -------------------
# Done, can quit this dialog (without saving)
#
def close(self, button):
self.destroy()
# Done, can quit this dialog with saving
#
def ok(self, button):
user_data = (self.user_id,
self.entry_login.get_text(),
self.entry_firstname.get_text(),
self.entry_lastname.get_text(),
self.entry_birthdate.get_text(),
self.class_id
)
# Save the changes in the base
self.cur.execute('insert or replace into users (user_id, login, firstname, lastname, birthdate, class_id) values (?, ?, ?, ?, ?, ?)', user_data)
self.con.commit()
# Close the dialog window now
self.list_user.reload(self.class_id)
self.destroy()
......@@ -30,6 +30,7 @@ from gettext import gettext as _
from pysqlite2 import dbapi2 as sqlite
import constants
import user_edit
# User Management
(
......@@ -38,8 +39,7 @@ import constants
COLUMN_FIRSTNAME,
COLUMN_LASTNAME,
COLUMN_BIRTHDATE,
COLUMN_USER_EDITABLE
) = range(6)
) = range(5)
class User_list:
"""GCompris Users List Table"""
......@@ -117,10 +117,10 @@ class User_list:
right_box.pack_start(button, False, False, 0)
button.show()
button = gtk.Button(stock='gtk-remove')
button.connect("clicked", self.on_remove_item_clicked, treeview)
right_box.pack_start(button, False, False, 0)
button.show()
self.button_remove = gtk.Button(stock='gtk-remove')
self.button_remove.connect("clicked", self.on_remove_item_clicked, treeview)
right_box.pack_start(self.button_remove, False, False, 0)
self.button_remove.show()
# Missing callbacks
selection = treeview.get_selection()
......@@ -138,6 +138,7 @@ class User_list:
self.model.clear()
self.button_edit.set_sensitive(False)
self.button_remove.set_sensitive(False)
# Grab the user data
self.cur.execute('select user_id,login,firstname,lastname,birthdate from users where class_id=?',
......@@ -155,8 +156,7 @@ class User_list:
COLUMN_LOGIN, user[COLUMN_LOGIN],
COLUMN_FIRSTNAME, user[COLUMN_FIRSTNAME],
COLUMN_LASTNAME, user[COLUMN_LASTNAME],
COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE],
COLUMN_USER_EDITABLE, True
COLUMN_BIRTHDATE, user[COLUMN_BIRTHDATE]
)
......@@ -181,11 +181,9 @@ class User_list:
# columns for login
renderer = gtk.CellRendererText()
renderer.connect("edited", self.on_cell_edited, model)
renderer.set_data("column", COLUMN_LOGIN)
column = gtk.TreeViewColumn(_('Login'), renderer,
text=COLUMN_LOGIN,
editable=COLUMN_USER_EDITABLE)
text=COLUMN_LOGIN)
column.set_sort_column_id(COLUMN_LOGIN)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(constants.COLUMN_WIDTH_LOGIN)
......@@ -193,11 +191,9 @@ class User_list:
# columns for first name
renderer = gtk.CellRendererText()
renderer.connect("edited", self.on_cell_edited, model)
renderer.set_data("column", COLUMN_FIRSTNAME)
column = gtk.TreeViewColumn(_('First Name'), renderer,
text=COLUMN_FIRSTNAME,
editable=COLUMN_USER_EDITABLE)
text=COLUMN_FIRSTNAME)
column.set_sort_column_id(COLUMN_FIRSTNAME)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(constants.COLUMN_WIDTH_FIRSTNAME)
......@@ -205,11 +201,9 @@ class User_list:
# column for last name
renderer = gtk.CellRendererText()
renderer.connect("edited", self.on_cell_edited, model)
renderer.set_data("column", COLUMN_LASTNAME)
column = gtk.TreeViewColumn(_('Last Name'), renderer,
text=COLUMN_LASTNAME,
editable=COLUMN_USER_EDITABLE)
text=COLUMN_LASTNAME)
column.set_sort_column_id(COLUMN_LASTNAME)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(constants.COLUMN_WIDTH_LASTNAME)
......@@ -217,11 +211,9 @@ class User_list:
# column for birth date
renderer = gtk.CellRendererText()
renderer.connect("edited", self.on_cell_edited, model)
renderer.set_data("column", COLUMN_BIRTHDATE)
column = gtk.TreeViewColumn(_('Birth Date'), renderer,
text=COLUMN_BIRTHDATE,
editable=COLUMN_USER_EDITABLE)
text=COLUMN_BIRTHDATE)
column.set_sort_column_id(COLUMN_BIRTHDATE)
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
column.set_fixed_width(constants.COLUMN_WIDTH_BIRTHDATE)
......@@ -242,13 +234,29 @@ class User_list:
#
def on_edit_clicked(self, button, treeview):
pass
selection = treeview.get_selection()
model, iter = selection.get_selected()
if iter:
path = model.get_path(iter)[0]
user_id = model.get_value(iter, COLUMN_USERID)
login = model.get_value(iter, COLUMN_LOGIN)
firstname = model.get_value(iter, COLUMN_FIRSTNAME)
lastname = model.get_value(iter, COLUMN_LASTNAME)
birthdate = model.get_value(iter, COLUMN_BIRTHDATE)
user_edit.UserEdit(self.con, self.cur,
user_id, login, firstname, lastname, birthdate, self.class_id,
self)
# Create a new user
def on_add_item_clicked(self, button, model):
user_id = self.get_next_user_id()
new_user = [user_id, "?", "?", "?", "?", self.class_id]
self.add_user_in_model(model, new_user)
user_edit.UserEdit(self.con, self.cur,
user_id, "", "", "", "", self.class_id,
self)
def on_remove_item_clicked(self, button, treeview):
......@@ -328,39 +336,9 @@ class User_list:
file.close()
def on_cell_edited(self, cell, path_string, new_text, model):
iter = model.get_iter_from_string(path_string)
path = model.get_path(iter)[0]
column = cell.get_data("column")
user_id = model.get_value(iter, COLUMN_USERID)
if column == COLUMN_LOGIN:
model.set(iter, column, new_text)
elif column == COLUMN_FIRSTNAME:
model.set(iter, column, new_text)
elif column == COLUMN_LASTNAME:
model.set(iter, column, new_text)
elif column == COLUMN_BIRTHDATE:
model.set(iter, column, new_text)
user_data = (user_id,
model.get_value(iter, COLUMN_LOGIN),
model.get_value(iter, COLUMN_FIRSTNAME),
model.get_value(iter, COLUMN_LASTNAME),
model.get_value(iter, COLUMN_BIRTHDATE),
self.class_id)
# Save the changes in the base
self.cur.execute('insert or replace into users (user_id, login, firstname, lastname, birthdate, class_id) values (?, ?, ?, ?, ?, ?)',
user_data)
self.con.commit()
# The user is changed ...
def user_changed_cb(self, selection, treeview):
self.button_edit.set_sensitive(True)
self.button_remove.set_sensitive(True)
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