Back to index

gcompris  8.2.2
py-gcompris-properties.c
Go to the documentation of this file.
00001 #include "py-gcompris-properties.h"
00002 #include <pygobject.h>
00003 #include "py-gcompris-profile.h"
00004 #include "py-gcompris-board.h"
00005 
00006 staticforward PyTypeObject pyGcomprisPropertiesType;
00007 
00008 //static char pyGcomprisPropertiesType_doc[]= "Python GcomprisBoars structure binding";
00009 
00010 
00011 /* Special function created for the python plugin to be able to create
00012  * a pyGcomprisBoardObject form the existing GcomprisBoard structure
00013  */
00014 PyObject*
00015 gcompris_new_pyGcomprisPropertiesObject(GcomprisProperties* properties)
00016 {
00017   pyGcomprisPropertiesObject* theproperties = NULL;
00018 
00019   theproperties = PyObject_New(pyGcomprisPropertiesObject, &pyGcomprisPropertiesType);
00020   if (theproperties!=NULL)
00021     theproperties->cdata = properties;
00022 
00023   return (PyObject*)theproperties;
00024 }
00025 
00026 
00027 /* Free the python gcompris properties */
00028 static void
00029 pyGcomprisPropertiesType_dealloc(pyGcomprisPropertiesObject *self)
00030 {
00031   self->cdata = NULL;
00032   PyObject_DEL(self);
00033 }
00034 
00035 
00036 /* Methods defined in the pyGcomprisProperties class */
00037 static PyMethodDef pyGcomprisPropertiesType_methods[] = {
00038         {NULL,          NULL}           /* sentinel */
00039 };
00040 
00041 
00042 /* Return the value of the members contained in the GcomprisProperties structure */
00043 static PyObject *
00044 pyGcomprisPropertiesType_getattr(pyGcomprisPropertiesObject *self, char *name)
00045 {
00046   if (self->cdata != NULL) {
00047     /* Properties type */
00048     if(strcmp(name,"music")==0){
00049       if(self->cdata->music){
00050        Py_INCREF(Py_True);
00051        return Py_True;
00052       } else {
00053        Py_INCREF(Py_False);
00054        return Py_False;
00055       }
00056     }
00057     if(strcmp(name,"fx")==0){
00058       if(self->cdata->fx){
00059        Py_INCREF(Py_True);
00060        return Py_True;
00061       } else {
00062        Py_INCREF(Py_False);
00063        return Py_False;
00064       }
00065     }
00066     if(strcmp(name,"fullscreen")==0){
00067       if(self->cdata->fullscreen){
00068        Py_INCREF(Py_True);
00069        return Py_True;
00070       } else {
00071        Py_INCREF(Py_False);
00072        return Py_False;
00073       }
00074     }
00075     if(strcmp(name,"noxf86vm")==0){
00076       if(self->cdata->noxf86vm){
00077        Py_INCREF(Py_True);
00078        return Py_True;
00079       } else {
00080        Py_INCREF(Py_False);
00081        return Py_False;
00082       }
00083     }
00084     /* enum */
00085     if(strcmp(name,"screensize")==0) return Py_BuildValue("i", self->cdata->screensize);
00086 
00087     /* enum */
00088     if(strcmp(name,"defaultcursor")==0) return Py_BuildValue("i", self->cdata->defaultcursor);
00089 
00090     if(strcmp(name,"timer")==0) return Py_BuildValue("i", self->cdata->timer);
00091 
00092     /* enum */
00093     if(strcmp(name,"filter_style")==0) return Py_BuildValue("i", self->cdata->filter_style);
00094 
00095     if(strcmp(name,"difficulty_filter")==0) return Py_BuildValue("i", self->cdata->difficulty_filter);
00096     if(strcmp(name,"difficulty_max")==0) return Py_BuildValue("i", self->cdata->difficulty_max);
00097     if(strcmp(name,"root_menu")==0) return Py_BuildValue("s", self->cdata->root_menu);
00098     if(strcmp(name,"local_directory")==0) return Py_BuildValue("s", self->cdata->local_directory);
00099     if(strcmp(name,"package_data_dir")==0) return Py_BuildValue("s", self->cdata->package_data_dir);
00100     if(strcmp(name,"locale")==0) return Py_BuildValue("s", self->cdata->locale);
00101     if(strcmp(name,"skin")==0) return Py_BuildValue("s", self->cdata->skin);
00102     if(strcmp(name,"shared_dir")==0) return Py_BuildValue("s", self->cdata->shared_dir);
00103     if(strcmp(name,"users_dir")==0) return Py_BuildValue("s", self->cdata->users_dir);
00104 
00105     if(strcmp(name,"profile")==0){
00106       if (self->cdata->profile)
00107        return gcompris_new_pyGcomprisProfileObject(self->cdata->profile);
00108       else {
00109        Py_INCREF(Py_None);
00110        return Py_None;
00111       }
00112     }
00113 
00114     if(strcmp(name,"logged_user")==0) {
00115       if (self->cdata->logged_user)
00116        return gcompris_new_pyGcomprisUserObject(self->cdata->logged_user);
00117       else {
00118        Py_INCREF(Py_None);
00119        return Py_None;
00120       }
00121     }
00122 
00123     if(strcmp(name,"menu_board")==0) {
00124       if (self->cdata->menu_board)
00125        return gcompris_new_pyGcomprisBoardObject(self->cdata->menu_board);
00126       else {
00127        Py_INCREF(Py_None);
00128        return Py_None;
00129       }
00130     }
00131 
00132     if(strcmp(name,"database")==0) return Py_BuildValue("s", self->cdata->database);
00133     if(strcmp(name,"administration")==0){
00134       if(self->cdata->administration){
00135        Py_INCREF(Py_True);
00136        return Py_True;
00137       } else {
00138        Py_INCREF(Py_False);
00139        return Py_False;
00140       }
00141     }
00142     if(strcmp(name,"reread_menu")==0){
00143       if(self->cdata->reread_menu){
00144        Py_INCREF(Py_True);
00145        return Py_True;
00146       } else {
00147        Py_INCREF(Py_False);
00148        return Py_False;
00149       }
00150     }
00151 
00152     if(strcmp(name,"context")==0){
00153       if (self->cdata->context)
00154        return (PyObject*) pygobject_new((GObject*)self->cdata->context);
00155       else {
00156        Py_INCREF(Py_None);
00157        return Py_None;
00158       }
00159     }
00160 
00161     if(strcmp(name,"default_context")==0) return Py_BuildValue("s", self->cdata->default_context);
00162 
00163   }
00164   return Py_FindMethod(pyGcomprisPropertiesType_methods, (PyObject *)self, name);
00165 }
00166 
00167 /* Set the value of a GcomprisProperties structure member */
00168 static int
00169 pyGcomprisPropertiesType_setattr(pyGcomprisPropertiesObject *self, char *name, PyObject *v)
00170 {
00171   if (self->cdata==NULL) return -1;
00172   if (v==NULL) return -1;
00173 
00174   /*  if (strcmp(name,"level")==0){
00175     value = (int) PyInt_AsLong(v);
00176     if ( value < 0 ) return -1;
00177     self->cdata->level=value;
00178     return 0;
00179     } */
00180   /* members are supposed to be read only */
00181 
00182   return -1;
00183 }
00184 
00185 static PyTypeObject pyGcomprisPropertiesType = {
00186 #if defined(WIN32)
00187   PyObject_HEAD_INIT(NULL)
00188 #else /* ! WIN32 */
00189   PyObject_HEAD_INIT(&PyType_Type)
00190 #endif
00191   0,                                        /*ob_size*/
00192   "pyGcomprisProperties",                        /*tp_name*/
00193   sizeof(pyGcomprisPropertiesObject),            /*tp_basicsize*/
00194   0,                                        /*tp_itemsize*/
00195   /* methods */
00196   (destructor)pyGcomprisPropertiesType_dealloc,  /*tp_dealloc*/
00197   0,                                        /*tp_print*/
00198   (getattrfunc)pyGcomprisPropertiesType_getattr, /*tp_getattr*/
00199   (setattrfunc)pyGcomprisPropertiesType_setattr, /*tp_setattr*/
00200   0,                                        /*tp_compare*/
00201   0,                                        /*tp_repr*/
00202   0,                                        /*tp_as_number*/
00203   0,                                        /*tp_as_sequence*/
00204   0,                                        /*tp_as_mapping*/
00205   0,                                        /*tp_hash*/
00206 };