Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/boards/py-mod-utils.c
blob: ab6c593aa85425bf984110f6e2895aa7a1b9fd9c (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <Python.h>
#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.
 */


/* GdkPixbuf *gcompris_load_number_pixmap(char number); */
static PyObject*
py_gcompris_load_number_pixmap(PyObject* self, PyObject* args)
{
  char value;
  GdkPixbuf* result;
  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "b:gcompris_load_number_pixmap", &value))
    return NULL;

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

  /* Create and return the result */
  return(PyObject*)pygobject_new((GObject*) result);
}


/* GdkPixbuf *gcompris_load_pixmap(char *pixmapfile); */
static PyObject*
py_gcompris_load_pixmap(PyObject* self, PyObject* args)
{
  char* pixmapfile;
  GdkPixbuf* result;
  /* Parse arguments */

  if(!PyArg_ParseTuple(args, "s:gcompris_load_pixmap", &pixmapfile))
    return NULL;

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

  /* Create and return the result */
  return (PyObject*) pygobject_new((GObject*) result);
}


/* void	gcompris_set_image_focus(GnomeCanvasItem *item, gboolean focus); */
static PyObject*
py_gcompris_set_image_focus(PyObject* self, PyObject* args)
{
  PyObject* pyitem;
  GnomeCanvasItem* item;
  gint pyfocus;
  gboolean focus;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "Oi:gcompris_set_image_focus"), &pyitem, &pyfocus)
    return NULL;
  item = (GnomeCanvasItem*) pygobject_get(pyitem);
  if(pyfocus>0) focus = TRUE;
  else focus = FALSE;

  /* Call the corresponding C function */
  gcompris_set_image_focus(item, focus);

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


/* gint	gcompris_item_event_focus(GnomeCanvasItem *item,
                                  GdkEvent *event,
                                  GnomeCanvasItem *dest_item);
*/
static PyObject*
py_gcompris_item_event_focus(PyObject* self, PyObject* args)
{
  PyObject* pyitem;
  GnomeCanvasItem* item;
  PyObject* pyevent;
  GdkEvent* event;
  PyObject* pydest_item;
  GnomeCanvasItem* dest_item;
  gint result;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "OOO:gcompris_item_event_focus", &pyitem, &pyevent, &pydest_item))
    return NULL;
  item = (GnomeCanvasItem*) pygobject_get(pyitem);
  event = (GdkEvent*) pygobject_get(pyevent);
  dest_item = (GnomeCanvasItem*) pygobject_get(pydest_item);

  /* Call the corresponding C function */
  result = gcompris_item_event_focus(item, event, dest_item);

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


/* void item_absolute_move(GnomeCanvasItem *item, int x, int y); */
static PyObject*
py_gcompris_item_absolute_move(PyObject* self, PyObject* args)
{
  PyObject* pyitem;
  GnomeCanvasItem* item;
  int x, y;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "Oii:gcompris_item_absolute_move", &pyitem, &x, &y))
    return NULL;
  item = (GnomeCanvasItem*) pygobject_get(pyitem);

  /* Call the corresponding C function */
  item_absolute_move(item, x, y);

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


/* void item_rotate(GnomeCanvasItem *item, double angle); */
static PyObject*
py_gcompris_item_rotate(PyObject* self, PyObject* args)
{
  PyObject* pyitem;
  GnomeCanvasItem* item;
  double angle;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "Od:gcompris_item_rotate", &pyitem, &angle))
    return NULL;
  item = (GnomeCanvasItem*) pygobject_get(pyitem);

  /* Call the corresponding C function */
  item_rotate(item, angle);

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


/* void item_rotate_with_center(GnomeCanvasItem *item, double angle, int x, int y); */
static PyObject*
py_gcompris_item_rotate_with_center(PyObject* self, PyObject* args)
{
  PyObject* pyitem;
  GnomeCanvasItem* item;
  double angle;
  int x,y;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "Odii:gcompris_item_rotate_with_center", &pyitem, &angle, &x, &y))
    return NULL;
  item = (GnomeCanvasItem*) pygobject_get(pyitem);

  /* Call the corresponding C function */
  item_rotate_with_center(item, angle, x, y);

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


/* Dialog callback wrapper */
static PyObject* pyDialogBoxCallBackFunc = NULL;

/* typedef void (*DialogBoxCallBack) (); */
void pyDialogBoxCallBack(){
  PyObject* result;
  if(pyDialogBoxCallBackFunc==NULL) return;

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


/* void	gcompris_dialog(gchar *str, DialogBoxCallBack dbcb); */
static PyObject*
py_gcompris_dialog(PyObject* self, PyObject* args)
{
  PyObject* pyCallback;
  gchar* str;

  /* Parse arguments */
  if(!PyArg_ParseTuple(args, "sO:gcompris_dialog", &str, &pyCallback))
    return NULL;
  if(!PyCallable_Check(pyCallback)) return NULL;

  /* Call the corresponding C function */
  gcompris_dialog(str, pyDialogBoxCallBack);

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


static PyMethodDef PythonGcomprisUtilsModule[] = {
  { "load_number_pixmap",  py_gcompris_load_number_pixmap, METH_VARARGS, "gcompris_load_number_pixmap" },
  { "load_pixmap",  py_gcompris_load_pixmap, METH_VARARGS, "gcompris_load_pixmap" },
  { "set_image_focus",  py_gcompris_set_image_focus, METH_VARARGS, "gcompris_set_image_focus" },
  { "item_event_focus",  py_gcompris_item_event_focus, METH_VARARGS, "gcompris_item_event_focus" },
  { "item_absolute_move",  py_gcompris_item_absolute_move, METH_VARARGS, "item_absolute_move" },
  { "item_rotate",  py_gcompris_item_rotate, METH_VARARGS, "item_rotate" },
  { "item_rotate_with_center",  py_gcompris_item_rotate_with_center, METH_VARARGS,
    "item_rotate_with_center" },
  { "dialog",  py_gcompris_dialog, METH_VARARGS, "gcompris_dialog" },
  { NULL, NULL, 0, NULL}
};


void python_gcompris_utils_module_init(void)
{
  PyObject* module;
  module = Py_InitModule("_gcompris_utils", PythonGcomprisUtilsModule);
}

/* 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_" },
*/