Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/boards/py-mod-timer.c
blob: 11da2baa9ae41276596aec0c354be3baa5d9e1a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <Python.h>
#define NO_IMPORT_PYGOBJECT 1
#include <pygobject.h>
#include "gcompris/gcompris.h"
#include "py-mod-utils.h"
#include "py-gcompris-board.h"

/* All functions provided by this python module
 * wraps a gcompris function. Each "py_*" function wraps the
 * "*" C function.
 */

/* typedef void (*GcomprisTimerEnd) (); */
static PyObject* pyTimerCallBackFunc = NULL;

void pyTimerCallBack(){
  PyObject* result;
  if(pyTimerCallBackFunc==NULL) return;

  /* Build arguments */
  result = PyObject_CallObject(pyTimerCallBackFunc, NULL);
  if(result==NULL){
    PyErr_Print();
  } else {
    Py_DECREF(result);
  }
}


/* void gc_timer_display
        (int x, int y, TimerList type, int second, GcomprisTimerEnd gcomprisTimerEnd); */
static PyObject*
py_gc_timer_display(PyObject* self, PyObject* args)
{
  int x,y;
  int type;
  int second;
  PyObject* pyCallback;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "iiiiO:gc_timer_display", &x, &y, &type, &second, &pyCallback))
    return NULL;
  if(!PyCallable_Check(pyCallback)) return NULL;
  pyTimerCallBackFunc = pyCallback;

  /* Call the corresponding C function */
  gc_timer_display(x, y, type, second, pyTimerCallBack );

  /* Create and return the result */
  Py_INCREF(Py_None);
  return Py_None;
}


/* void gc_timer_add(int second); */
static PyObject*
py_gc_timer_add(PyObject* self, PyObject* args)
{
  int second;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "i:gc_timer_add", &second))
    return NULL;

  /* Call the corresponding C function */
  gc_timer_add(second);

  /* Create and return the result */
  Py_INCREF(Py_None);
  return Py_None;
}


/*void gc_timer_end(void); */
static PyObject*
py_gc_timer_end(PyObject* self, PyObject* args)
{
  /* Parse arguments */
  if(!PyArg_ParseTuple(args, ":gc_timer_end"))
    return NULL;

  /* Call the corresponding C function */
  gc_timer_end();

  /* Create and return the result */
  Py_INCREF(Py_None);
  return Py_None;
}


/* guint gc_timer_get_remaining(); */
static PyObject*
py_gc_timer_get_remaining(PyObject* self, PyObject* args)
{
  guint result;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, ":gc_timer_get_remaining"))
    return NULL;

  /* Call the corresponding C function */
  result = gc_timer_get_remaining();

  /* Create and return the result */
  return Py_BuildValue("i", result);  
}


/* void	 gc_timer_pause(gboolean pause); */
static PyObject*
py_gc_timer_pause(PyObject* self, PyObject* args)
{
  gboolean pause;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "i:gc_timer_pause", &pause))
    return NULL;

  /* Call the corresponding C function */
  gc_timer_pause(pause);

  /* Create and return the result */
  Py_INCREF(Py_None);
  return Py_None;
}


static PyMethodDef PythonGcomprisTimerModule[] = {
  { "display",  py_gc_timer_display, METH_VARARGS, "gc_timer_display" },
  { "add",  py_gc_timer_add, METH_VARARGS, "gc_timer_add" },
  { "end",  py_gc_timer_end, METH_VARARGS, "gc_timer_end" },
  { "get_remaining",  py_gc_timer_get_remaining, METH_VARARGS, "gc_timer_get_remaining" },
  { "pause",  py_gc_timer_pause, METH_VARARGS, "gc_timer_pause" },
  { NULL, NULL, 0, NULL}
};

void python_gc_timer_module_init(void)
{
  PyObject* module;
  module = Py_InitModule("_gcompris_timer", PythonGcomprisTimerModule);

  /* TimerList constants */
  PyModule_AddIntConstant(module, "TEXT", GCOMPRIS_TIMER_TEXT );
  PyModule_AddIntConstant(module, "SAND", GCOMPRIS_TIMER_SAND );
  PyModule_AddIntConstant(module, "BALLOON", GCOMPRIS_TIMER_BALLOON );
  PyModule_AddIntConstant(module, "CLOCK", GCOMPRIS_TIMER_CLOCK );
}

/* Some usefull code parts ... */
/*
static PyObject*
py_gcompris_(PyObject* self, PyObject* args)
{
*/  /* Parse arguments */
/*  if(!PyArg_ParseTuple(args, ":gcompris_"))
    return NULL;
*/
  /* Call the corresponding C function */
/*  gcompris_();
*/
  /* Create and return the result */
/*  Py_INCREF(Py_None);
  return Py_None;
}
*/
/*
  { "",  py_gcompris_, METH_VARARGS, "gcompris_" },
*/