1
#include "py-gcompris-wordlist.h"
3
#include "py-gcompris-profile.h"
4
#include "py-gcompris-board.h"
6
staticforward PyTypeObject pyGcomprisWordlistType;
8
//static char pyGcomprisWordlistType_doc[]= "Python GcomprisBoars structure binding";
11
/* Special function created for the python plugin to be able to create
12
* a pyGcomprisBoardObject form the existing GcomprisBoard structure
15
gcompris_new_pyGcomprisWordlistObject(GcomprisWordlist* wordlist)
17
pyGcomprisWordlistObject* thewordlist = NULL;
19
thewordlist = PyObject_New(pyGcomprisWordlistObject, &pyGcomprisWordlistType);
20
if (thewordlist!=NULL)
21
thewordlist->cdata = wordlist;
23
return (PyObject*)thewordlist;
27
/* Free the python gcompris wordlist */
29
pyGcomprisWordlistType_dealloc(pyGcomprisWordlistObject *self)
31
gc_wordlist_free((GcomprisWordlist *)self->cdata);
37
/* Methods defined in the pyGcomprisWordlist class */
38
static PyMethodDef pyGcomprisWordlistType_methods[] = {
39
{NULL, NULL} /* sentinel */
43
/* Return the value of the members contained in the GcomprisWordlist structure */
45
pyGcomprisWordlistType_getattr(pyGcomprisWordlistObject *self, char *name)
47
if (self->cdata != NULL) {
48
/* Wordlist filename */
49
if(strcmp(name,"filename")==0) return Py_BuildValue("s", self->cdata->filename);
50
if(strcmp(name,"locale")==0) return Py_BuildValue("z", self->cdata->locale);
51
if(strcmp(name,"description")==0) return Py_BuildValue("z", self->cdata->description);
54
if(strcmp(name,"words")==0){
59
GSList *list, *list_words;
61
pydict = PyDict_New();
63
for (list = self->cdata->levels_words; list !=NULL; list = list->next){
64
level = ((LevelWordlist *) list)->level;
65
words = ((LevelWordlist *) list)->words;
67
pylist = PyList_New(0);
68
for (list_words = words; list_words !=NULL; list_words = list_words->next){
69
PyList_Append(pylist, Py_BuildValue("s", (gchar *)list->data));
72
PyDict_SetItem( pydict, PyInt_FromLong( (long) level), pylist);
79
return Py_FindMethod(pyGcomprisWordlistType_methods, (PyObject *)self, name);
83
/* Set the value of a GcomprisWordlist structure member */
85
pyGcomprisWordlistType_setattr(pyGcomprisWordlistObject *self, char *name, PyObject *v)
87
/* members are supposed to be read only */
92
static PyTypeObject pyGcomprisWordlistType = {
94
PyObject_HEAD_INIT(NULL)
96
PyObject_HEAD_INIT(&PyType_Type)
99
"pyGcomprisWordlist", /*tp_name*/
100
sizeof(pyGcomprisWordlistObject), /*tp_basicsize*/
103
(destructor)pyGcomprisWordlistType_dealloc, /*tp_dealloc*/
105
(getattrfunc)pyGcomprisWordlistType_getattr, /*tp_getattr*/
106
(setattrfunc)pyGcomprisWordlistType_setattr, /*tp_setattr*/
110
0, /*tp_as_sequence*/