Back to index

gcompris  8.2.2
py-mod-bonus.c
Go to the documentation of this file.
00001 #include <Python.h>
00002 #include <pygobject.h>
00003 #include "gcompris/gcompris.h"
00004 #include "py-mod-bonus.h"
00005 #include "py-gcompris-board.h"
00006 
00007 /* All functions provided by this python module
00008  * wraps a gcompris function. Each "py_*" function wraps the
00009  * "*" C function.
00010  */
00011 
00012 /* void       gc_bonus_display(int gamewon, int bonus_id); */
00013 static PyObject*
00014 py_gc_bonus_display(PyObject* self, PyObject* args)
00015 {
00016   int gamewon;
00017   int bonus_id;
00018   /* Parse arguments */
00019   if(!PyArg_ParseTuple(args, "ii:gc_bonus_display", &gamewon, &bonus_id))
00020     return NULL;
00021 
00022   /* Call the corresponding C function */
00023   gc_bonus_display(gamewon, bonus_id);
00024 
00025   /* Create and return the result */
00026   Py_INCREF(Py_None);
00027   return Py_None;
00028 }
00029 
00030 
00031 /* void gc_bonus_end_display(int type); */
00032 static PyObject*
00033 py_gcompris_gc_bonus_end_display(PyObject* self, PyObject* args)
00034 {
00035   int type;
00036   /* Parse arguments */
00037   if(!PyArg_ParseTuple(args, "i:gc_bonus_end_display", &type))
00038     return NULL;
00039 
00040   /* Call the corresponding C function */
00041   gc_bonus_end_display(type);
00042 
00043   /* Create and return the result */
00044   Py_INCREF(Py_None);
00045   return Py_None;
00046 }
00047 
00048 
00049 static PyMethodDef PythonGcomprisBonusModule[] = {
00050   { "display",  py_gc_bonus_display, METH_VARARGS, "gc_bonus_display" },
00051   { "board_finished",  py_gcompris_gc_bonus_end_display, METH_VARARGS, "gc_bonus_end_display" },
00052   { NULL, NULL, 0, NULL}
00053 };
00054 
00055 void python_gcompris_bonus_module_init(void)
00056 {
00057   PyObject* module;
00058   module = Py_InitModule("_gcompris_bonus", PythonGcomprisBonusModule);
00059 
00060   /* Misc constants */
00061   PyModule_AddIntConstant(module, "TIME_CLICK_TO", TIME_CLICK_TO_BONUS );
00062 
00063   /* BonusList constants */
00064   PyModule_AddIntConstant(module, "RANDOM", BONUS_RANDOM );
00065   PyModule_AddIntConstant(module, "SMILEY", BONUS_SMILEY );
00066   PyModule_AddIntConstant(module, "FLOWER", BONUS_FLOWER );
00067   PyModule_AddIntConstant(module, "TUX",    BONUS_TUX );
00068   PyModule_AddIntConstant(module, "GNU",    BONUS_GNU );
00069 
00070   /* BonusFinishedList constants */
00071   PyModule_AddIntConstant(module, "FINISHED_RANDOM", BOARD_FINISHED_RANDOM );
00072   PyModule_AddIntConstant(module, "FINISHED_TUXPLANE", BOARD_FINISHED_TUXPLANE );
00073   PyModule_AddIntConstant(module, "FINISHED_TUXLOCO", BOARD_FINISHED_TUXLOCO );
00074   PyModule_AddIntConstant(module, "FINISHED_TOOMANYERRORS", BOARD_FINISHED_TOOMANYERRORS );
00075 
00076   /* BonusStatusList constants */
00077   PyModule_AddIntConstant(module, "LOOSE", BOARD_LOOSE );
00078   PyModule_AddIntConstant(module, "WIN",   BOARD_WIN );
00079   PyModule_AddIntConstant(module, "DRAW",  BOARD_DRAW );
00080 }
00081 
00082 /* Some usefull code parts ... */
00083 /*
00084 static PyObject*
00085 py_gcompris_(PyObject* self, PyObject* args)
00086 {
00087 */  /* Parse arguments */
00088 /*  if(!PyArg_ParseTuple(args, ":gcompris_"))
00089     return NULL;
00090 */
00091   /* Call the corresponding C function */
00092 /*  gcompris_();
00093 */
00094   /* Create and return the result */
00095 /*  Py_INCREF(Py_None);
00096   return Py_None;
00097 }
00098 */
00099 /*
00100   { "",  py_gcompris_, METH_VARARGS, "gcompris_" },
00101 */
00102