[gcompris/gcomprixogoo] Added the method gcompris.get_random_word(wordlist, level) on the python side.
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris/gcomprixogoo] Added the method gcompris.get_random_word(wordlist, level) on the python side.
- Date: Sun, 22 Aug 2010 09:50:25 +0000 (UTC)
commit 1335698021c853faef7a8d177d8ba93f3918b702
Author: Bruno Coudoin <bruno coudoin free fr>
Date: Sun Aug 22 11:49:36 2010 +0200
Added the method gcompris.get_random_word(wordlist, level) on the python side.
docs/C/python.xml | 10 ++++++++++
src/boards/py-gcompris-wordlist.c | 27 +++++++++++++++------------
src/boards/py-mod-gcompris.c | 29 ++++++++++++++++++++++++++++-
3 files changed, 53 insertions(+), 13 deletions(-)
---
diff --git a/docs/C/python.xml b/docs/C/python.xml
index da846b6..b588687 100644
--- a/docs/C/python.xml
+++ b/docs/C/python.xml
@@ -278,6 +278,16 @@ attribute is readeable and/or writable.</para>
<entry>gchar* gc_db_get_filename(void)</entry>
<entry>return the filename (string) of the database (fullpath)</entry>
</row>
+ <row>
+ <entry>gcompris.get_wordlist()</entry>
+ <entry>GcomprisWordlist* gc_wordlist_get_from_file(const gchar *fileformat, ...)</entry>
+ <entry>Return a WordList object loaded from the given file. It can be loaded with "wordsgame/default-$LOCALE.xml"</entry>
+ </row>
+ <row>
+ <entry>gcompris.get_random_word(wordlist, level)</entry>
+ <entry>gchar* gc_wordlist_random_word_get(GcomprisWordlist *wordlist, guint level)</entry>
+ <entry>Return a random word from the previously loaded wordlist object and the specified level.</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
diff --git a/src/boards/py-gcompris-wordlist.c b/src/boards/py-gcompris-wordlist.c
index 62c347c..8a1e14b 100644
--- a/src/boards/py-gcompris-wordlist.c
+++ b/src/boards/py-gcompris-wordlist.c
@@ -1,4 +1,4 @@
-/* gcompris - py-mod-gcompris.c
+/* gcompris
*
* Copyright (C) 2003, 2008 Olivier Samyn <osamyn ulb ac be>
*
@@ -63,28 +63,31 @@ static PyObject *
pyGcomprisWordlistType_getattr(pyGcomprisWordlistObject *self, char *name)
{
if (self->cdata != NULL) {
+ GcomprisWordlist *wl = self->cdata;
/* Wordlist filename */
- if(strcmp(name,"filename")==0) return Py_BuildValue("s", self->cdata->filename);
- if(strcmp(name,"locale")==0) return Py_BuildValue("z", self->cdata->locale);
- if(strcmp(name,"description")==0) return Py_BuildValue("z", self->cdata->description);
+ if(strcmp(name,"filename")==0) return Py_BuildValue("s", wl->filename);
+ if(strcmp(name,"locale")==0) return Py_BuildValue("z", wl->locale);
+ if(strcmp(name,"description")==0) return Py_BuildValue("z", wl->description);
+ if(strcmp(name,"number_of_level")==0) return Py_BuildValue("i", wl->number_of_level);
/* list */
if(strcmp(name,"words")==0){
PyObject *pydict;
PyObject *pylist;
- gint level;
- GSList *words;
- GSList *list, *list_words;
+ GSList *levelList, *list_words;
pydict = PyDict_New();
- for (list = self->cdata->levels_words; list !=NULL; list = list->next){
- level = ((LevelWordlist *) list)->level;
- words = ((LevelWordlist *) list)->words;
+ // Fixme does not work, I get only the level 2 no idea why
+ for (levelList = wl->levels_words; levelList;
+ levelList = levelList->next){
+ LevelWordlist *lw = levelList->data;
+ gint level = lw->level;
pylist = PyList_New(0);
- for (list_words = words; list_words !=NULL; list_words = list_words->next){
- PyList_Append(pylist, Py_BuildValue("s", (gchar *)list->data));
+ for (list_words = lw->words; list_words !=NULL;
+ list_words = list_words->next){
+ PyList_Append(pylist, Py_BuildValue("s", (gchar *)list_words->data));
}
PyDict_SetItem( pydict, PyInt_FromLong( (long) level), pylist);
diff --git a/src/boards/py-mod-gcompris.c b/src/boards/py-mod-gcompris.c
index fc7a6ae..a35219e 100644
--- a/src/boards/py-mod-gcompris.c
+++ b/src/boards/py-mod-gcompris.c
@@ -1576,6 +1576,32 @@ py_gcompris_wordlist_get_from_file (PyObject* self, PyObject* args)
}
static PyObject*
+py_gcompris_wordlist_get_random_word (PyObject* self, PyObject* args)
+{
+ PyObject* pyGcWordList;
+ GcomprisWordlist *gcWordList;
+ gint level;
+ gchar *result;
+ /* Parse arguments */
+ if(!PyArg_ParseTuple(args, "Oi:get_random_word", &pyGcWordList, &level))
+ return NULL;
+ gcWordList = (GcomprisWordlist*) pygobject_get(pyGcWordList);
+
+ printf("level=%d\n", level);
+ printf("worldlist nol=%d\n", gcWordList->number_of_level);
+ printf("worldlist locale name=%s\n", gcWordList->name);
+ /* Call the corresponding C function */
+ result = gc_wordlist_random_word_get (gcWordList, level);
+
+ if (result)
+ return PyString_FromString(result);
+ else {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+}
+
+static PyObject*
py_gc_im_reset (PyObject* self, PyObject* args)
{
@@ -1647,7 +1673,8 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "combo_locales_asset", py_gc_board_config_combo_locales_asset, METH_VARARGS, "gc_board_config_combo_locales_asset" },
{ "get_locales_asset_list", py_gc_locale_gets_asset_list, METH_VARARGS, "gc_locale_gets_asset_list" },
{ "textview", py_gc_board_config_textview, METH_VARARGS, "gc_board_config_textview" },
- { "get_wordlist", py_gcompris_wordlist_get_from_file, METH_VARARGS, "gcompris_wordlist_get_from_file" },
+ { "get_wordlist", py_gcompris_wordlist_get_from_file, METH_VARARGS, "gc_wordlist_get_from_file" },
+ { "get_random_word", py_gcompris_wordlist_get_random_word, METH_VARARGS, "gc_wordlist_random_word_get" },
{ "im_reset", py_gc_im_reset, METH_VARARGS, "gc_im_reset" },
{ NULL, NULL, 0, NULL}
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]