~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/boards/py-gcompris-wordlist.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "py-gcompris-wordlist.h"
 
2
#include <pygobject.h>
 
3
#include "py-gcompris-profile.h"
 
4
#include "py-gcompris-board.h"
 
5
 
 
6
staticforward PyTypeObject pyGcomprisWordlistType;
 
7
 
 
8
//static char pyGcomprisWordlistType_doc[]= "Python GcomprisBoars structure binding";
 
9
 
 
10
 
 
11
/* Special function created for the python plugin to be able to create
 
12
 * a pyGcomprisBoardObject form the existing GcomprisBoard structure
 
13
 */
 
14
PyObject*
 
15
gcompris_new_pyGcomprisWordlistObject(GcomprisWordlist* wordlist)
 
16
{
 
17
  pyGcomprisWordlistObject* thewordlist = NULL;
 
18
 
 
19
  thewordlist = PyObject_New(pyGcomprisWordlistObject, &pyGcomprisWordlistType);
 
20
  if (thewordlist!=NULL)
 
21
    thewordlist->cdata = wordlist;
 
22
 
 
23
  return (PyObject*)thewordlist;
 
24
}
 
25
 
 
26
 
 
27
/* Free the python gcompris wordlist */
 
28
static void
 
29
pyGcomprisWordlistType_dealloc(pyGcomprisWordlistObject *self)
 
30
{
 
31
  gc_wordlist_free((GcomprisWordlist *)self->cdata);
 
32
  self->cdata = NULL;
 
33
  PyObject_DEL(self);
 
34
}
 
35
 
 
36
 
 
37
/* Methods defined in the pyGcomprisWordlist class */
 
38
static PyMethodDef pyGcomprisWordlistType_methods[] = {
 
39
        {NULL,          NULL}           /* sentinel */
 
40
};
 
41
 
 
42
 
 
43
/* Return the value of the members contained in the GcomprisWordlist structure */
 
44
static PyObject *
 
45
pyGcomprisWordlistType_getattr(pyGcomprisWordlistObject *self, char *name)
 
46
{
 
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);
 
52
 
 
53
    /* list */
 
54
    if(strcmp(name,"words")==0){
 
55
      PyObject *pydict;
 
56
      PyObject *pylist;
 
57
      gint level;
 
58
      GSList *words;
 
59
      GSList *list, *list_words;
 
60
 
 
61
      pydict = PyDict_New();
 
62
 
 
63
      for (list = self->cdata->levels_words; list !=NULL; list = list->next){
 
64
        level =  ((LevelWordlist *)  list)->level;
 
65
        words = ((LevelWordlist *)  list)->words;
 
66
 
 
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));
 
70
        }
 
71
 
 
72
        PyDict_SetItem( pydict, PyInt_FromLong( (long) level), pylist);
 
73
 
 
74
      return pydict;
 
75
      }
 
76
    }
 
77
  }
 
78
 
 
79
  return Py_FindMethod(pyGcomprisWordlistType_methods, (PyObject *)self, name);
 
80
 
 
81
}
 
82
 
 
83
/* Set the value of a GcomprisWordlist structure member */
 
84
static int
 
85
pyGcomprisWordlistType_setattr(pyGcomprisWordlistObject *self, char *name, PyObject *v)
 
86
{
 
87
  /* members are supposed to be read only */
 
88
 
 
89
  return -1;
 
90
}
 
91
 
 
92
static PyTypeObject pyGcomprisWordlistType = {
 
93
#if defined(WIN32)
 
94
  PyObject_HEAD_INIT(NULL)
 
95
#else /* ! WIN32 */
 
96
  PyObject_HEAD_INIT(&PyType_Type)
 
97
#endif
 
98
  0,                                        /*ob_size*/
 
99
  "pyGcomprisWordlist",                        /*tp_name*/
 
100
  sizeof(pyGcomprisWordlistObject),            /*tp_basicsize*/
 
101
  0,                                        /*tp_itemsize*/
 
102
  /* methods */
 
103
  (destructor)pyGcomprisWordlistType_dealloc,  /*tp_dealloc*/
 
104
  0,                                        /*tp_print*/
 
105
  (getattrfunc)pyGcomprisWordlistType_getattr, /*tp_getattr*/
 
106
  (setattrfunc)pyGcomprisWordlistType_setattr, /*tp_setattr*/
 
107
  0,                                        /*tp_compare*/
 
108
  0,                                        /*tp_repr*/
 
109
  0,                                        /*tp_as_number*/
 
110
  0,                                        /*tp_as_sequence*/
 
111
  0,                                        /*tp_as_mapping*/
 
112
  0,                                        /*tp_hash*/
 
113
};