Back to index

gcompris  8.2.2
py-mod-gcompris.c
Go to the documentation of this file.
00001 /* gcompris - py-mod-gcompris.c
00002  *
00003  * Time-stamp: <2006/08/21 23:36:37 bruno>
00004  *
00005  * Copyright (C) 2003 Olivier Samyn <osamyn@ulb.ac.be>
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program; if not, write to the Free Software
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #include <Python.h>
00023 #include <pygobject.h>
00024 #include "gcompris/gcompris.h"
00025 #include "py-mod-gcompris.h"
00026 #include "py-gcompris-board.h"
00027 #include "py-gcompris-properties.h"
00028 #include "py-gcompris-profile.h"
00029 #include "py-gcompris-wordlist.h"
00030 
00031 /* submodules includes */
00032 #include "py-mod-bonus.h"
00033 #include "py-mod-score.h"
00034 #include "py-mod-skin.h"
00035 #include "py-mod-sound.h"
00036 #include "py-mod-timer.h"
00037 #include "py-mod-utils.h"
00038 #include "py-mod-anim.h"
00039 #include "py-mod-admin.h"
00040 
00041 void initgnomecanvas (void);
00042 
00043 void pair_in_dict(gpointer key,
00044                 gpointer value,
00045                 gpointer dict)
00046 {
00047   PyObject *pyValue;
00048   PyObject *pyKey;
00049 
00050   pyKey = PyString_FromString((gchar *)key);
00051   Py_INCREF(pyKey);
00052 
00053 
00054   /* key cannot be NULL. But value can */
00055   if (value==NULL){
00056     Py_INCREF(Py_None);
00057     pyValue = Py_None;
00058   } else {
00059     pyValue = PyString_FromString((gchar *)value);
00060     Py_INCREF(pyValue);
00061   }
00062 
00063   PyDict_SetItem((PyObject *)dict, pyKey, pyValue);
00064 
00065   g_warning("Hash to dict: pass key %s and value %s",(gchar *)key, (gchar *)value );
00066 }
00067 
00068 
00069 /* Utility */
00070 PyObject* hash_to_dict(GHashTable *table)
00071 {
00072   PyObject *pydict;
00073 
00074   pydict = PyDict_New();
00075 
00076   g_hash_table_foreach            (table,
00077                                pair_in_dict,
00078                                    (gpointer) pydict);
00079 
00080   Py_INCREF(pydict);
00081   return pydict;
00082 }
00083 
00084 
00085 /* All functions provided by this python module
00086  * wraps a gcompris function. Each "py_*" function wraps the
00087  * "*" C function.
00088  */
00089 
00090 
00091 /* void gc_board_end(void); */
00092 static PyObject*
00093 py_gc_board_end(PyObject* self, PyObject* args)
00094 {
00095   /* Parse arguments */
00096   if(!PyArg_ParseTuple(args, ":gc_board_end"))
00097     return NULL;
00098 
00099   /* Call the corresponding C function */
00100   gc_board_end();
00101 
00102   /* Create and return the result */
00103   Py_INCREF(Py_None);
00104   return Py_None;
00105 }
00106 
00107 
00108 /* void       gc_bar_start (GnomeCanvas *theCanvas); */
00109 static PyObject*
00110 py_gc_bar_start(PyObject* self, PyObject* args)
00111 {
00112   PyObject* pyCanvas;
00113   GnomeCanvas* canvas;
00114 
00115   /* Parse arguments */
00116   if(!PyArg_ParseTuple(args, "O:gc_bar_start", &pyCanvas))
00117     return NULL;
00118   canvas = (GnomeCanvas*) pygobject_get(pyCanvas);
00119 
00120   /* Call the corresponding C function */
00121   gc_bar_start(canvas);
00122 
00123   /* Create and return the result */
00124   Py_INCREF(Py_None);
00125   return Py_None;
00126 }
00127 
00128 
00129 /* GnomeCanvasItem *gc_set_background(GnomeCanvasGroup *parent, gchar *file); */
00130 static PyObject*
00131 py_gc_set_background(PyObject* self, PyObject* args)
00132 {
00133   PyObject* pyCanvasGroup;
00134   GnomeCanvasGroup* canvasGroup;
00135   gchar* file;
00136   PyObject* pyResult;
00137   GnomeCanvasItem* result;
00138 
00139   /* Parse arguments */
00140   if(!PyArg_ParseTuple(args, "Os:gc_set_background", &pyCanvasGroup, &file))
00141     return NULL;
00142   canvasGroup = (GnomeCanvasGroup*) pygobject_get(pyCanvasGroup);
00143 
00144   /* Call the corresponding C function */
00145   result = gc_set_background(canvasGroup, file);
00146 
00147   /* Create and return the result */
00148   pyResult = pygobject_new((GObject*)result);
00149   return pyResult;
00150 }
00151 
00152 
00153 /* void gc_bar_set_level (GcomprisBoard *gcomprisBoard); */
00154 static PyObject*
00155 py_gc_bar_set_level(PyObject* self, PyObject* args)
00156 {
00157   PyObject* pyObject;
00158   pyGcomprisBoardObject* pyGcomprisBoard;
00159   GcomprisBoard* cGcomprisBoard;
00160 
00161   /* Parse arguments */
00162   if(!PyArg_ParseTuple(args, "O:gc_bar_set_level", &pyObject))
00163     return NULL;
00164   pyGcomprisBoard = (pyGcomprisBoardObject*) pyObject;
00165   cGcomprisBoard = pyGcomprisBoard->cdata;
00166 
00167   /* Call the corresponding C function */
00168   gc_bar_set_level(cGcomprisBoard);
00169 
00170   /* Create and return the result */
00171   Py_INCREF(Py_None);
00172   return Py_None;
00173 }
00174 
00175 
00176 /* void gc_bar_set_repeat_icon (GdkPixbuf *pixmap); */
00177 static PyObject*
00178 py_gc_bar_set_repeat_icon(PyObject* self, PyObject* args)
00179 {
00180   PyObject* pyObject;
00181   GdkPixbuf* pixmap;
00182 
00183   /* Parse arguments */
00184   if(!PyArg_ParseTuple(args, "O:gc_bar_set_repeat_icon", &pyObject))
00185     return NULL;
00186   pixmap = (GdkPixbuf*) pygobject_get(pyObject);
00187 
00188   /* Call the corresponding C function */
00189   gc_bar_set_repeat_icon(pixmap);
00190 
00191   /* Create and return the result */
00192   Py_INCREF(Py_None);
00193   return Py_None;
00194 }
00195 
00196 
00197 /* void gc_bar_set (const GComprisBarFlags flags); */
00198 static PyObject*
00199 py_gc_bar_set(PyObject* self, PyObject* args)
00200 {
00201   gint values;
00202 
00203   /* Parse arguments */
00204   if(!PyArg_ParseTuple(args, "i:gc_bar_set", &values))
00205     return NULL;
00206 
00207   /* Call the corresponding C function */
00208   gc_bar_set(values);
00209 
00210   /* Create and return the result */
00211   Py_INCREF(Py_None);
00212   return Py_None;
00213 }
00214 
00215 
00216 /* void gc_bar_hide (gboolean hide); */
00217 static PyObject*
00218 py_gc_bar_hide(PyObject* self, PyObject* args)
00219 {
00220   gint values;
00221 
00222   /* Parse arguments */
00223   if(!PyArg_ParseTuple(args, "i:gc_bar_hide", &values))
00224     return NULL;
00225 
00226   /* Call the corresponding C function */
00227   gc_bar_hide(values);
00228 
00229   /* Create and return the result */
00230   Py_INCREF(Py_None);
00231   return Py_None;
00232 }
00233 
00234 /* GnomeCanvas *gc_get_canvas(void); */
00235 static PyObject*
00236 py_gc_get_canvas(PyObject* self, PyObject* args)
00237 {
00238   GnomeCanvas* result;
00239   /* Parse arguments */
00240   if(!PyArg_ParseTuple(args, ":gc_get_canvas"))
00241     return NULL;
00242 
00243   /* Call the corresponding C function */
00244   result = gc_get_canvas();
00245 
00246   /* Create and return the result */
00247   return (PyObject*) pygobject_new((GObject*) result);
00248 }
00249 
00250 
00251 /* GtkWidget *gc_get_window(void); */
00252 static PyObject*
00253 py_gc_get_window(PyObject* self, PyObject* args)
00254 {
00255   GtkWidget* result;
00256   /* Parse arguments */
00257   if(!PyArg_ParseTuple(args, ":gc_get_window"))
00258     return NULL;
00259 
00260   /* Call the corresponding C function */
00261   result = gc_get_window();
00262 
00263   /* Create and return the result */
00264   return (PyObject*)pygobject_new((GObject*)result);
00265 }
00266 
00267 
00268 /* gchar *gc_locale_get(void); */
00269 static PyObject*
00270 py_gc_locale_get(PyObject* self, PyObject* args)
00271 {
00272   gchar* result;
00273   /* Parse arguments */
00274   if(!PyArg_ParseTuple(args, ":gc_locale_get"))
00275     return NULL;
00276 
00277   /* Call the corresponding C function */
00278   result = (gchar*)gc_locale_get();
00279 
00280   /* Create and return the result */
00281   return Py_BuildValue("s", result);
00282 }
00283 
00284 
00285 /* void gc_locale_set(gchar *locale); */
00286 static PyObject*
00287 py_gc_locale_set(PyObject* self, PyObject* args)
00288 {
00289   gchar* locale;
00290   /* Parse arguments */
00291   if(!PyArg_ParseTuple(args, "s:gc_locale_set", &locale))
00292     return NULL;
00293 
00294   /* Call the corresponding C function */
00295   gc_locale_set(locale);
00296 
00297   /* Create and return the result */
00298   Py_INCREF(Py_None);
00299   return Py_None;
00300 }
00301 
00302 
00303 /* char *gc_locale_get_user_default(void) */
00304 static PyObject*
00305 py_gc_locale_get_user_default(PyObject* self, PyObject* args)
00306 {
00307   char* result;
00308   /* Parse arguments */
00309   if(!PyArg_ParseTuple(args, ":gc_locale_get_user_default"))
00310     return NULL;
00311 
00312   /* Call the corresponding C function */
00313   result = gc_locale_get_user_default();
00314 
00315   /* Create and return the result */
00316   return Py_BuildValue("s", result);
00317 }
00318 
00319 
00320 /* void gc_cursor_set(guint gdk_cursor_type); */
00321 static PyObject*
00322 py_gc_cursor_set(PyObject* self, PyObject* args)
00323 {
00324   guint cursor;
00325   /* Parse arguments */
00326   if(!PyArg_ParseTuple(args, "i:gc_cursor_set",&cursor))
00327     return NULL;
00328 
00329   /* Call the corresponding C function */
00330   gc_cursor_set(cursor);
00331 
00332   /* Create and return the result */
00333   Py_INCREF(Py_None);
00334   return Py_None;
00335 }
00336 
00337 
00338 /* Some functions and variables needed to get the image selector working */
00339 static PyObject* pyImageSelectorCallBackFunc = NULL;
00340 
00341 void pyImageSelectorCallBack(gchar* image){
00342   PyObject* args;
00343   PyObject* result;
00344   if(pyImageSelectorCallBackFunc==NULL) return;
00345 
00346   /* Build arguments */
00347   args = PyTuple_New(1);
00348   PyTuple_SetItem(args, 0, Py_BuildValue("s", image));
00349   result = PyObject_CallObject(pyImageSelectorCallBackFunc, args);
00350   if(result==NULL){
00351     PyErr_Print();
00352   } else {
00353     Py_DECREF(result);
00354   }
00355 }
00356 
00357 
00358 /* void gc_selector_images_start (GcomprisBoard *gcomprisBoard,  */
00359 /*                                 gchar *dataset,  */
00360 /*                                 ImageSelectorCallBack imscb); */
00361 static PyObject*
00362 py_gc_selector_images_start(PyObject* self, PyObject* args)
00363 {
00364   PyObject* pyGcomprisBoard;
00365   GcomprisBoard* cGcomprisBoard;
00366   PyObject* pyCallback;
00367   gchar* dataset;
00368 
00369   /* Parse arguments */
00370   if(!PyArg_ParseTuple(args,
00371                      "OsO:gc_selector_images_start",
00372                      &pyGcomprisBoard,
00373                      &dataset,
00374                      &pyCallback))
00375     return NULL;
00376   if(!PyCallable_Check(pyCallback)) return NULL;
00377   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
00378 
00379   /* Call the corresponding C function */
00380   pyImageSelectorCallBackFunc = pyCallback;
00381   gc_selector_images_start(cGcomprisBoard,
00382                              dataset,
00383                              pyImageSelectorCallBack);
00384 
00385   /* Create and return the result */
00386   Py_INCREF(Py_None);
00387   return Py_None;
00388 }
00389 
00390 
00391 /* void gc_log_set_comment (GcomprisBoard *gcomprisBoard, gchar *expected, gchar *got); */
00392 static PyObject*
00393 py_gc_log_set_comment(PyObject* self, PyObject* args)
00394 {
00395   PyObject* pyGcomprisBoard;
00396   GcomprisBoard* cGcomprisBoard;
00397   gchar* expected;
00398   gchar* got;
00399 
00400   /* Parse arguments */
00401   if(!PyArg_ParseTuple(args,
00402                      "Os:gc_log_set_comment",
00403                      &pyGcomprisBoard,
00404                      &expected,
00405                      &got))
00406     return NULL;
00407   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
00408 
00409   /* Call the corresponding C function */
00410   gc_log_set_comment(cGcomprisBoard,
00411                         expected, got);
00412 
00413   /* Create and return the result */
00414   Py_INCREF(Py_None);
00415   return Py_None;
00416 }
00417 
00418 
00419 /* void gc_log_end (GcomprisBoard *gcomprisBoard, gchar *status); */
00420 static PyObject*
00421 py_gc_log_end(PyObject* self, PyObject* args)
00422 {
00423   PyObject* pyGcomprisBoard;
00424   GcomprisBoard* cGcomprisBoard;
00425   gchar* status;
00426 
00427   /* Parse arguments */
00428   if(!PyArg_ParseTuple(args,
00429                      "Os:gc_log_end",
00430                      &pyGcomprisBoard,
00431                      &status))
00432     return NULL;
00433   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
00434 
00435   /* Call the corresponding C function */
00436   gc_log_end(cGcomprisBoard,
00437                  status);
00438 
00439   /* Create and return the result */
00440   Py_INCREF(Py_None);
00441   return Py_None;
00442 }
00443 
00444 
00445 /* void gc_selector_images_stop (void); */
00446 static PyObject*
00447 py_gc_selector_images_stop(PyObject* self, PyObject* args)
00448 {
00449   /* Parse arguments */
00450   if(!PyArg_ParseTuple(args, ":gc_selector_images_stop"))
00451     return NULL;
00452 
00453   /* Call the corresponding C function */
00454   gc_selector_images_stop();
00455 
00456   /* Create and return the result */
00457   Py_INCREF(Py_None);
00458   return Py_None;
00459 }
00460 
00461 
00462 /* Some functions and variables needed to get the file selector working */
00463 static PyObject* pyFileSelectorCallBackFunc = NULL;
00464 
00465 void pyFileSelectorCallBack(gchar* file, char* file_type){
00466   PyObject* args;
00467   PyObject* result;
00468   if(pyFileSelectorCallBackFunc==NULL) return;
00469 
00470   /* Build arguments */
00471   args  = PyTuple_New(2);
00472   PyTuple_SetItem(args, 0, Py_BuildValue("s", file));
00473   PyTuple_SetItem(args, 1, Py_BuildValue("s", file_type));
00474   result = PyObject_CallObject(pyFileSelectorCallBackFunc, args);
00475   if(result==NULL){
00476     PyErr_Print();
00477   } else {
00478     Py_DECREF(result);
00479   }
00480 
00481 }
00482 
00483 
00484 /* void gc_selector_file_load(GcomprisBoard *gcomprisBoard,
00485                                     gchar *rootdir,
00486                                 gchar *file_types, (A Comma separated text explaining the different file types)
00487                                     FileSelectorCallBack fscb);
00488 */
00489 static PyObject*
00490 py_gc_selector_file_load(PyObject* self, PyObject* args){
00491   PyObject* pyGcomprisBoard;
00492   GcomprisBoard* cGcomprisBoard;
00493   PyObject* pyCallback;
00494   gchar* rootdir;
00495   gchar* file_types;
00496 
00497   /* Parse arguments */
00498   if(!PyArg_ParseTuple(args,
00499                      "OssO:gc_selector_file_load",
00500                      &pyGcomprisBoard,
00501                      &rootdir,
00502                      &file_types,
00503                      &pyCallback))
00504     return NULL;
00505   if(!PyCallable_Check(pyCallback)) return NULL;
00506   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
00507 
00508   /* Call the corresponding C function */
00509   pyFileSelectorCallBackFunc = pyCallback;
00510   gc_selector_file_load(cGcomprisBoard,
00511                               rootdir,
00512                            file_types,
00513                               pyFileSelectorCallBack);
00514 
00515   /* Create and return the result */
00516   Py_INCREF(Py_None);
00517   return Py_None;
00518 }
00519 
00520 
00521 /* void gc_selector_file_save(GcomprisBoard *gcomprisBoard,
00522                                     gchar *rootdir,
00523                                 gchar *file_types, (A Comma separated text explaining the different file types)
00524                                     FileSelectorCallBack fscb);
00525 */
00526 static PyObject*
00527 py_gc_selector_file_save(PyObject* self, PyObject* args){
00528   PyObject* pyGcomprisBoard;
00529   GcomprisBoard* cGcomprisBoard;
00530   PyObject* pyCallback;
00531   gchar* rootdir;
00532   char* file_types;
00533 
00534   /* Parse arguments */
00535   if(!PyArg_ParseTuple(args,
00536                      "OssO:gc_selector_file_save",
00537                      &pyGcomprisBoard,
00538                      &rootdir,
00539                      &file_types,
00540                      &pyCallback))
00541     return NULL;
00542   if(!PyCallable_Check(pyCallback)) return NULL;
00543   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
00544 
00545   /* Call the corresponding C function */
00546   pyFileSelectorCallBackFunc = pyCallback;
00547   gc_selector_file_save(cGcomprisBoard,
00548                               rootdir,
00549                            file_types,
00550                               pyFileSelectorCallBack);
00551 
00552   /* Create and return the result */
00553   Py_INCREF(Py_None);
00554   return Py_None;
00555 }
00556 
00557 
00558 /* void gc_selector_file_stop (void); */
00559 static PyObject*
00560 py_gc_selector_file_stop(PyObject* self, PyObject* args)
00561 {
00562   /* Parse arguments */
00563   if(!PyArg_ParseTuple(args, ":gc_selector_file_stop"))
00564     return NULL;
00565 
00566   /* Call the corresponding C function */
00567   gc_selector_file_stop();
00568 
00569   /* Create and return the result */
00570   Py_INCREF(Py_None);
00571   return Py_None;
00572 }
00573 
00574 /* gchar *gc_db_get_filename(void); */
00575 static PyObject*
00576 py_gc_db_get_filename(PyObject* self, PyObject* args)
00577 {
00578   gchar* result;
00579   /* Parse arguments */
00580   if(!PyArg_ParseTuple(args, ":gc_db_get_filename"))
00581     return NULL;
00582 
00583   /* Call the corresponding C function */
00584   result = (gchar*)gc_db_get_filename();
00585 
00586   /* Create and return the result */
00587   return Py_BuildValue("s", result);
00588 }
00589 
00590 
00591 /* GcomprisProperties *gc_prop_get(void); */
00592 static PyObject*
00593 py_gc_prop_get(PyObject* self, PyObject* args)
00594 {
00595   GcomprisProperties* result;
00596   /* Parse arguments */
00597   if(!PyArg_ParseTuple(args, ":gc_prop_get"))
00598     return NULL;
00599 
00600   /* Call the corresponding C function */
00601   result = gc_prop_get();
00602 
00603   /* Create and return the result */
00604   return gcompris_new_pyGcomprisPropertiesObject(result);
00605 }
00606 
00607 /* GcomprisBoard *gc_menu_section_get(gchar *section); */
00608 static PyObject*
00609 py_gc_menu_section_get(PyObject* self, PyObject* args)
00610 {
00611   GcomprisBoard* result;
00612   gchar *section;
00613 
00614   /* Parse arguments */
00615   if(!PyArg_ParseTuple(args, "s:gc_menu_section_get", &section))
00616     return NULL;
00617 
00618   /* Call the corresponding C function */
00619   result = gc_menu_section_get(section);
00620 
00621   /* Create and return the result */
00622   return gcompris_new_pyGcomprisBoardObject(result);
00623 }
00624 
00625 
00626 /* Code stolen from PyGTK */
00627 /* This bindings are available only in pygtk 2.6, a little bit too young for us. */
00628 
00629 
00630 struct _PyGChildData {
00631     PyObject *func;
00632     PyObject *data;
00633 };
00634 
00635 
00636 static void
00637 child_watch_func(GPid pid, gint status, gpointer data)
00638 {
00639     struct _PyGChildData *child_data = (struct _PyGChildData *) data;
00640     PyObject *retval;
00641     PyGILState_STATE gil;
00642 
00643     gil = pyg_gil_state_ensure();
00644     if (child_data->data)
00645         retval = PyObject_CallFunction(child_data->func, "iiO", pid, status,
00646                                        child_data->data);
00647     else
00648         retval = PyObject_CallFunction(child_data->func, "ii", pid, status);
00649 
00650     if (retval)
00651        Py_DECREF(retval);
00652     else
00653        PyErr_Print();
00654 
00655     pyg_gil_state_release(gil);
00656 }
00657 
00658 static void
00659 child_watch_dnotify(gpointer data)
00660 {
00661     struct _PyGChildData *child_data = (struct _PyGChildData *) data;
00662     Py_DECREF(child_data->func);
00663     Py_XDECREF(child_data->data);
00664     g_free(child_data);
00665 }
00666 
00667 
00668 static PyObject *
00669 py_gcompris_child_watch_add(PyObject *unused, PyObject *args, PyObject *kwargs)
00670 {
00671     static char *kwlist[] = { "pid", "function", "data", "priority", NULL };
00672     guint id;
00673     gint priority = G_PRIORITY_DEFAULT;
00674     int pid;
00675     PyObject *func, *user_data = NULL;
00676     struct _PyGChildData *child_data;
00677 
00678     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "iO|Oi:gcompris.child_watch_add", kwlist,
00679                                      &pid, &func, &user_data, &priority))
00680         return NULL;
00681     if (!PyCallable_Check(func)) {
00682         PyErr_SetString(PyExc_TypeError,
00683                         "gobject.child_watch_add: second argument must be callable");
00684         return NULL;
00685     }
00686 
00687     child_data = g_new(struct _PyGChildData, 1);
00688     child_data->func = func;
00689     child_data->data = user_data;
00690     Py_INCREF(child_data->func);
00691     if (child_data->data)
00692         Py_INCREF(child_data->data);
00693     id = g_child_watch_add_full(priority, pid, child_watch_func,
00694                                 child_data, child_watch_dnotify);
00695     return PyInt_FromLong(id);
00696 }
00697 
00698 struct _PyGChildSetupData {
00699     PyObject *func;
00700     PyObject *data;
00701 };
00702 
00703 static void
00704 _pyg_spawn_async_callback(gpointer user_data)
00705 {
00706     struct _PyGChildSetupData *data;
00707     PyObject *retval;
00708     PyGILState_STATE gil;
00709 
00710     data = (struct _PyGChildSetupData *) user_data;
00711     gil = pyg_gil_state_ensure();
00712     if (data->data)
00713         retval = PyObject_CallFunction(data->func, "O", data->data);
00714     else
00715         retval = PyObject_CallFunction(data->func, NULL);
00716     if (retval)
00717        Py_DECREF(retval);
00718     else
00719        PyErr_Print();
00720     Py_DECREF(data->func);
00721     Py_XDECREF(data->data);
00722     g_free(data);
00723     pyg_gil_state_release(gil);
00724 }
00725 
00726 static PyObject *
00727 py_gcompris_spawn_async(PyObject *unused, PyObject *args, PyObject *kwargs)
00728 {
00729     static char *kwlist[] = { "argv", "envp", "working_directory", "flags",
00730                               "child_setup", "user_data", "standard_input",
00731                               "standard_output", "standard_error", NULL };
00732     PyObject *pyargv, *pyenvp = NULL;
00733     char **argv, **envp = NULL;
00734     PyObject *func = NULL, *user_data = NULL;
00735     char *working_directory = NULL;
00736     int flags = 0, _stdin = -1, _stdout = -1, _stderr = -1;
00737     PyObject *pystdin = NULL, *pystdout = NULL, *pystderr = NULL;
00738     gint *standard_input, *standard_output, *standard_error;
00739     struct _PyGChildSetupData *callback_data = NULL;
00740     GError *error = NULL;
00741     GPid child_pid = -1;
00742     int len, i;
00743 
00744     if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OsiOOOOO:gcompris.spawn_async",
00745                                      kwlist,
00746                                      &pyargv, &pyenvp, &working_directory, &flags,
00747                                      &func, &user_data,
00748                                      &pystdin, &pystdout, &pystderr))
00749         return NULL;
00750 
00751     if (pystdin && PyObject_IsTrue(pystdin))
00752         standard_input = &_stdin;
00753     else
00754         standard_input = NULL;
00755 
00756     if (pystdout && PyObject_IsTrue(pystdout))
00757         standard_output = &_stdout;
00758     else
00759         standard_output = NULL;
00760 
00761     if (pystderr && PyObject_IsTrue(pystderr))
00762         standard_error = &_stderr;
00763     else
00764         standard_error = NULL;
00765 
00766       /* parse argv */
00767     if (!PySequence_Check(pyargv)) {
00768         PyErr_SetString(PyExc_TypeError,
00769                         "gobject.spawn_async: first argument must be a sequence of strings");
00770         return NULL;
00771     }
00772     len = PySequence_Length(pyargv);
00773     argv = g_new0(char *, len + 1);
00774     for (i = 0; i < len; ++i) {
00775         PyObject *tmp = PySequence_ITEM(pyargv, i);
00776         if (!PyString_Check(tmp)) {
00777             PyErr_SetString(PyExc_TypeError,
00778                             "gobject.spawn_async: first argument must be a sequence of strings");
00779             g_free(argv);
00780             Py_XDECREF(tmp);
00781             return NULL;
00782         }
00783         argv[i] = PyString_AsString(tmp);
00784         Py_DECREF(tmp);
00785     }
00786 
00787       /* parse envp */
00788     if (pyenvp) {
00789         if (!PySequence_Check(pyenvp)) {
00790             PyErr_SetString(PyExc_TypeError,
00791                             "gobject.spawn_async: second argument must be a sequence of strings");
00792             g_free(argv);
00793             return NULL;
00794         }
00795         len = PySequence_Length(pyenvp);
00796         envp = g_new0(char *, len + 1);
00797         for (i = 0; i < len; ++i) {
00798             PyObject *tmp = PySequence_ITEM(pyenvp, i);
00799             if (!PyString_Check(tmp)) {
00800                 PyErr_SetString(PyExc_TypeError,
00801                                 "gobject.spawn_async: second argument must be a sequence of strings");
00802                 g_free(envp);
00803                 Py_XDECREF(tmp);
00804                 return NULL;
00805             }
00806             envp[i] = PyString_AsString(tmp);
00807             Py_DECREF(tmp);
00808         }
00809     }
00810 
00811     if (func) {
00812         callback_data = g_new(struct _PyGChildSetupData, 1);
00813         callback_data->func = func;
00814         callback_data->data = user_data;
00815         Py_INCREF(callback_data->func);
00816         if (callback_data->data)
00817             Py_INCREF(callback_data->data);
00818     }
00819 
00820     if (!g_spawn_async_with_pipes(working_directory, argv, envp, flags,
00821                                   func? _pyg_spawn_async_callback : NULL,
00822                                   callback_data, &child_pid,
00823                                   standard_input,
00824                                   standard_output,
00825                                   standard_error,
00826                                   &error))
00827     {
00828         g_free(argv);
00829         if (envp) g_free(envp);
00830         if (callback_data) {
00831             Py_DECREF(callback_data->func);
00832             Py_XDECREF(callback_data->data);
00833             g_free(callback_data);
00834         }
00835         pyg_error_check(&error);
00836         return NULL;
00837     }
00838     g_free(argv);
00839     if (envp) g_free(envp);
00840 
00841     if (standard_input)
00842         pystdin = PyInt_FromLong(*standard_input);
00843     else {
00844         Py_INCREF(Py_None);
00845         pystdin = Py_None;
00846     }
00847 
00848     if (standard_output)
00849         pystdout = PyInt_FromLong(*standard_output);
00850     else {
00851         Py_INCREF(Py_None);
00852         pystdout = Py_None;
00853     }
00854 
00855     if (standard_error)
00856         pystderr = PyInt_FromLong(*standard_error);
00857     else {
00858         Py_INCREF(Py_None);
00859         pystderr = Py_None;
00860     }
00861 
00862     return Py_BuildValue("iNNN", child_pid, pystdin, pystdout, pystderr);
00863 }
00864 
00865 
00866 /*
00867   { "",  py_gcompris_, METH_VARARGS, "gcompris_" },
00868 */
00869 
00870 
00871 static PyObject*
00872 py_gc_db_get_board_conf(PyObject* self, PyObject* args)
00873 {
00874   PyObject *pydict;
00875   GHashTable *table;
00876 
00877   /* Parse arguments */
00878   if(!PyArg_ParseTuple(args, ":gcompris.get_board_conf"))
00879     return NULL;
00880 
00881   /* Call the corresponding C function */
00882 
00883   table = gc_db_get_board_conf();
00884 
00885   pydict = hash_to_dict(table);
00886 
00887   g_hash_table_destroy(table);
00888 
00889   return pydict;;
00890 }
00891 
00892 static PyObject*
00893 py_gc_db_get_conf(PyObject* self, PyObject* args)
00894 {
00895   PyObject *pydict;
00896   GHashTable *table;
00897 
00898   PyObject* pyBoard;
00899   PyObject* pyProfile;
00900   pyGcomprisBoardObject* pyGcomprisBoard;
00901   GcomprisBoard* cGcomprisBoard;
00902   pyGcomprisProfileObject* pyGcomprisProfile;
00903   GcomprisProfile* cGcomprisProfile;
00904 
00905   /* Parse arguments */
00906   if(!PyArg_ParseTuple(args, "OO:gcompris.get_conf", &pyProfile ,&pyBoard))
00907     return NULL;
00908 
00909   pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
00910   pyGcomprisProfile = (pyGcomprisProfileObject *) pyProfile;
00911 
00912   cGcomprisProfile = pyGcomprisProfile->cdata;
00913   cGcomprisBoard = pyGcomprisBoard->cdata;
00914 
00915   /* Call the corresponding C function */
00916   table = gc_db_get_conf(cGcomprisProfile, cGcomprisBoard);
00917 
00918   pydict = hash_to_dict(table);
00919 
00920   g_hash_table_destroy(table);
00921 
00922   return pydict;;
00923 }
00924 
00925 
00926 /* GcomprisProfile *gc_profile_get_current(void); */
00927 static PyObject*
00928 py_gc_profile_get_current(PyObject* self, PyObject* args)
00929 {
00930   GcomprisProfile* result;
00931   /* Parse arguments */
00932   if(!PyArg_ParseTuple(args, ":gc_profile_get_current"))
00933     return NULL;
00934 
00935   /* Call the corresponding C function */
00936   result = gc_profile_get_current();
00937 
00938   /* Create and return the result */
00939   return gcompris_new_pyGcomprisProfileObject(result);
00940 }
00941 
00942 
00943 /* GcomprisUser *gc_profile_get_current_user(void); */
00944 static PyObject*
00945 py_gc_profile_get_current_user(PyObject* self, PyObject* args)
00946 {
00947   GcomprisUser* result;
00948   /* Parse arguments */
00949   if(!PyArg_ParseTuple(args, ":gc_profile_get_current_user"))
00950     return NULL;
00951 
00952   /* Call the corresponding C function */
00953   result = gc_profile_get_current_user();
00954 
00955   /* Create and return the result */
00956   return gcompris_new_pyGcomprisUserObject(result);
00957 }
00958 
00959 
00960 static PyObject*
00961 py_gc_db_set_board_conf (PyObject* self, PyObject* args)
00962 {
00963   PyObject* pyBoard;
00964   PyObject* pyProfile;
00965   pyGcomprisBoardObject* pyGcomprisBoard;
00966   GcomprisBoard* cGcomprisBoard;
00967   pyGcomprisProfileObject* pyGcomprisProfile;
00968   GcomprisProfile* cGcomprisProfile;
00969   char *key;
00970   char *value;
00971 
00972   /* Parse arguments */
00973   if(!PyArg_ParseTuple(args, "OOss:gcompris.set_board_conf",
00974                      &pyProfile, &pyBoard,
00975                      &key, &value))
00976     return NULL;
00977 
00978   pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
00979   pyGcomprisProfile = (pyGcomprisProfileObject *) pyProfile;
00980 
00981   cGcomprisProfile = pyGcomprisProfile->cdata;
00982   cGcomprisBoard = pyGcomprisBoard->cdata;
00983 
00984   /* Call the corresponding C function */
00985   gc_db_set_board_conf(cGcomprisProfile, cGcomprisBoard, key, value);
00986 
00987   /* Create and return the result */
00988   Py_INCREF(Py_None);
00989   return Py_None;
00990 }
00991 
00992 
00993 /* Some functions and variables needed to get the file selector working */
00994 static PyObject* pyGcomprisConfCallbackFunc = NULL;
00995 
00996 static void pyGcomprisConfCallback(GHashTable* table){
00997   PyObject* result;
00998 
00999   PyGILState_STATE gil;
01000 
01001 
01002   if(pyGcomprisConfCallbackFunc==NULL) return;
01003 
01004   gil = pyg_gil_state_ensure();
01005 
01006   if (table)
01007     result = PyObject_CallFunction(pyGcomprisConfCallbackFunc, "O", hash_to_dict(table));
01008   else
01009     result = PyObject_CallFunction(pyGcomprisConfCallbackFunc, "O", Py_None);
01010 
01011   // This callback can be called multiple time ? not now
01012 
01013   Py_DECREF(pyGcomprisConfCallbackFunc);
01014 
01015   if(result==NULL){
01016     PyErr_Print();
01017   } else {
01018     Py_DECREF(result);
01019   }
01020 
01021   pyg_gil_state_release(gil);
01022 
01023 }
01024 
01025 
01026 static PyObject*
01027 py_gc_board_config_window_display(PyObject* self, PyObject* args){
01028   PyObject* pyCallback;
01029   gchar *label;
01030 
01031   /* Parse arguments */
01032   if(!PyArg_ParseTuple(args,
01033                      "sO:gc_board_config_window_display",
01034                      &label,
01035                      &pyCallback))
01036     return NULL;
01037   if(!PyCallable_Check(pyCallback))
01038     {
01039       PyErr_SetString(PyExc_TypeError,
01040                     "gc_board_config_window_display second argument must be callable");
01041       return NULL;
01042     }
01043 
01044   //if (pyGcomprisConfCallbackFunc)
01045   //  Py_DECREF(pyGcomprisConfCallbackFunc);
01046 
01047   pyGcomprisConfCallbackFunc = pyCallback;
01048 
01049   Py_INCREF(pyGcomprisConfCallbackFunc);
01050 
01051 
01052   return (PyObject *) \
01053              pygobject_new((GObject*) \
01054                         gc_board_config_window_display( label,
01055                                                    (GcomprisConfCallback )pyGcomprisConfCallback));
01056 
01057 }
01058 
01059 
01060 /* GtkCheckButton *gc_board_config_boolean_box (label, key, init);*/
01061 static PyObject*
01062 py_gc_board_config_boolean_box(PyObject* self, PyObject* args)
01063 {
01064   PyObject *py_bool;
01065   gchar *label;
01066   gchar *key;
01067 
01068   /* Parse arguments */
01069   if(!PyArg_ParseTuple(args, "ssO:gc_board_config_boolean_box", &label, &key, &py_bool))
01070     return NULL;
01071 
01072   /* Call the corresponding C function */
01073   return (PyObject *)pygobject_new((GObject*) \
01074                                 gc_board_config_boolean_box((const gchar *)label, key, PyObject_IsTrue(py_bool)));
01075 
01076 }
01077 
01078 /* GtkComboBox *gc_board_config_combo_box(const gchar *label, GList *strings, gchar *key, gint index); */
01079 static PyObject*
01080 py_gc_board_config_combo_box(PyObject* self, PyObject* args)
01081 {
01082   PyObject *py_list;
01083   gchar *label;
01084   gchar *key;
01085   gchar *init;
01086 
01087   GList *list = NULL;
01088 
01089   int i, size;
01090 
01091   /* Parse arguments */
01092   if(!PyArg_ParseTuple(args, "sOss:gc_board_config_combo_box", &label, &py_list, &key, &init))
01093     return NULL;
01094 
01095   if (!PyList_Check(py_list)){
01096     PyErr_SetString(PyExc_TypeError,
01097                     "gc_board_config_combo_box second argument must be a list");
01098     return NULL;
01099   }
01100 
01101   size = PyList_Size (py_list);
01102 
01103   for (i=0; i < size; i ++)
01104     list = g_list_append( list,
01105                        PyString_AsString( PyList_GetItem( py_list, i)));
01106 
01107   /* Call the corresponding C function */
01108   return (PyObject *)pygobject_new((GObject*) \
01109                                 gc_board_config_combo_box((const gchar *)label,
01110                                                  list,
01111                                                  key,
01112                                                  init));
01113 }
01114 
01115 
01116 /* Params: */
01117 /*   - Label */
01118 /*   - key (for hashtable  return) */
01119 /*   - g_hash_table (gchar *values, gchar *label) */
01120 /* Returns */
01121 /*   - g_hash_table (gchar *values, GtkWidget *pointer) */
01122 
01123 /* GHashTable *gc_board_config_radio_buttons(const gchar *label, */
01124 /*                             gchar *key, */
01125 /*                             GHashTable *buttons_label, */
01126 /*                             gchar *init);  */
01127 
01128 void pair_object_in_dict(gpointer key,
01129                       gpointer value,
01130                       gpointer dict)
01131 {
01132   PyObject *pyValue;
01133   PyObject *pyKey;
01134 
01135   pyKey = PyString_FromString((gchar *)key);
01136   Py_INCREF(pyKey);
01137 
01138   pyValue = pygobject_new((GObject*) value);
01139   Py_INCREF(pyValue);
01140 
01141   PyDict_SetItem((PyObject *)dict, pyKey, pyValue);
01142 }
01143 
01144 
01145 /* Utility */
01146 PyObject* hash_object_to_dict(GHashTable *table)
01147 {
01148   PyObject *pydict;
01149 
01150   pydict = PyDict_New();
01151 
01152   g_hash_table_foreach            (table,
01153                                pair_object_in_dict,
01154                                    (gpointer) pydict);
01155 
01156   Py_INCREF(pydict);
01157   return pydict;
01158 }
01159 
01160 
01161 static PyObject*
01162 py_gc_board_config_radio_buttons(PyObject* self, PyObject* args)
01163 {
01164   PyObject *py_dict;
01165   GHashTable *buttons_label, *result;
01166   gchar *label;
01167   gchar *key;
01168   gchar *init;
01169 
01170   /* Parse arguments */
01171   if(!PyArg_ParseTuple(args, "ssOs:gc_board_config_radio_buttons", &label, &key, &py_dict, &init))
01172     return NULL;
01173 
01174   if (!PyDict_Check(py_dict)){
01175     PyErr_SetString(PyExc_TypeError,
01176                     "gc_board_config_radio_buttons second argument must be a dict");
01177     return NULL;
01178   }
01179 
01180   PyObject *pykey, *pyvalue;
01181   int pos = 0;
01182 
01183   buttons_label = g_hash_table_new_full (g_str_hash,
01184                                 g_str_equal,
01185                                 g_free,
01186                                 g_free);
01187 
01188   while (PyDict_Next(py_dict, &pos, &pykey, &pyvalue)) {
01189     g_hash_table_replace (buttons_label,
01190                        g_strdup(PyString_AsString(pykey)),
01191                        g_strdup(PyString_AsString(pyvalue)));
01192   }
01193 
01194   result = gc_board_config_radio_buttons(label,
01195                               key,
01196                               buttons_label,
01197                               init);
01198 
01199   g_hash_table_destroy(buttons_label);
01200 
01201   return hash_object_to_dict(result);
01202 }
01203 
01204 static PyObject*
01205 py_gc_board_config_spin_int(PyObject* self, PyObject* args)
01206 {
01207   gchar *label;
01208   gchar *key;
01209   gint min, max, step, init;
01210 
01211   /* Parse arguments */
01212   if(!PyArg_ParseTuple(args, "ssiiii:gc_board_config_radio_buttons", &label, &key, &min, &max, &step, &init))
01213     return NULL;
01214 
01215   return (PyObject *)pygobject_new((GObject*) \
01216                                gc_board_config_spin_int((const gchar *)label,
01217                                                key,
01218                                                min,
01219                                                max,
01220                                                step,
01221                                                init));
01222 
01223 }
01224 
01225 
01226 /* GtkHSeparator *gc_board_conf_separator(void); */
01227 static PyObject*
01228 py_gc_board_conf_separator(PyObject* self, PyObject* args)
01229 {
01230   /* Parse arguments */
01231   if(!PyArg_ParseTuple(args, ":gc_board_conf_separator"))
01232     return NULL;
01233 
01234   /* Create and return the result */
01235   return (PyObject *)pygobject_new((GObject*) gc_board_conf_separator());
01236 
01237 }
01238 
01239 
01240 static PyObject*
01241 py_gc_board_config_combo_locales(PyObject* self, PyObject* args)
01242 {
01243   gchar *init;
01244 
01245   /* Parse arguments */
01246   if(!PyArg_ParseTuple(args, "s:gc_board_config_combo_locales", &init))
01247     return NULL;
01248 
01249   return (PyObject *)pygobject_new((GObject*) \
01250                                gc_board_config_combo_locales( init));
01251 }
01252 
01253 
01254 static PyObject*
01255 py_gc_locale_gets_list(PyObject* self, PyObject* args)
01256 {
01257   PyObject *pylist;
01258   GList *result, *list ;
01259 
01260   /* Parse arguments */
01261   if(!PyArg_ParseTuple(args, ":gcompris.get_locales_list"))
01262     return NULL;
01263 
01264   /* Call the corresponding C function */
01265   result = gc_locale_gets_list();
01266 
01267   pylist = PyList_New(0);
01268 
01269   for (list = result; list != NULL; list = list->next){
01270     PyList_Append( pylist, PyString_FromString(list->data));
01271   }
01272 
01273   Py_INCREF(pylist);
01274   return pylist;
01275 }
01276 
01277 
01278 static PyObject*
01279 py_gc_board_config_combo_locales_asset(PyObject* self, PyObject* args)
01280 {
01281   gchar *init;
01282   gchar *label;
01283   gchar *file;
01284 
01285   /* Parse arguments */
01286   if(!PyArg_ParseTuple(args, "ssz:gc_board_config_combo_locales",
01287                      &label,
01288                      &init,
01289                      &file))
01290     return NULL;
01291 
01292   return (PyObject *)pygobject_new((GObject*) \
01293                                gc_board_config_combo_locales_asset( label, init, file ));
01294 }
01295 
01296 
01297 static PyObject*
01298 py_gc_locale_gets_asset_list(PyObject* self, PyObject* args)
01299 {
01300   PyObject *pylist;
01301   GList *result, *list ;
01302   gchar *file;
01303 
01304   /* Parse arguments */
01305   if(!PyArg_ParseTuple(args, "z:gcompris.get_locales_asset_list",
01306                      &file))
01307     return NULL;
01308 
01309   /* Call the corresponding C function */
01310   result = gc_locale_gets_asset_list(file);
01311 
01312   pylist = PyList_New(0);
01313 
01314   for (list = result; list != NULL; list = list->next){
01315     PyList_Append( pylist, PyString_FromString(list->data));
01316   }
01317 
01318   Py_INCREF(pylist);
01319   return pylist;
01320 }
01321 
01322 
01323 
01324 static PyObject*
01325 py_gcompris_gettext(PyObject* self, PyObject* args)
01326 {
01327   gchar *text;
01328 
01329   /* Parse arguments */
01330   if(!PyArg_ParseTuple(args, "s:gcompris_gettext", &text))
01331     return NULL;
01332 
01333   return PyString_FromString(_(text));
01334 }
01335 
01336 
01337 
01338 /* void gc_locale_change(gchar *locale); */
01339 static PyObject*
01340 py_gc_locale_change(PyObject* self, PyObject* args)
01341 {
01342   gchar *locale;
01343 
01344   /* Parse arguments */
01345   if(!PyArg_ParseTuple(args, "s:gc_locale_change", &locale))
01346     return NULL;
01347 
01348   /* Call the corresponding C function */
01349   gc_locale_set(locale);
01350 
01351   /* Create and return the result */
01352   Py_INCREF(Py_None);
01353   return Py_None;
01354 }
01355 
01356 
01357 /* void gc_locale_reset(gchar *locale); */
01358 static PyObject*
01359 py_gc_locale_reset(PyObject* self, PyObject* args)
01360 {
01361   /* Parse arguments */
01362   if(!PyArg_ParseTuple(args, ":gc_locale_reset"))
01363     return NULL;
01364 
01365   /* Call the corresponding C function */
01366   gc_locale_reset();
01367 
01368   /* Create and return the result */
01369   Py_INCREF(Py_None);
01370   return Py_None;
01371 }
01372 
01373 
01374 /* How can i free that ? */
01375 static GHashTable *text_callbacks = NULL;
01376 
01377 static gboolean pyGcomprisTextCallback(gchar *key, gchar *text, GtkLabel *label){
01378   PyObject* result;
01379   gboolean validate;
01380 
01381   PyGILState_STATE gil;
01382 
01383   PyObject* pyGcomprisTextCallbackFunc = g_hash_table_lookup( text_callbacks, key);
01384 
01385   if(pyGcomprisTextCallbackFunc==NULL) return FALSE;
01386 
01387   gil = pyg_gil_state_ensure();
01388 
01389   result = PyObject_CallFunction(pyGcomprisTextCallbackFunc, "ssO", key, text,(PyObject *)pygobject_new((GObject*) label ));
01390 
01391   //Py_DECREF(pyGcomprisTextCallbackFunc);
01392 
01393   if (PyObject_IsTrue(result))
01394     validate = TRUE;
01395   else
01396     validate = FALSE;
01397 
01398   if(result==NULL){
01399     PyErr_Print();
01400   } else {
01401     Py_DECREF(result);
01402   }
01403 
01404   pyg_gil_state_release(gil);
01405 
01406   return validate;
01407 
01408 }
01409 
01410 
01411 static PyObject*
01412 py_gc_board_config_textview(PyObject* self, PyObject* args){
01413   PyObject* pyCallback;
01414   gchar *label;
01415   gchar *key;
01416   gchar *desc = NULL;
01417   gchar *init_text = NULL;
01418 
01419   /* Parse arguments */
01420   if(!PyArg_ParseTuple(args,
01421                      "sszzO:gc_board_config_window_display",
01422                      &label,
01423                      &key,
01424                      &desc,
01425                      &init_text,
01426                      &pyCallback))
01427     return NULL;
01428   if(!PyCallable_Check(pyCallback))
01429     {
01430       PyErr_SetString(PyExc_TypeError,
01431                     "gc_board_config_textview 5th argument must be callable");
01432       return NULL;
01433     }
01434 
01435   if (!text_callbacks)
01436     text_callbacks = g_hash_table_new ( g_str_hash, g_str_equal);
01437 
01438   g_hash_table_replace (text_callbacks, key, pyCallback);
01439 
01440   Py_INCREF(pyCallback);
01441 
01442   return (PyObject *) \
01443              pygobject_new((GObject*) \
01444                         gc_board_config_textview( label,
01445                                          key,
01446                                          desc,
01447                                          init_text,
01448                                          (GcomprisTextCallback )pyGcomprisTextCallback));
01449 
01450 }
01451 
01452 
01453 static PyObject*
01454 py_gc_prop_user_dirname_get (PyObject* self, PyObject* args)
01455 {
01456   PyObject* pyUser;
01457   pyGcomprisUserObject* pyGcomprisUser;
01458   GcomprisUser* cGcomprisUser;
01459 
01460   /* Parse arguments */
01461   if(!PyArg_ParseTuple(args, "O:gcompris.get_user_dirname", &pyUser))
01462     return NULL;
01463 
01464   pyGcomprisUser = (pyGcomprisUserObject *) pyUser;
01465 
01466   cGcomprisUser = pyGcomprisUser->cdata;
01467 
01468   /* Call the corresponding C function */
01469   return PyString_FromString(gc_prop_user_dirname_get(cGcomprisUser));
01470 
01471 }
01472 
01473 static PyObject*
01474 py_gc_prop_board_dirname_get (PyObject* self, PyObject* args)
01475 {
01476   PyObject* pyBoard;
01477   pyGcomprisBoardObject* pyGcomprisBoard;
01478   GcomprisBoard* cGcomprisBoard;
01479 
01480   /* Parse arguments */
01481   if(!PyArg_ParseTuple(args, "O:gcompris.get_board_dirname", &pyBoard))
01482     return NULL;
01483 
01484   pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
01485 
01486   cGcomprisBoard = pyGcomprisBoard->cdata;
01487 
01488   /* Call the corresponding C function */
01489   return PyString_FromString(gc_prop_board_dirname_get(cGcomprisBoard));
01490 
01491 }
01492 
01493 static PyObject*
01494 py_gc_prop_current_user_dirname_get (PyObject* self, PyObject* args)
01495 {
01496   /* Parse arguments */
01497   if(!PyArg_ParseTuple(args, ":gcompris.get_current_user_dirname"))
01498     return NULL;
01499 
01500   /* Call the corresponding C function */
01501   return PyString_FromString(gc_prop_current_user_dirname_get());
01502 
01503 }
01504 
01505 static PyObject*
01506 py_gc_prop_current_board_dirname_get (PyObject* self, PyObject* args)
01507 {
01508   /* Parse arguments */
01509   if(!PyArg_ParseTuple(args, ":gcompris.get_current_board_dirname"))
01510     return NULL;
01511 
01512   /* Call the corresponding C function */
01513   return PyString_FromString(gc_prop_current_board_dirname_get());
01514 
01515 }
01516 
01517 static PyObject*
01518 py_gcompris_wordlist_get_from_file (PyObject* self, PyObject* args)
01519 {
01520   GcomprisWordlist *result;
01521   gchar *filename;
01522   /* Parse arguments */
01523   if(!PyArg_ParseTuple(args, "s:gcompris.get_wordlist", &filename))
01524     return NULL;
01525 
01526   /* Call the corresponding C function */
01527   result = gc_wordlist_get_from_file (filename);
01528   if (result)
01529     return gcompris_new_pyGcomprisWordlistObject(result);
01530   else {
01531     Py_INCREF(Py_None);
01532     return Py_None;
01533   }
01534 }
01535 
01536 static PyObject*
01537 py_gc_im_reset (PyObject* self, PyObject* args)
01538 {
01539 
01540   /* Parse arguments */
01541   if(!PyArg_ParseTuple(args, ":gcompris.im_reset"))
01542     return NULL;
01543 
01544   /* Call the corresponding C function */
01545   gc_im_reset ();
01546 
01547   Py_INCREF(Py_None);
01548   return Py_None;
01549 }
01550 
01551 
01552 
01553 /****************************************************/
01554 
01555 static PyMethodDef PythonGcomprisModule[] = {
01556   { "end_board",  py_gc_board_end, METH_VARARGS, "gc_board_end" },
01557   { "bar_start",  py_gc_bar_start, METH_VARARGS, "gc_bar_start" },
01558   { "set_background",  py_gc_set_background, METH_VARARGS, "gc_set_background" },
01559   { "bar_set_level",  py_gc_bar_set_level, METH_VARARGS, "gc_bar_set_level" },
01560   { "bar_set_repeat_icon",  py_gc_bar_set_repeat_icon, METH_VARARGS, "gc_bar_set_repeat_icon" },
01561   { "bar_set",  py_gc_bar_set, METH_VARARGS, "gc_bar_set" },
01562   { "bar_hide",  py_gc_bar_hide, METH_VARARGS, "gc_bar_hide" },
01563   { "get_canvas",  py_gc_get_canvas, METH_VARARGS, "gc_get_canvas" },
01564   { "get_window",  py_gc_get_window, METH_VARARGS, "gc_get_window" },
01565   { "get_locale",  py_gc_locale_get, METH_VARARGS, "gc_locale_get" },
01566   { "get_user_default_locale",  py_gc_locale_get_user_default, METH_VARARGS, "gc_locale_get_user_default" },
01567   { "set_locale",  py_gc_locale_set, METH_VARARGS, "gc_locale_set" },
01568   { "set_cursor",  py_gc_cursor_set, METH_VARARGS, "gc_cursor_set" },
01569   { "images_selector_start",  py_gc_selector_images_start,
01570     METH_VARARGS, "gc_selector_images_start" },
01571   { "images_selector_stop",  py_gc_selector_images_stop,
01572     METH_VARARGS, "gc_selector_images_stop" },
01573   { "log_set_comment",  py_gc_log_set_comment, METH_VARARGS, "gc_log_set_comment" },
01574   { "log_end",  py_gc_log_end, METH_VARARGS, "gc_log_end" },
01575   { "file_selector_load",  py_gc_selector_file_load,
01576     METH_VARARGS, "gc_selector_file_load" },
01577   { "file_selector_save",  py_gc_selector_file_save,
01578     METH_VARARGS, "gc_selector_file_save" },
01579   { "file_selector_stop",  py_gc_selector_file_stop,
01580     METH_VARARGS, "gc_selector_file_stop" },
01581   { "get_database",  py_gc_db_get_filename, METH_VARARGS, "gc_db_get_filename" },
01582   { "get_properties",  py_gc_prop_get, METH_VARARGS, "gc_prop_get" },
01583   { "get_board_from_section",  py_gc_menu_section_get, METH_VARARGS, "gc_menu_section_get" },
01584   { "spawn_async",  (PyCFunction)py_gcompris_spawn_async, METH_VARARGS|METH_KEYWORDS, "gcompris_spawn_sync" },
01585   { "child_watch_add",  (PyCFunction)py_gcompris_child_watch_add, METH_VARARGS|METH_KEYWORDS, "gcompris_child_watch_add" },
01586   { "get_board_conf",  py_gc_db_get_board_conf, METH_VARARGS, "gc_db_get_board_conf" },
01587   { "get_conf",  py_gc_db_get_conf, METH_VARARGS, "gc_db_get_conf" },
01588   { "set_board_conf",  py_gc_db_set_board_conf, METH_VARARGS, "gc_db_set_board_conf" },
01589   { "get_current_profile",  py_gc_profile_get_current, METH_VARARGS, "gc_profile_get_current" },
01590   { "get_current_user",  py_gc_profile_get_current_user, METH_VARARGS, "gc_profile_get_current_user" },
01591   { "configuration_window",  py_gc_board_config_window_display, METH_VARARGS, "gc_board_config_window_display" },
01592   { "boolean_box",  py_gc_board_config_boolean_box, METH_VARARGS, "gc_board_config_boolean_box" },
01593   { "combo_box",  py_gc_board_config_combo_box, METH_VARARGS, "gc_board_config_combo_box" },
01594   { "radio_buttons",  py_gc_board_config_radio_buttons, METH_VARARGS, "gc_board_config_radio_buttons" },
01595   { "spin_int",  py_gc_board_config_spin_int, METH_VARARGS, "gc_board_config_spin_int" },
01596   { "separator",  py_gc_board_conf_separator, METH_VARARGS, "gc_board_conf_separator" },
01597   { "combo_locales",  py_gc_board_config_combo_locales, METH_VARARGS, "gc_board_config_combo_locales" },
01598   { "get_locales_list",  py_gc_locale_gets_list, METH_VARARGS, "gc_locale_gets_list" },
01599   { "gcompris_gettext",  py_gcompris_gettext, METH_VARARGS, "gcompris_gettext" },
01600   { "change_locale",  py_gc_locale_change, METH_VARARGS, "gc_locale_change" },
01601   { "reset_locale",  py_gc_locale_reset, METH_VARARGS, "gc_locale_reset" },
01602   { "combo_locales_asset",  py_gc_board_config_combo_locales_asset, METH_VARARGS, "gc_board_config_combo_locales_asset" },
01603   { "get_locales_asset_list",  py_gc_locale_gets_asset_list, METH_VARARGS, "gc_locale_gets_asset_list" },
01604   { "textview",  py_gc_board_config_textview, METH_VARARGS, "gc_board_config_textview" },
01605   { "get_user_dirname",  py_gc_prop_user_dirname_get, METH_VARARGS, "gc_prop_user_dirname_get" },
01606   { "get_current_user_dirname",  py_gc_prop_current_user_dirname_get, METH_VARARGS, "gc_prop_current_user_dirname_get" },
01607   { "get_board_dirname",  py_gc_prop_board_dirname_get, METH_VARARGS, "gc_prop_board_dirname_get" },
01608   { "get_current_board_dirname",  py_gc_prop_current_board_dirname_get, METH_VARARGS, "gc_prop_current_board_dirname_get" },
01609   { "get_wordlist",  py_gcompris_wordlist_get_from_file, METH_VARARGS, "gcompris_wordlist_get_from_file" },
01610   { "im_reset",  py_gc_im_reset, METH_VARARGS, "gc_im_reset" },
01611   { NULL, NULL, 0, NULL}
01612 };
01613 
01614 void python_gcompris_module_init(void)
01615 {
01616   PyObject* gcomprisModule;
01617 
01618   gcomprisModule = Py_InitModule("_gcompris", PythonGcomprisModule);
01619 
01620   /* Misc constants */
01621   PyModule_AddIntConstant(gcomprisModule, "BOARD_HEIGHT", BOARDHEIGHT );
01622   PyModule_AddIntConstant(gcomprisModule, "BOARD_WIDTH",  BOARDWIDTH);
01623   PyModule_AddIntConstant(gcomprisModule, "BAR_HEIGHT",   BARHEIGHT);
01624   PyModule_AddStringConstant(gcomprisModule, "DEFAULT_SKIN", DEFAULT_SKIN);
01625 
01626   /* The GComprisBarFlags enum constants */
01627   PyModule_AddIntConstant(gcomprisModule, "BAR_LEVEL",       GC_BAR_LEVEL);
01628   PyModule_AddIntConstant(gcomprisModule, "BAR_OK",          GC_BAR_OK);
01629   PyModule_AddIntConstant(gcomprisModule, "BAR_REPEAT",      GC_BAR_REPEAT);
01630   PyModule_AddIntConstant(gcomprisModule, "BAR_REPEAT_ICON", GC_BAR_REPEAT_ICON);
01631   PyModule_AddIntConstant(gcomprisModule, "BAR_CONFIG",      GC_BAR_CONFIG);
01632   PyModule_AddIntConstant(gcomprisModule, "BAR_ABOUT",       GC_BAR_ABOUT);
01633 
01634   /* Colors constants */
01635   PyModule_AddIntConstant(gcomprisModule, "COLOR_TITLE",       COLOR_TITLE);
01636   PyModule_AddIntConstant(gcomprisModule, "COLOR_TEXT_BUTTON", COLOR_TEXT_BUTTON);
01637   PyModule_AddIntConstant(gcomprisModule, "COLOR_CONTENT",     COLOR_CONTENT);
01638   PyModule_AddIntConstant(gcomprisModule, "COLOR_SUBTITLE",    COLOR_SUBTITLE);
01639 
01640   /* Fonts constants */
01641   PyModule_AddStringConstant(gcomprisModule, "FONT_TITLE",             FONT_TITLE);
01642   PyModule_AddStringConstant(gcomprisModule, "FONT_TITLE_FALLBACK",    FONT_TITLE_FALLBACK);
01643   PyModule_AddStringConstant(gcomprisModule, "FONT_SUBTITLE",          FONT_SUBTITLE);
01644   PyModule_AddStringConstant(gcomprisModule, "FONT_SUBTITLE_FALLBACK", FONT_SUBTITLE_FALLBACK);
01645   PyModule_AddStringConstant(gcomprisModule, "FONT_CONTENT",           FONT_CONTENT);
01646   PyModule_AddStringConstant(gcomprisModule, "FONT_CONTENT_FALLBACK",  FONT_CONTENT_FALLBACK);
01647 
01648   /* Fonts board constants */
01649   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_TINY",       FONT_BOARD_TINY);
01650   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_SMALL",      FONT_BOARD_SMALL);
01651   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_MEDIUM",     FONT_BOARD_MEDIUM);
01652   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_BIG",        FONT_BOARD_BIG);
01653   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_BIG_BOLD",   FONT_BOARD_BIG_BOLD);
01654   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_FIXED",      FONT_BOARD_FIXED);
01655   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_TITLE",      FONT_BOARD_TITLE);
01656   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_TITLE_BOLD", FONT_BOARD_TITLE_BOLD);
01657   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_HUGE",       FONT_BOARD_HUGE);
01658   PyModule_AddStringConstant(gcomprisModule, "FONT_BOARD_HUGE_BOLD",  FONT_BOARD_HUGE_BOLD);
01659 
01660   /* Cursors constants */
01661   PyModule_AddIntConstant(gcomprisModule, "CURSOR_FIRST_CUSTOM",  GCOMPRIS_FIRST_CUSTOM_CURSOR);
01662   PyModule_AddIntConstant(gcomprisModule, "CURSOR_BIG_RED_ARROW", GCOMPRIS_BIG_RED_ARROW_CURSOR);
01663   PyModule_AddIntConstant(gcomprisModule, "CURSOR_BIRD",          GCOMPRIS_BIRD_CURSOR);
01664   PyModule_AddIntConstant(gcomprisModule, "CURSOR_LINE",          GCOMPRIS_LINE_CURSOR);
01665   PyModule_AddIntConstant(gcomprisModule, "CURSOR_FILLRECT",      GCOMPRIS_FILLRECT_CURSOR);
01666   PyModule_AddIntConstant(gcomprisModule, "CURSOR_RECT",          GCOMPRIS_RECT_CURSOR);
01667   PyModule_AddIntConstant(gcomprisModule, "CURSOR_FILLCIRCLE",    GCOMPRIS_FILLCIRCLE_CURSOR);
01668   PyModule_AddIntConstant(gcomprisModule, "CURSOR_CIRCLE",        GCOMPRIS_CIRCLE_CURSOR);
01669   PyModule_AddIntConstant(gcomprisModule, "CURSOR_DEL",           GCOMPRIS_DEL_CURSOR);
01670   PyModule_AddIntConstant(gcomprisModule, "CURSOR_FILL",          GCOMPRIS_FILL_CURSOR);
01671   PyModule_AddIntConstant(gcomprisModule, "CURSOR_SELECT",        GCOMPRIS_SELECT_CURSOR);
01672   PyModule_AddIntConstant(gcomprisModule, "CURSOR_DEFAULT",       GCOMPRIS_DEFAULT_CURSOR);
01673 
01674   /* Some non gcompris.h constants. */
01675   GcomprisProperties *properties = gc_prop_get();
01676   PyModule_AddStringConstant(gcomprisModule, "DATA_DIR", properties->package_data_dir);
01677   PyModule_AddStringConstant(gcomprisModule, "PYTHON_PLUGIN_DIR", properties->package_python_plugin_dir);
01678 
01679   /* GetText constants. */
01680   PyModule_AddStringConstant(gcomprisModule, "GETTEXT_PACKAGE", GETTEXT_PACKAGE);
01681   PyModule_AddStringConstant(gcomprisModule, "PACKAGE_LOCALE_DIR",  PACKAGE_LOCALE_DIR);
01682 
01683 
01684   /* Initialize the sub modules */
01685   initgnomecanvas();
01686   python_gcompris_bonus_module_init();
01687   python_gc_score_module_init();
01688   python_gc_skin_module_init();
01689   python_gcompris_sound_module_init();
01690   python_gc_timer_module_init();
01691   python_gcompris_utils_module_init();
01692   python_gcompris_anim_module_init();
01693   python_gcompris_admin_module_init();
01694 }
01695 
01696 /* Some usefull code parts ... */
01697 /*
01698 static PyObject*
01699 py_gcompris_(PyObject* self, PyObject* args)
01700 {
01701 */  /* Parse arguments */
01702 /*  if(!PyArg_ParseTuple(args, ":gcompris_"))
01703     return NULL;
01704 */
01705   /* Call the corresponding C function */
01706 /*  gcompris_();
01707 */
01708   /* Create and return the result */
01709 /*  Py_INCREF(Py_None);
01710   return Py_None;
01711 }
01712 */
01713 /*
01714   { "",  py_gcompris_, METH_VARARGS, "gcompris_" },
01715 */