Commit 772df908 authored by Olivier Samyn's avatar Olivier Samyn

Fixed some compilation warnings and bugs.

Fixed bug when pressing a key in a python game.
Fixed function name in gcompris.h
parent 48a4e1d3
2004-01-24 Olivier Samyn <osamyn@ulb.ac.be>
* src/boards/py-mod-gcompris.c: (py_gcompris_bar_set_repeat_icon),
(py_gcompris_bar_hide), (py_gcompris_board_has_help),
(py_gcompris_help_start), (py_gcompris_log_set_comment): fixed compilation warning and some errors
* src/boards/py-mod-skin.c: (py_gcompris_skin_get_font): fixed compilation warning and some errors
* src/boards/py-mod-utils.c: (py_gcompris_item_event_focus): fixed compilation warning and some errors
* src/boards/python.c: (pythonboard_init), (pythonboard_start),
(pythonboard_pause), (pythonboard_end), (pythonboard_is_our_board),
(pythonboard_key_press), (pythonboard_ok), (pythonboard_set_level),
(pythonboard_config), (pythonboard_repeat): fixed bug when pressing a key in a python board, fixed compilation warning and some errors
* src/gcompris/gcompris.h: corrected function name (gcompris_log_set_comment)
2004-01-24 Bruno coudoin <bruno.coudoin@free.fr>
* src/boards/target.c: (start_board), (target_next_level),
......
......@@ -109,12 +109,11 @@ py_gcompris_bar_set_repeat_icon(PyObject* self, PyObject* args)
{
PyObject* pyObject;
GdkPixbuf* pixmap;
GcomprisBoard* cGcomprisBoard;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris_bar_set_repeat_icon", &pyObject))
return NULL;
pixmap = (GdkPixbuf*) pygobject_get(pixmap);
pixmap = (GdkPixbuf*) pygobject_get(pyObject);
/* Call the corresponding C function */
gcompris_bar_set_repeat_icon(pixmap);
......@@ -151,7 +150,7 @@ py_gcompris_bar_hide(PyObject* self, PyObject* args)
gint values;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "i:gcompris_bar_hide", values))
if(!PyArg_ParseTuple(args, "i:gcompris_bar_hide", &values))
return NULL;
/* Call the corresponding C function */
......@@ -172,7 +171,7 @@ py_gcompris_board_has_help(PyObject* self, PyObject* args)
gboolean result;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris_board_has_help", pyObject))
if(!PyArg_ParseTuple(args, "O:gcompris_board_has_help", &pyObject))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject*) pyObject;
cGcomprisBoard = pyGcomprisBoard -> cdata;
......@@ -199,9 +198,9 @@ py_gcompris_help_start(PyObject* self, PyObject* args)
GcomprisBoard* cGcomprisBoard;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris_help_start", pyObject))
if(!PyArg_ParseTuple(args, "O:gcompris_help_start", &pyObject))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject*) pyGcomprisBoard;
pyGcomprisBoard = (pyGcomprisBoardObject*) pyObject;
cGcomprisBoard = pyGcomprisBoard->cdata;
/* Call the corresponding C function */
......@@ -386,9 +385,9 @@ py_gcompris_images_selector_start(PyObject* self, PyObject* args)
}
/* void gcompris_log_set_reason (GcomprisBoard *gcomprisBoard, gchar *comment); */
/* void gcompris_log_set_comment (GcomprisBoard *gcomprisBoard, gchar *comment); */
static PyObject*
py_gcompris_log_set_reason(PyObject* self, PyObject* args)
py_gcompris_log_set_comment(PyObject* self, PyObject* args)
{
PyObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
......@@ -396,15 +395,15 @@ py_gcompris_log_set_reason(PyObject* self, PyObject* args)
/* Parse arguments */
if(!PyArg_ParseTuple(args,
"Os:gcompris_log_set_reason",
"Os:gcompris_log_set_comment",
&pyGcomprisBoard,
&comment))
return NULL;
cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
/* Call the corresponding C function */
gcompris_log_set_reason(cGcomprisBoard,
comment);
gcompris_log_set_comment(cGcomprisBoard,
comment);
/* Create and return the result */
Py_INCREF(Py_None);
......@@ -494,7 +493,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "images_selector_stop", py_gcompris_images_selector_stop,
METH_VARARGS, "gcompris_images_selector_stop" },
{ "exit", py_gcompris_exit, METH_VARARGS, "gcompris_exit" },
{ "log_set_reason", py_gcompris_log_set_reason, METH_VARARGS, "gcompris_log_set_reason" },
{ "log_set_comment", py_gcompris_log_set_comment, METH_VARARGS, "gcompris_log_set_comment" },
{ "log_end", py_gcompris_log_end, METH_VARARGS, "gcompris_log_end" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -109,7 +109,6 @@ py_gcompris_skin_get_color(PyObject* self, PyObject* args)
static PyObject*
py_gcompris_skin_get_font(PyObject* self, PyObject* args)
{
char* pixmapfile;
gchar* id;
gchar* result;
......
......@@ -84,7 +84,6 @@ py_gcompris_item_event_focus(PyObject* self, PyObject* args)
GnomeCanvasItem* item;
PyObject* pyevent;
GdkEvent* event;
PyObject* pydest_item;
gint result;
/* Parse arguments */
......
......@@ -72,7 +72,7 @@ BoardPlugin pythonboard_bp =
* Return the plugin structure (Common to all gcompris boards)
*/
BoardPlugin
BoardPlugin
*get_bplugin_info(void)
{
return &pythonboard_bp;
......@@ -83,7 +83,7 @@ BoardPlugin
* Tests if a python interpreter is available
* and that all required imports can be loaded.
*/
void
void
pythonboard_init (){
PyObject* main_module;
PyObject* globals;
......@@ -99,54 +99,54 @@ pythonboard_init (){
globals = PyModule_GetDict(main_module); /* Borrowed reference */
if(globals==NULL){
g_warning("! Python disabled: Cannot get infos from the python interpreter.\n");
g_warning("! Python disabled: Cannot get infos from the python interpreter.\n");
pythonboard_is_ready = FALSE;
} else {
/* Add the python plugins dir to the python's search path */
execstr = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR);
execstr = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR);
#ifndef DISABLE_USER_PLUGIN_DIR
userplugindir = g_strconcat(g_get_home_dir(), "/.gcompris/Plugins/", NULL);
execstr = g_strdup_printf("import sys; sys.path.append('%s/python'); sys.path.append('%s/python')",
userplugindir, PLUGIN_DIR);
execstr = g_strdup_printf("import sys; sys.path.append('%s/python'); sys.path.append('%s/python')",
userplugindir, PLUGIN_DIR);
g_free(userplugindir);
#else
execstr = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR );
execstr = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR );
#endif
if(PyRun_SimpleString(execstr)!=0){
pythonboard_is_ready = FALSE;
g_warning("! Python disabled: Cannot add plugins dir into search path\n");
g_warning("! Python disabled: Cannot add plugins dir into search path\n");
} else {
/* Load the gcompris modules */
python_gcompris_module_init();
/* Try to import pygtk modules */
g_free(execstr);
execstr = g_strdup_printf("import gtk; import gtk.gdk",PLUGIN_DIR);
execstr = g_strdup("import gtk; import gtk.gdk");
if(PyRun_SimpleString(execstr)!=0){
pythonboard_is_ready = FALSE;
g_warning("! Python disabled: Cannot import pygtk modules\n");
g_warning("! Python disabled: Cannot import pygtk modules\n");
} else {
/* Try to import gnome-python modules */
g_free(execstr);
execstr = g_strdup_printf("import gnome; import gnome.canvas",PLUGIN_DIR);
execstr = g_strdup("import gnome; import gnome.canvas");
if(PyRun_SimpleString(execstr)!=0){
pythonboard_is_ready = FALSE;
g_warning("! Python disabled: Cannot import gnome-python modules\n");
g_warning("! Python disabled: Cannot import gnome-python modules\n");
} else {
/* Try to import gcompris modules */
g_free(execstr);
execstr = g_strdup_printf("import gcompris; import gcompris.bonus; "
"import gcompris.score; import gcompris.sound;"
"import gcompris.skin; import gcompris.timer;"
"import gcompris.utils" ,PLUGIN_DIR);
execstr = g_strdup("import gcompris; import gcompris.bonus; "
"import gcompris.score; import gcompris.sound;"
"import gcompris.skin; import gcompris.timer;"
"import gcompris.utils");
if(PyRun_SimpleString(execstr)!=0){
pythonboard_is_ready = FALSE;
g_warning("! Python disabled: Cannot import gcompris modules\n");
g_warning("! Python disabled: Cannot import gcompris modules\n");
}
}
}
}
g_free(execstr);
g_free(execstr);
}
......@@ -155,15 +155,15 @@ pythonboard_init (){
}
/*
* Start the board.
* In this case:
* Start the board.
* In this case:
* - initialize python interpreter
* - import gcompris functions/objects
* - import gtk/gnome functions/objects
* - load the python written board
* - call the board start function
*/
void
void
pythonboard_start (GcomprisBoard *agcomprisBoard){
PyObject* main_module;
PyObject* py_function_result;
......@@ -181,16 +181,16 @@ pythonboard_start (GcomprisBoard *agcomprisBoard){
/* Initialize the python interpreter */
Py_SetProgramName(python_prog_name);
Py_Initialize();
PySys_SetArgv(1, python_args);
init_pygobject();
main_module = PyImport_AddModule("__main__");
globals = PyModule_GetDict(main_module);
if(globals==NULL){
g_print("Cannot get infos from the python interpreter. Seems there is a problem with this one.\n");
g_print("Cannot get infos from the python interpreter. Seems there is a problem with this one.\n");
return;
} else {
gcomprisBoard = agcomprisBoard;
......@@ -199,13 +199,13 @@ pythonboard_start (GcomprisBoard *agcomprisBoard){
/* Add the python plugins dir to the python's search path */
#ifndef DISABLE_USER_PLUGIN_DIR
userplugindir = g_strconcat(g_get_home_dir(), "/.gcompris/Plugins/", NULL);
boarddir = g_strdup_printf("import sys; sys.path.append('%s/python'); sys.path.append('%s/python')",
userplugindir, PLUGIN_DIR);
boarddir = g_strdup_printf("import sys; sys.path.append('%s/python'); sys.path.append('%s/python')",
userplugindir, PLUGIN_DIR);
#else
boarddir = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR );
boarddir = g_strdup_printf("import sys; sys.path.append('%s/python')",PLUGIN_DIR );
#endif
PyRun_SimpleString(boarddir);
g_free(boarddir);
PyRun_SimpleString(boarddir);
g_free(boarddir);
#ifndef DISABLE_USER_PLUGIN_DIR
g_free(userplugindir);
#endif
......@@ -217,40 +217,40 @@ pythonboard_start (GcomprisBoard *agcomprisBoard){
boardclass = g_strdup_printf("Gcompris_%s", agcomprisBoard->name);
/* Insert the board module into the python's interpreter */
python_board_module = PyImport_ImportModuleEx(agcomprisBoard->name,
python_board_module = PyImport_ImportModuleEx(agcomprisBoard->name,
globals,
globals,
NULL);
if(python_board_module!=NULL){
NULL);
if(python_board_module!=NULL){
/* Get the module dictionnary */
module_dict = PyModule_GetDict(python_board_module);
module_dict = PyModule_GetDict(python_board_module);
/* Get the python board class */
py_boardclass = PyDict_GetItemString(module_dict, boardclass);
/* Create a python gcompris board */
python_gcomprisBoard=gcompris_new_pyGcomprisBoardObject(agcomprisBoard);
python_gcomprisBoard=gcompris_new_pyGcomprisBoardObject(agcomprisBoard);
/* Create an instance of the board class */
py_boardclass_args = PyTuple_New(1);
Py_INCREF(python_gcomprisBoard);
PyTuple_SetItem(py_boardclass_args, 0, python_gcomprisBoard);
python_board_instance = PyInstance_New(py_boardclass, py_boardclass_args, NULL);
Py_DECREF(py_boardclass_args);
/* Call the function */
/* Call the function */
py_function_result = PyObject_CallMethod(python_board_instance, "start", NULL);
if( py_function_result != NULL){
Py_DECREF(py_function_result);
} else {
PyErr_Print();
PyErr_Print();
}
} else {
PyErr_Print();
} else {
PyErr_Print();
}
g_free(boardclass);
g_free(boardclass);
}
}
......@@ -264,7 +264,7 @@ void pythonboard_pause (gboolean pause){
if( result != NULL){
Py_DECREF(result);
} else {
PyErr_Print();
PyErr_Print();
}
}
......@@ -280,7 +280,7 @@ void pythonboard_end (void){
if(python_gcomprisBoard!=NULL){
result = PyObject_CallMethod(python_board_instance, "end", NULL);
if( result == NULL){
PyErr_Print();
PyErr_Print();
} else {
Py_DECREF(result);
}
......@@ -302,14 +302,14 @@ gboolean pythonboard_is_our_board (GcomprisBoard *agcomprisBoard){
{
/* Set the plugin entry */
agcomprisBoard->plugin=&pythonboard_bp;
g_print("pythonboard: is our board = TRUE\n");
return TRUE;
}
}
}
return FALSE;
return FALSE;
}
/*
......@@ -322,7 +322,7 @@ gint pythonboard_key_press (guint keyval){
if (result==NULL) return FALSE;
if (PyInt_AsLong(result)>0){
if (PyInt_Check(result) && (PyInt_AsLong(result)>0)){
Py_DECREF(result);
return TRUE;
} else {
......@@ -340,7 +340,7 @@ void pythonboard_ok (void){
if( result != NULL){
Py_DECREF(result);
} else {
PyErr_Print();
PyErr_Print();
}
}
......@@ -354,7 +354,7 @@ void pythonboard_set_level (guint level){
if( result != NULL){
Py_DECREF(result);
} else {
PyErr_Print();
PyErr_Print();
}
}
......@@ -367,7 +367,7 @@ void pythonboard_config(void){
if( result != NULL){
Py_DECREF(result);
} else {
PyErr_Print();
PyErr_Print();
}
}
......@@ -380,6 +380,6 @@ void pythonboard_repeat (void){
if( result != NULL){
Py_DECREF(result);
} else {
PyErr_Print();
PyErr_Print();
}
}
......@@ -114,7 +114,7 @@ void gcompris_exit();
void gcompris_log_start (GcomprisBoard *gcomprisBoard);
/* Use it to tell the teacher where the kid failed */
void gcompris_log_set_reason (GcomprisBoard *gcomprisBoard, gchar *comment);
void gcompris_log_set_comment (GcomprisBoard *gcomprisBoard, gchar *comment);
/* Do not use it if you use the bonus API in your board */
void gcompris_log_end (GcomprisBoard *gcomprisBoard, gchar *status);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment