1
#include "py-gcompris-profile.h"
4
staticforward PyTypeObject pyGcomprisUserType;
6
//static char pyGcomprisUserType_doc[]= "Python GcomprisBoars structure binding";
9
/* Special function created for the python plugin to be able to create
10
* a pyGcomprisBoardObject form the existing GcomprisBoard structure
13
gcompris_new_pyGcomprisUserObject(GcomprisUser* user)
15
pyGcomprisUserObject* theuser = NULL;
17
theuser = PyObject_New(pyGcomprisUserObject, &pyGcomprisUserType);
19
theuser->cdata = user;
21
return (PyObject*)theuser;
25
/* Free the python gcompris user */
27
pyGcomprisUserType_dealloc(pyGcomprisUserObject *self)
34
/* Methods defined in the pyGcomprisUser class */
35
static PyMethodDef pyGcomprisUserType_methods[] = {
36
{NULL, NULL} /* sentinel */
40
/* Return the value of the members contained in the GcomprisUser structure */
42
pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
45
if(strcmp(name,"user_id")==0) return Py_BuildValue("i", self->cdata->user_id);
47
if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
49
if(strcmp(name,"login")==0) return Py_BuildValue("s", self->cdata->login);
51
if(strcmp(name,"lastname")==0) return Py_BuildValue("s", self->cdata->lastname);
53
if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
55
if(strcmp(name,"birthdate")==0) return Py_BuildValue("s", self->cdata->birthdate);
57
if(strcmp(name,"session_id")==0) return Py_BuildValue("i", self->cdata->session_id);
59
return Py_FindMethod(pyGcomprisUserType_methods, (PyObject *)self, name);
62
/* Set the value of a GcomprisUser structure member */
64
pyGcomprisUserType_setattr(pyGcomprisUserObject *self, char *name, PyObject *v)
66
if (self->cdata==NULL) return -1;
67
if (v==NULL) return -1;
69
/* if (strcmp(name,"level")==0){
70
value = (int) PyInt_AsLong(v);
71
if ( value < 0 ) return -1;
72
self->cdata->level=value;
75
/* members are supposed to be read only */
80
static PyTypeObject pyGcomprisUserType = {
82
PyObject_HEAD_INIT(NULL)
84
PyObject_HEAD_INIT(&PyType_Type)
87
"pyGcomprisUser", /*tp_name*/
88
sizeof(pyGcomprisUserObject), /*tp_basicsize*/
91
(destructor)pyGcomprisUserType_dealloc, /*tp_dealloc*/
93
(getattrfunc)pyGcomprisUserType_getattr, /*tp_getattr*/
94
(setattrfunc)pyGcomprisUserType_setattr, /*tp_setattr*/