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

« back to all changes in this revision

Viewing changes to src/boards/py-gcompris-user.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-profile.h"
 
2
#include <pygobject.h>
 
3
 
 
4
staticforward PyTypeObject pyGcomprisUserType;
 
5
 
 
6
//static char pyGcomprisUserType_doc[]= "Python GcomprisBoars structure binding";
 
7
 
 
8
 
 
9
/* Special function created for the python plugin to be able to create
 
10
 * a pyGcomprisBoardObject form the existing GcomprisBoard structure
 
11
 */
 
12
PyObject*
 
13
gcompris_new_pyGcomprisUserObject(GcomprisUser* user)
 
14
{
 
15
  pyGcomprisUserObject* theuser = NULL;
 
16
 
 
17
  theuser = PyObject_New(pyGcomprisUserObject, &pyGcomprisUserType);
 
18
  if (theuser!=NULL)
 
19
    theuser->cdata = user;
 
20
 
 
21
  return (PyObject*)theuser;
 
22
}
 
23
 
 
24
 
 
25
/* Free the python gcompris user */
 
26
static void
 
27
pyGcomprisUserType_dealloc(pyGcomprisUserObject *self)
 
28
{
 
29
  self->cdata = NULL;
 
30
  PyObject_DEL(self);
 
31
}
 
32
 
 
33
 
 
34
/* Methods defined in the pyGcomprisUser class */
 
35
static PyMethodDef pyGcomprisUserType_methods[] = {
 
36
        {NULL,          NULL}           /* sentinel */
 
37
};
 
38
 
 
39
 
 
40
/* Return the value of the members contained in the GcomprisUser structure */
 
41
static PyObject *
 
42
pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
 
43
{
 
44
    /* int */
 
45
    if(strcmp(name,"user_id")==0) return Py_BuildValue("i", self->cdata->user_id);
 
46
    /* int */
 
47
    if(strcmp(name,"class_id")==0) return Py_BuildValue("i", self->cdata->class_id);
 
48
    /* str */
 
49
    if(strcmp(name,"login")==0) return Py_BuildValue("s", self->cdata->login);
 
50
    /* str */
 
51
    if(strcmp(name,"lastname")==0) return Py_BuildValue("s", self->cdata->lastname);
 
52
    /* str */
 
53
    if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
 
54
    /* str */
 
55
    if(strcmp(name,"birthdate")==0) return Py_BuildValue("s", self->cdata->birthdate);
 
56
    /* u int */
 
57
    if(strcmp(name,"session_id")==0) return Py_BuildValue("i", self->cdata->session_id);
 
58
 
 
59
  return Py_FindMethod(pyGcomprisUserType_methods, (PyObject *)self, name);
 
60
}
 
61
 
 
62
/* Set the value of a GcomprisUser structure member */
 
63
static int
 
64
pyGcomprisUserType_setattr(pyGcomprisUserObject *self, char *name, PyObject *v)
 
65
{
 
66
  if (self->cdata==NULL) return -1;
 
67
  if (v==NULL) return -1;
 
68
 
 
69
  /*  if (strcmp(name,"level")==0){
 
70
    value = (int) PyInt_AsLong(v);
 
71
    if ( value < 0 ) return -1;
 
72
    self->cdata->level=value;
 
73
    return 0;
 
74
    } */
 
75
  /* members are supposed to be read only */
 
76
 
 
77
  return -1;
 
78
}
 
79
 
 
80
static PyTypeObject pyGcomprisUserType = {
 
81
#if defined(WIN32)
 
82
  PyObject_HEAD_INIT(NULL)
 
83
#else /* ! WIN32 */
 
84
  PyObject_HEAD_INIT(&PyType_Type)
 
85
#endif
 
86
  0,                                        /*ob_size*/
 
87
  "pyGcomprisUser",                        /*tp_name*/
 
88
  sizeof(pyGcomprisUserObject),            /*tp_basicsize*/
 
89
  0,                                        /*tp_itemsize*/
 
90
  /* methods */
 
91
  (destructor)pyGcomprisUserType_dealloc,  /*tp_dealloc*/
 
92
  0,                                        /*tp_print*/
 
93
  (getattrfunc)pyGcomprisUserType_getattr, /*tp_getattr*/
 
94
  (setattrfunc)pyGcomprisUserType_setattr, /*tp_setattr*/
 
95
  0,                                        /*tp_compare*/
 
96
  0,                                        /*tp_repr*/
 
97
  0,                                        /*tp_as_number*/
 
98
  0,                                        /*tp_as_sequence*/
 
99
  0,                                        /*tp_as_mapping*/
 
100
  0,                                        /*tp_hash*/
 
101
};