Back to index

gcompris  8.2.2
py-gcompris-group.c
Go to the documentation of this file.
00001 #include "py-gcompris-profile.h"
00002 #include <pygobject.h>
00003 
00004 staticforward PyTypeObject pyGcomprisGroupType;
00005 
00006 //static char pyGcomprisGroupType_doc[]= "Python GcomprisBoars structure binding";
00007 
00008 
00009 /* Special function created for the python plugin to be able to create
00010  * a pyGcomprisBoardObject form the existing GcomprisBoard structure
00011  */
00012 PyObject*
00013 gcompris_new_pyGcomprisGroupObject(GcomprisGroup* group)
00014 {
00015   pyGcomprisGroupObject* thegroup = NULL;
00016 
00017   thegroup = PyObject_New(pyGcomprisGroupObject, &pyGcomprisGroupType);
00018   if (thegroup!=NULL)
00019     thegroup->cdata = group;
00020 
00021   return (PyObject*)thegroup;
00022 }
00023 
00024 
00025 /* Free the python gcompris group */
00026 static void
00027 pyGcomprisGroupType_dealloc(pyGcomprisGroupObject *self)
00028 {
00029   self->cdata = NULL;
00030   PyObject_DEL(self);
00031 }
00032 
00033 
00034 /* Methods defined in the pyGcomprisGroup class */
00035 static PyMethodDef pyGcomprisGroupType_methods[] = {
00036         {NULL,          NULL}           /* sentinel */
00037 };
00038 
00039 
00040 /* Return the value of the members contained in the GcomprisGroup structure */
00041 static PyObject *
00042 pyGcomprisGroupType_getattr(pyGcomprisGroupObject *self, char *name)
00043 {
00044     /* int */
00045     if(strcmp(name,"group_id")==0) return Py_BuildValue("i", self->cdata->group_id);
00046     /* int */
00047     if(strcmp(name,"name")==0) return Py_BuildValue("s", self->cdata->name);
00048     /* string */
00049     if(strcmp(name,"description")==0) return Py_BuildValue("s", self->cdata->description);
00050     /* int */
00051     if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
00052 
00053     /* list */
00054     if(strcmp(name,"user_ids")==0){
00055       PyObject *pylist;
00056       GList *list;
00057 
00058       pylist = PyList_New(0);
00059       for (list = self->cdata->user_ids; list !=NULL; list = list->next)
00060        PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
00061 
00062       return pylist;
00063     }
00064 
00065   return Py_FindMethod(pyGcomprisGroupType_methods, (PyObject *)self, name);
00066 }
00067 
00068 /* Set the value of a GcomprisGroup structure member */
00069 static int
00070 pyGcomprisGroupType_setattr(pyGcomprisGroupObject *self, char *name, PyObject *v)
00071 {
00072   if (self->cdata==NULL) return -1;
00073   if (v==NULL) return -1;
00074 
00075   /*  if (strcmp(name,"level")==0){
00076     value = (int) PyInt_AsLong(v);
00077     if ( value < 0 ) return -1;
00078     self->cdata->level=value;
00079     return 0;
00080     } */
00081   /* members are supposed to be read only */
00082 
00083   return -1;
00084 }
00085 
00086 static PyTypeObject pyGcomprisGroupType = {
00087 #if defined(WIN32)
00088   PyObject_HEAD_INIT(NULL)
00089 #else /* ! WIN32 */
00090   PyObject_HEAD_INIT(&PyType_Type)
00091 #endif
00092   0,                                        /*ob_size*/
00093   "pyGcomprisGroup",                        /*tp_name*/
00094   sizeof(pyGcomprisGroupObject),            /*tp_basicsize*/
00095   0,                                        /*tp_itemsize*/
00096   /* methods */
00097   (destructor)pyGcomprisGroupType_dealloc,  /*tp_dealloc*/
00098   0,                                        /*tp_print*/
00099   (getattrfunc)pyGcomprisGroupType_getattr, /*tp_getattr*/
00100   (setattrfunc)pyGcomprisGroupType_setattr, /*tp_setattr*/
00101   0,                                        /*tp_compare*/
00102   0,                                        /*tp_repr*/
00103   0,                                        /*tp_as_number*/
00104   0,                                        /*tp_as_sequence*/
00105   0,                                        /*tp_as_mapping*/
00106   0,                                        /*tp_hash*/
00107 };