Commit 3e7e2c99 authored by Yves Combe's avatar Yves Combe
Browse files

add some administration usefull function.

add gcompris.admin submodule for them.
some fonction are empty for now.
parent 0f9a7628
2005-07-18 Yves Combe <yves@ycombe.net>
add some administration usefull function.
add gcompris.admin submodule for them.
some fonction are empty for now.
* configure.in:
* src/boards/Makefile.am:
* src/boards/py-gcompris-class.c:
(gcompris_new_pyGcomprisClassObject),
(pyGcomprisClassType_dealloc), (pyGcomprisClassType_getattr),
(pyGcomprisClassType_setattr):
* src/boards/py-gcompris-group.c:
(gcompris_new_pyGcomprisGroupObject),
(pyGcomprisGroupType_dealloc), (pyGcomprisGroupType_getattr),
(pyGcomprisGroupType_setattr):
* src/boards/py-gcompris-user.c:
(gcompris_new_pyGcomprisUserObject), (pyGcomprisUserType_dealloc),
(pyGcomprisUserType_getattr), (pyGcomprisUserType_setattr):
* src/boards/py-mod-admin.c: (py_board_run_next),
(py_board_config_start), (py_board_config_stop),
(py_gcompris_get_boards_list), (py_gcompris_set_board_conf),
(py_gcompris_get_profile_from_id), (py_gcompris_get_board_from_id),
(py_gcompris_get_group_from_id), (py_gcompris_get_user_from_id),
(py_gcompris_get_class_from_id), (py_gcompris_get_profiles_list),
(py_gcompris_get_users_list), (py_gcompris_get_groups_list),
(py_gcompris_get_classes_list),
(python_gcompris_admin_module_init):
* src/boards/py-mod-admin.h:
* src/boards/py-mod-gcompris.c: (py_gcompris_get_board_conf),
(py_gcompris_get_current_profile), (py_gcompris_get_current_user),
(python_gcompris_module_init):
* src/boards/python/gcompris/Makefile.am:
* src/boards/python/tuxpaint.py:
* src/gcompris/gcompris_db.c: (gcompris_load_menus_db),
(gcompris_get_profile_from_id), (gcompris_db_get_profile),
(gcompris_get_class_from_id), (gcompris_get_board_conf),
(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):
* src/gcompris/gcompris_db.h:
* src/gcompris/profile.c: (gcompris_get_current_profile),
(gcompris_set_current_user), (gcompris_get_current_user):
* src/gcompris/profile.h:
2005-07-13 Bruno coudoin <bruno.coudoin@free.fr>
Reworked the class module to use a single canvas item
......
......@@ -497,6 +497,7 @@ src/gcompris/libgcompris-1.0-uninstalled.pc
src/boards/Makefile
src/boards/python/Makefile
src/boards/python/gcompris/Makefile
src/boards/python/gcompris/admin/Makefile
src/boards/python/gcompris/anim/Makefile
src/boards/python/gcompris/bonus/Makefile
src/boards/python/gcompris/score/Makefile
......
......@@ -235,9 +235,12 @@ libpython_la_SOURCES = python.c \
py-gcompris-board.c py-gcompris-board.h \
py-gcompris-properties.c py-gcompris-properties.h \
py-gcompris-profile.c py-gcompris-profile.h \
py-gcompris-user.cy \
py-gcompris-user.c \
py-gcompris-class.c \
py-gcompris-group.c \
py-mod-gcompris.c py-mod-gcompris.h \
py-mod-utils.c py-mod-utils.h \
py-mod-admin.c py-mod-admin.h \
py-mod-bonus.c py-mod-bonus.h \
py-mod-score.c py-mod-score.h \
py-mod-timer.c py-mod-timer.h \
......
#include "py-gcompris-profile.h"
#include <pygobject.h>
staticforward PyTypeObject pyGcomprisClassType;
//static char pyGcomprisClassType_doc[]= "Python GcomprisBoars structure binding";
/* Special function created for the python plugin to be able to create
* a pyGcomprisBoardObject form the existing GcomprisBoard structure
*/
PyObject*
gcompris_new_pyGcomprisClassObject(GcomprisClass* class)
{
pyGcomprisClassObject* theclass = NULL;
theclass = PyObject_New(pyGcomprisClassObject, &pyGcomprisClassType);
if (theclass!=NULL)
theclass->cdata = class;
return (PyObject*)theclass;
}
/* Free the python gcompris class */
static void
pyGcomprisClassType_dealloc(pyGcomprisClassObject *self)
{
self->cdata = NULL;
PyObject_DEL(self);
}
/* Methods defined in the pyGcomprisClass class */
static PyMethodDef pyGcomprisClassType_methods[] = {
{NULL, NULL} /* sentinel */
};
/* Return the value of the members contained in the GcomprisClass structure */
static PyObject *
pyGcomprisClassType_getattr(pyGcomprisClassObject *self, char *name)
{
/* int */
if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
/* int */
if(strcmp(name,"name")==0) return Py_BuildValue("s", self->cdata->name);
/* int */
if(strcmp(name,"wholegroup_id")==0) return Py_BuildValue("i", self->cdata->wholegroup_id);
/* int */
if(strcmp(name,"description")==0) return Py_BuildValue("s", self->cdata->description);
/* list */
if(strcmp(name,"group_ids")==0){
PyObject *pylist;
GList *list;
pylist = PyList_New(0);
for (list = self->cdata->group_ids; list !=NULL; list = list->next)
PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
return pylist;
}
/* list */
if(strcmp(name,"user_ids")==0){
PyObject *pylist;
GList *list;
pylist = PyList_New(0);
for (list = self->cdata->user_ids; list !=NULL; list = list->next)
PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
return pylist;
}
return Py_FindMethod(pyGcomprisClassType_methods, (PyObject *)self, name);
}
/* Set the value of a GcomprisClass structure member */
static int
pyGcomprisClassType_setattr(pyGcomprisClassObject *self, char *name, PyObject *v)
{
int value;
if (self->cdata==NULL) return -1;
if (v==NULL) return -1;
/* if (strcmp(name,"level")==0){
value = (int) PyInt_AsLong(v);
if ( value < 0 ) return -1;
self->cdata->level=value;
return 0;
} */
/* members are supposed to be read only */
return -1;
}
static PyTypeObject pyGcomprisClassType = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"pyGcomprisClass", /*tp_name*/
sizeof(pyGcomprisClassObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)pyGcomprisClassType_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)pyGcomprisClassType_getattr, /*tp_getattr*/
(setattrfunc)pyGcomprisClassType_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
#include "py-gcompris-profile.h"
#include <pygobject.h>
staticforward PyTypeObject pyGcomprisGroupType;
//static char pyGcomprisGroupType_doc[]= "Python GcomprisBoars structure binding";
/* Special function created for the python plugin to be able to create
* a pyGcomprisBoardObject form the existing GcomprisBoard structure
*/
PyObject*
gcompris_new_pyGcomprisGroupObject(GcomprisGroup* group)
{
pyGcomprisGroupObject* thegroup = NULL;
thegroup = PyObject_New(pyGcomprisGroupObject, &pyGcomprisGroupType);
if (thegroup!=NULL)
thegroup->cdata = group;
return (PyObject*)thegroup;
}
/* Free the python gcompris group */
static void
pyGcomprisGroupType_dealloc(pyGcomprisGroupObject *self)
{
self->cdata = NULL;
PyObject_DEL(self);
}
/* Methods defined in the pyGcomprisGroup class */
static PyMethodDef pyGcomprisGroupType_methods[] = {
{NULL, NULL} /* sentinel */
};
/* Return the value of the members contained in the GcomprisGroup structure */
static PyObject *
pyGcomprisGroupType_getattr(pyGcomprisGroupObject *self, char *name)
{
/* int */
if(strcmp(name,"group_id")==0) return Py_BuildValue("i", self->cdata->group_id);
/* int */
if(strcmp(name,"name")==0) return Py_BuildValue("s", self->cdata->name);
/* string */
if(strcmp(name,"description")==0) return Py_BuildValue("s", self->cdata->description);
/* int */
if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
/* list */
if(strcmp(name,"user_ids")==0){
PyObject *pylist;
GList *list;
pylist = PyList_New(0);
for (list = self->cdata->user_ids; list !=NULL; list = list->next)
PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
return pylist;
}
return Py_FindMethod(pyGcomprisGroupType_methods, (PyObject *)self, name);
}
/* Set the value of a GcomprisGroup structure member */
static int
pyGcomprisGroupType_setattr(pyGcomprisGroupObject *self, char *name, PyObject *v)
{
int value;
if (self->cdata==NULL) return -1;
if (v==NULL) return -1;
/* if (strcmp(name,"level")==0){
value = (int) PyInt_AsLong(v);
if ( value < 0 ) return -1;
self->cdata->level=value;
return 0;
} */
/* members are supposed to be read only */
return -1;
}
static PyTypeObject pyGcomprisGroupType = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"pyGcomprisGroup", /*tp_name*/
sizeof(pyGcomprisGroupObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)pyGcomprisGroupType_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)pyGcomprisGroupType_getattr, /*tp_getattr*/
(setattrfunc)pyGcomprisGroupType_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
#include "py-gcompris-profile.h"
#include <pygobject.h>
staticforward PyTypeObject pyGcomprisUserType;
//static char pyGcomprisUserType_doc[]= "Python GcomprisBoars structure binding";
/* Special function created for the python plugin to be able to create
* a pyGcomprisBoardObject form the existing GcomprisBoard structure
*/
PyObject*
gcompris_new_pyGcomprisUserObject(GcomprisUser* user)
{
pyGcomprisUserObject* theuser = NULL;
theuser = PyObject_New(pyGcomprisUserObject, &pyGcomprisUserType);
if (theuser!=NULL)
theuser->cdata = user;
return (PyObject*)theuser;
}
/* Free the python gcompris user */
static void
pyGcomprisUserType_dealloc(pyGcomprisUserObject *self)
{
self->cdata = NULL;
PyObject_DEL(self);
}
/* Methods defined in the pyGcomprisUser class */
static PyMethodDef pyGcomprisUserType_methods[] = {
{NULL, NULL} /* sentinel */
};
/* Return the value of the members contained in the GcomprisUser structure */
static PyObject *
pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
{
/* int */
if(strcmp(name,"user_id")==0) return Py_BuildValue("i", self->cdata->user_id);
/* int */
if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
/* str */
if(strcmp(name,"lastname")==0) return Py_BuildValue("s", self->cdata->lastname);
/* str */
if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
/* str */
if(strcmp(name,"birthdate")==0) return Py_BuildValue("s", self->cdata->birthdate);
return Py_FindMethod(pyGcomprisUserType_methods, (PyObject *)self, name);
}
/* Set the value of a GcomprisUser structure member */
static int
pyGcomprisUserType_setattr(pyGcomprisUserObject *self, char *name, PyObject *v)
{
int value;
if (self->cdata==NULL) return -1;
if (v==NULL) return -1;
/* if (strcmp(name,"level")==0){
value = (int) PyInt_AsLong(v);
if ( value < 0 ) return -1;
self->cdata->level=value;
return 0;
} */
/* members are supposed to be read only */
return -1;
}
static PyTypeObject pyGcomprisUserType = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*ob_size*/
"pyGcomprisUser", /*tp_name*/
sizeof(pyGcomprisUserObject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
(destructor)pyGcomprisUserType_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(getattrfunc)pyGcomprisUserType_getattr, /*tp_getattr*/
(setattrfunc)pyGcomprisUserType_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash*/
};
#include <Python.h>
#include <pygobject.h>
#include "gcompris/gcompris.h"
#include "py-mod-admin.h"
#include "py-gcompris-board.h"
#include "py-gcompris-profile.h"
/* All functions provided by this python module
* wraps a gcompris function. Each "py_*" function wraps the
* "*" C function.
*/
static PyObject*
py_board_run_next (PyObject* self, PyObject* args)
{
PyObject* pyObject;
pyGcomprisBoardObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:board_run_next", &pyObject))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject*) pyObject;
cGcomprisBoard = pyGcomprisBoard->cdata;
/* Call the corresponding C function */
board_run_next(cGcomprisBoard);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
py_board_config_start (PyObject* self, PyObject* args)
{
PyObject* pyBoard;
PyObject* pyCanvasGroup;
pyGcomprisBoardObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
GnomeCanvasGroup *canvasgroup;
int x, y, width, height;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "OOiiii:board_config_start", &pyBoard,
&pyCanvasGroup, &x, &y, &width, &height))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject*) pyBoard;
cGcomprisBoard = pyGcomprisBoard->cdata;
canvasgroup = (GnomeCanvasGroup*) pygobject_get(pyCanvasGroup);
/* Call the corresponding C function */
board_config_start(cGcomprisBoard, canvasgroup, x, y, width, height);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
py_board_config_stop (PyObject* self, PyObject* args)
{
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.board_config_stop"))
return NULL;
/* Call the corresponding C function */
board_config_stop();
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
static PyObject*
py_gcompris_get_boards_list (PyObject* self, PyObject* args)
{
GList *boards_list;
GList *list;
PyObject *pylist;
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_boards_list"))
return NULL;
/* Call the corresponding C function */
boards_list = gcompris_get_boards_list();
pylist = PyList_New(0);
for (list = boards_list; list != NULL; list = list->next){
PyList_Append(pylist, gcompris_new_pyGcomprisBoardObject((GcomprisBoard*) list->data));
}
/* Create and return the result */
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)
{
GcomprisProfile *profile;
int profile_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris.get_profile_from_id", &profile_id))
return NULL;
/* Call the corresponding C function */
profile = gcompris_get_profile_from_id (profile_id);
/* Create and return the result */
return gcompris_new_pyGcomprisProfileObject(profile) ;
}
static PyObject*
py_gcompris_get_board_from_id (PyObject* self, PyObject* args)
{
GcomprisBoard *board;
int board_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris.get_board_from_id", &board_id))
return NULL;
/* Call the corresponding C function */
board = gcompris_get_board_from_id (board_id);
/* Create and return the result */
return gcompris_new_pyGcomprisBoardObject(board) ;
}
static PyObject*
py_gcompris_get_group_from_id (PyObject* self, PyObject* args)
{
GcomprisGroup *group;
int group_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris.get_group_from_id", &group_id))
return NULL;
/* Call the corresponding C function */
group = gcompris_get_group_from_id (group_id);
/* Create and return the result */
return gcompris_new_pyGcomprisGroupObject(group) ;
}
static PyObject*
py_gcompris_get_user_from_id (PyObject* self, PyObject* args)
{
GcomprisUser *user;
int user_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris.get_user_from_id", &user_id))
return NULL;
/* Call the corresponding C function */
user = gcompris_get_user_from_id (user_id);
/* Create and return the result */
return gcompris_new_pyGcomprisUserObject(user) ;
}
static PyObject*
py_gcompris_get_class_from_id (PyObject* self, PyObject* args)
{
GcomprisClass *class;
int class_id;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris.get_class_from_id", &class_id))
return NULL;
/* Call the corresponding C function */
class = gcompris_get_class_from_id (class_id);
/* Create and return the result */
return gcompris_new_pyGcomprisClassObject(class) ;
}
static PyObject*
py_gcompris_get_profiles_list (PyObject* self, PyObject* args)
{
GList *profiles_list;
GList *list;
PyObject *pylist;
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_profiles_list"))
return NULL;
/* Call the corresponding C function */
profiles_list = gcompris_get_profiles_list();