Commit 1edcdd0f authored by Yves Combe's avatar Yves Combe
Browse files

Put set_board_conf directly in gcompris module.

Add combobox to select profile in Boards panel module.
Finish (but untested) admin db functions.
parent b388acd3
2005-07-20 Yves Combe <yves@ycombe.net>
Put set_board_conf directly in gcompris module.
Add combobox to select profile in Boards panel module.
Finish (but untested) admin db functions.
* src/boards/py-mod-admin.c:
* src/boards/py-mod-gcompris.c: (py_gcompris_set_board_conf):
* src/boards/python/admin/board_list.py:
* src/boards/python/admin/module_boards.py:
* src/boards/python/tuxpaint.py:
* src/gcompris/gcompris_db.c: (gcompris_get_profiles_list),
(gcompris_get_group_from_id), (gcompris_get_groups_list),
(gcompris_get_board_from_id), (gcompris_get_users_list),
(gcompris_get_classes_list):
2005-07-19 Bruno coudoin <bruno.coudoin@free.fr>
Now after edition, the user and group list is updated
......
......@@ -96,39 +96,6 @@ py_gcompris_get_boards_list (PyObject* self, PyObject* args)
return pylist;
}
static PyObject*
py_gcompris_set_board_conf (PyObject* self, PyObject* args)
{
GcomprisConfPair *pair;
PyObject* pyBoard;
PyObject* pyProfile;
pyGcomprisBoardObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
pyGcomprisProfileObject* pyGcomprisProfile;
GcomprisProfile* cGcomprisProfile;
char *key;
char *value;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "OOss:gcompris.set_board_conf",
&pyProfile, &pyBoard,
&key, &value))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
pyGcomprisProfile = (pyGcomprisProfileObject *) pyProfile;
cGcomprisProfile = pyGcomprisProfile->cdata;
cGcomprisBoard = pyGcomprisBoard->cdata;
/* Call the corresponding C function */
gcompris_set_board_conf(cGcomprisProfile, cGcomprisBoard, key, value);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
py_gcompris_get_profile_from_id (PyObject* self, PyObject* args)
{
......@@ -307,7 +274,6 @@ static PyMethodDef PythonGcomprisAdminModule[] = {
{ "board_run_next", py_board_run_next, METH_VARARGS, "board_run_next" },
{ "board_config_start", py_board_config_start, METH_VARARGS, "board_config_start" },
{ "board_config_stop", py_board_config_stop, METH_VARARGS, "board_config_stop" },
{ "set_board_conf", py_gcompris_set_board_conf, METH_VARARGS, "gcompris_set_board_conf" },
{ "get_profile_from_id", py_gcompris_get_profile_from_id, METH_VARARGS, "gcompris_get_profile_from_id" },
{ "get_profiles_list", py_gcompris_get_profiles_list, METH_VARARGS, "gcompris_get_profiles_list" },
{ "get_user_from_id", py_gcompris_get_user_from_id, METH_VARARGS, "gcompris_get_user_from_id" },
......
......@@ -936,6 +936,39 @@ py_gcompris_get_current_user(PyObject* self, PyObject* args)
}
static PyObject*
py_gcompris_set_board_conf (PyObject* self, PyObject* args)
{
GcomprisConfPair *pair;
PyObject* pyBoard;
PyObject* pyProfile;
pyGcomprisBoardObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
pyGcomprisProfileObject* pyGcomprisProfile;
GcomprisProfile* cGcomprisProfile;
char *key;
char *value;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "OOss:gcompris.set_board_conf",
&pyProfile, &pyBoard,
&key, &value))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
pyGcomprisProfile = (pyGcomprisProfileObject *) pyProfile;
cGcomprisProfile = pyGcomprisProfile->cdata;
cGcomprisBoard = pyGcomprisBoard->cdata;
/* Call the corresponding C function */
gcompris_set_board_conf(cGcomprisProfile, cGcomprisBoard, key, value);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
/****************************************************/
......@@ -977,6 +1010,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "spawn_async", py_gcompris_spawn_async, METH_VARARGS|METH_KEYWORDS, "gcompris_spawn_sync" },
{ "child_watch_add", py_gcompris_child_watch_add, METH_VARARGS|METH_KEYWORDS, "gcompris_child_watch_add" },
{ "get_board_conf", py_gcompris_get_board_conf, METH_VARARGS, "gcompris_get_board_conf" },
{ "set_board_conf", py_gcompris_set_board_conf, METH_VARARGS, "gcompris_set_board_conf" },
{ "get_current_profile", py_gcompris_get_current_profile, METH_VARARGS, "gcompris_get_current_profile" },
{ "get_current_user", py_gcompris_get_current_user, METH_VARARGS, "gcompris_get_current_user" },
{ NULL, NULL, 0, NULL}
......
......@@ -42,9 +42,9 @@ class Board_list:
# area is the drawing area for the list
def __init__(self, canvas, db_connect, db_cursor, area, hgap, vgap):
def __init__(self, db_connect, db_cursor, frame):
self.rootitem = canvas
self.frame = frame
self.cur = db_cursor
self.con = db_connect
......@@ -56,6 +56,36 @@ class Board_list:
self.cur.execute('select * from boards')
self.board_data = self.cur.fetchall()
# Main box is vertical
top_box = gtk.VBox(False, 8)
top_box.show()
self.frame.add(top_box)
# Create the profiles Combo
self.profiles_list = gcompris.admin.get_profiles_list()
print self.profiles_list
box1 = gtk.HBox(False, 0)
box1.show()
top_box.pack_start(box1, False, False, 0)
label = gtk.Label(_('Select a profile:'))
label.show()
box1.pack_start(label,True, False, 0)
combobox = gtk.combo_box_new_text()
combobox.show()
box1.pack_start(combobox, True, False, 0)
for profile in self.profiles_list:
combobox.append_text(profile.name)
combobox.connect('changed', self.changed_cb)
combobox.set_active(0)
self.active_profile = self.profiles_list[0]
print 'Active profile is now', self.active_profile.name
# Create the table
sw = gtk.ScrolledWindow()
sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
......@@ -73,18 +103,11 @@ class Board_list:
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=gtk.FALSE)
#but_height = hgap * 2
#but_width = hgap * 6
top_box.add(sw)
sw.show()
treeview.show()
......@@ -133,6 +156,15 @@ class Board_list:
# button_imp.show()
def changed_cb(self, combobox):
index = combobox.get_active()
self.active_profile = self.profiles_list[index]
print 'Active profile is now', self.active_profile.name
# -------------------
# Board Management
# -------------------
......
......@@ -55,14 +55,14 @@ class Boards(module.Module):
module.Module.start(self)
item = self.rootitem.add (
gnome.canvas.CanvasText,
text=_(self.module_label + " Panel"),
font=gcompris.skin.get_font("gcompris/content"),
x = area[0] + (area[2]-area[0])/2,
y = area[1] + 50,
fill_color="black"
)
# item = self.rootitem.add (
# gnome.canvas.CanvasText,
# text=_(self.module_label + " Panel"),
# font=gcompris.skin.get_font("gcompris/content"),
# x = area[0] + (area[2]-area[0])/2,
# y = area[1] + 50,
# fill_color="black"
# )
boards = []
for board in gcompris.admin.get_boards_list():
......@@ -79,7 +79,7 @@ class Boards(module.Module):
origin_y = area[1]+vgap
boards_height = (area[3]-area[1]) - vgap*2
boards_height = (area[3]-area[1]) - vgap*2
list_area = ( area[0], origin_y, area[2], boards_height)
......@@ -87,9 +87,21 @@ class Boards(module.Module):
self.con = sqlite.connect(gcompris.get_database())
self.cur = self.con.cursor()
board_list.Board_list(self.rootitem,
self.con, self.cur,
list_area, hgap, vgap)
frame = gtk.Frame(_("Boards"))
frame.show()
self.rootitem.add(
gnome.canvas.CanvasWidget,
widget=frame,
x=area[0],
y=area[1],
width=area[2]-area[0],
height=area[3]-area[1],
anchor=gtk.ANCHOR_NW,
size_pixels=False)
board_list.Board_list(self.con, self.cur,
frame)
def stop(self):
print "stopping boards panel"
......
......@@ -41,10 +41,10 @@ class Gcompris_tuxpaint:
pass
def start(self):
line = os.sys.stdin.readline()
while (len(line) >1):
exec(line)
line = os.sys.stdin.readline()
# line = os.sys.stdin.readline()
# while (len(line) >1):
# exec(line)
# line = os.sys.stdin.readline()
Prop = gcompris.get_properties()
......
/* gcompris - gcompris_db.c
*
* Time-stamp: <2005/07/19 01:00:00 yves>
* Time-stamp: <2005/07/19 22:15:03 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -1200,7 +1200,7 @@ GList *gcompris_get_profiles_list()
gchar *request;
int i;
GList *profiles_list;
GList *profiles_list = NULL;
char **result_;
int nrow_;
......@@ -1327,7 +1327,6 @@ GcomprisGroup *gcompris_get_group_from_id(int group_id)
gchar *request;
int i;
GList *users = NULL;
GcomprisGroup *group = NULL;
request = g_strdup_printf(GROUP_FROM_ID(group_id));
......@@ -1374,7 +1373,7 @@ GcomprisGroup *gcompris_get_group_from_id(int group_id)
GList *gcompris_get_groups_list()
{
#ifdef USE_SQLITE
GList *groups_list;
GList *groups_list = NULL;
char *zErrMsg;
char **result;
......@@ -1384,7 +1383,6 @@ GList *gcompris_get_groups_list()
gchar *request;
int i;
GList *users = NULL;
GcomprisGroup *group = NULL;
rc = sqlite3_get_table(gcompris_db,
......@@ -1426,19 +1424,202 @@ GList *gcompris_get_groups_list()
#endif
}
#define BOARDS_READ_FROM_ID(n) \
"SELECT name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards WHERE board_id=%d;",n
GcomprisBoard *gcompris_get_board_from_id(int board_id)
{
#ifdef USE_SQLITE
GcomprisProperties *properties = gcompris_get_properties();
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
int i;
gchar *request;
request = g_strdup_printf(BOARDS_READ_FROM_ID(board_id));
rc = sqlite3_get_table(gcompris_db,
request,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
g_free(request);
/* first ncolumns are columns labels. */
i = ncolumn;
GcomprisBoard *gcomprisBoard = NULL;
gcomprisBoard = g_malloc0 (sizeof (GcomprisBoard));
gcomprisBoard->plugin=NULL;
gcomprisBoard->previous_board=NULL;
gcomprisBoard->board_ready=FALSE;
gcomprisBoard->canvas=canvas;
gcomprisBoard->gmodule = NULL;
gcomprisBoard->gmodule_file = NULL;
/* From DB we have only package_data_dir. */
gcomprisBoard->board_dir = properties->package_data_dir;
/* Fixed since I use the canvas own pixel_per_unit scheme */
gcomprisBoard->width = BOARDWIDTH;
gcomprisBoard->height = BOARDHEIGHT;
gcomprisBoard->board_id = board_id;
gcomprisBoard->name = g_strdup(result[i++]);
gcomprisBoard->section_id = atoi(result[i++]);
gcomprisBoard->section = g_strdup(result[i++]);
gcomprisBoard->author = g_strdup(result[i++]);
gcomprisBoard->type = g_strdup(result[i++]);
gcomprisBoard->mode = g_strdup(result[i++]);
gcomprisBoard->difficulty = g_strdup(result[i++]);
gcomprisBoard->icon_name = g_strdup(result[i++]);
gcomprisBoard->boarddir = g_strdup(result[i++]);
gcomprisBoard->mandatory_sound_file = g_strdup(result[i++]);
gcomprisBoard->mandatory_sound_dataset = g_strdup(result[i++]);
gcomprisBoard->filename = g_strdup(result[i++]);
gcomprisBoard->title = reactivate_newline(gettext(result[i++]));
gcomprisBoard->description = reactivate_newline(gettext(result[i++]));
gcomprisBoard->prerequisite = reactivate_newline(gettext(result[i++]));
gcomprisBoard->goal = reactivate_newline(gettext(result[i++]));
gcomprisBoard->manual = reactivate_newline(gettext(result[i++]));
gcomprisBoard->credit = reactivate_newline(gettext(result[i++]));
sqlite3_free_table(result);
return gcomprisBoard;
#else
return NULL;
#endif
}
#define GET_ALL_USERS \
"SELECT user_id, login, lastname, firstname, birthdate, class_id FROM users;"
GList *gcompris_get_users_list()
{
#ifdef USE_SQLITE
GList *users_list = NULL;
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
gchar *request;
int i;
GcomprisUser *user = NULL;
rc = sqlite3_get_table(gcompris_db,
GET_ALL_USERS,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
if (nrow == 0){
g_warning(_("No users !"));
return NULL;
} else {
i = ncolumn;
while ( i < (nrow +1)*ncolumn) {
user = g_malloc0(sizeof(GcomprisUser));
user->user_id = atoi(result[i++]);
user->login = g_strdup(result[i++]);
user->firstname = g_strdup(result[i++]);
user->lastname = g_strdup(result[i++]);
user->birthdate = g_strdup(result[i++]);
user->class_id = atoi(result[i++]);
users_list = g_list_append(users_list, user);
}
}
return users_list;
#else
return NULL;
#endif
}
#define GET_ALL_CLASSES \
"SELECT class_id, name, teacher, wholegroup_id FROM class;"
GList *gcompris_get_classes_list()
{
#ifdef USE_SQLITE
GList *classes_list;
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
gchar *request;
int i;
GcomprisClass *class = NULL;
rc = sqlite3_get_table(gcompris_db,
GET_ALL_CLASSES,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
if (nrow == 0){
g_warning(_("No groups !"));
return NULL;
} else {
i = ncolumn;
while ( i < (nrow +1)*ncolumn) {
class = g_malloc0(sizeof(GcomprisClass));
class->class_id = atoi(result[i++]);
class->name = g_strdup(result[i++]);
class->description = g_strdup(result[i++]);
class->wholegroup_id = atoi(result[i++]);
classes_list = g_list_append(classes_list, class);
}
}
return classes_list;
#else
return NULL;
#endif
}
/* Local Variables: */
......
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