Back to index

gcompris  8.2.2
py-gcompris-profile.c
Go to the documentation of this file.
00001 #include "py-gcompris-profile.h"
00002 #include <pygobject.h>
00003 
00004 staticforward PyTypeObject pyGcomprisProfileType;
00005 
00006 //static char pyGcomprisProfileType_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_pyGcomprisProfileObject(GcomprisProfile* profile)
00014 {
00015   if (!profile)
00016     return Py_None;
00017 
00018   pyGcomprisProfileObject* theprofile = NULL;
00019 
00020   theprofile = PyObject_New(pyGcomprisProfileObject, &pyGcomprisProfileType);
00021   if (theprofile!=NULL)
00022     theprofile->cdata = profile;
00023 
00024   return (PyObject*)theprofile;
00025 }
00026 
00027 
00028 /* Free the python gcompris profile */
00029 static void
00030 pyGcomprisProfileType_dealloc(pyGcomprisProfileObject *self)
00031 {
00032   self->cdata = NULL;
00033   PyObject_DEL(self);
00034 }
00035 
00036 
00037 /* Methods defined in the pyGcomprisProfile class */
00038 static PyMethodDef pyGcomprisProfileType_methods[] = {
00039         {NULL,          NULL}           /* sentinel */
00040 };
00041 
00042 
00043 /* Return the value of the members contained in the GcomprisProfile structure */
00044 static PyObject *
00045 pyGcomprisProfileType_getattr(pyGcomprisProfileObject *self, char *name)
00046 {
00047     /* int */
00048     if(strcmp(name,"profile_id")==0) return Py_BuildValue("i", self->cdata->profile_id);
00049     /* int */
00050     if(strcmp(name,"name")==0) return Py_BuildValue("s", self->cdata->name);
00051     /* int */
00052     if(strcmp(name,"directory")==0) return Py_BuildValue("s", self->cdata->directory);
00053     /* int */
00054     if(strcmp(name,"description")==0) return Py_BuildValue("s", self->cdata->description);
00055 
00056     /* list */
00057     if(strcmp(name,"group_ids")==0){
00058       PyObject *pylist;
00059       GList *list;
00060 
00061       pylist = PyList_New(0);
00062       for (list = self->cdata->group_ids; list !=NULL; list = list->next)
00063        PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
00064 
00065       return pylist;
00066     }
00067 
00068     /* list */
00069     if(strcmp(name,"activities")==0){
00070       PyObject *pylist;
00071       GList *list;
00072 
00073       pylist = PyList_New(0);
00074       for (list = self->cdata->activities; list !=NULL; list = list->next)
00075        PyList_Append(pylist, Py_BuildValue("i", *((int *)list->data)));
00076 
00077       return pylist;
00078     }
00079 
00080   return Py_FindMethod(pyGcomprisProfileType_methods, (PyObject *)self, name);
00081 }
00082 
00083 /* Set the value of a GcomprisProfile structure member */
00084 static int
00085 pyGcomprisProfileType_setattr(pyGcomprisProfileObject *self, char *name, PyObject *v)
00086 {
00087   if (self->cdata==NULL) return -1;
00088   if (v==NULL) return -1;
00089 
00090   /*  if (strcmp(name,"level")==0){
00091     value = (int) PyInt_AsLong(v);
00092     if ( value < 0 ) return -1;
00093     self->cdata->level=value;
00094     return 0;
00095     } */
00096   /* members are supposed to be read only */
00097 
00098   return -1;
00099 }
00100 
00101 static PyTypeObject pyGcomprisProfileType = {
00102 #if defined(WIN32)
00103   PyObject_HEAD_INIT(NULL)
00104 #else /* ! WIN32 */
00105   PyObject_HEAD_INIT(&PyType_Type)
00106 #endif
00107   0,                                        /*ob_size*/
00108   "pyGcomprisProfile",                        /*tp_name*/
00109   sizeof(pyGcomprisProfileObject),            /*tp_basicsize*/
00110   0,                                        /*tp_itemsize*/
00111   /* methods */
00112   (destructor)pyGcomprisProfileType_dealloc,  /*tp_dealloc*/
00113   0,                                        /*tp_print*/
00114   (getattrfunc)pyGcomprisProfileType_getattr, /*tp_getattr*/
00115   (setattrfunc)pyGcomprisProfileType_setattr, /*tp_setattr*/
00116   0,                                        /*tp_compare*/
00117   0,                                        /*tp_repr*/
00118   0,                                        /*tp_as_number*/
00119   0,                                        /*tp_as_sequence*/
00120   0,                                        /*tp_as_mapping*/
00121   0,                                        /*tp_hash*/
00122 };