File: diashape.override

package info (click to toggle)
diacanvas2 0.13.0-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,360 kB
  • ctags: 2,897
  • sloc: ansic: 20,741; xml: 8,608; sh: 7,458; python: 669; makefile: 536
file content (467 lines) | stat: -rw-r--r-- 12,476 bytes parent folder | download
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
%%
headers
/* vim: syntax=c
 */
#include <Python.h>
#define NO_IMPORT_PYGOBJECT 1
#define NO_IMPORT_PYGTK 1
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <diacanvas/dia-canvas.h>
#include <diacanvas/dia-shape.h>
#include <diacanvas/dia-geometry.h>
#include <diacanvas/diatypebuiltins.h>


/* This might look evil, but it avoid unnessesary warnings...
 *
 * In Python the DiaShape class is split up in separate classes, one
 * for each shape type. Since shapes have some common operations we have
 * to add them to all python classes seperately.
 */

#define DiaShapePath DiaShape
#define dia_shape_path_set_color(s, c) dia_shape_set_color((DiaShape*)s, c)
#define dia_shape_path_request_update(s) dia_shape_request_update((DiaShape*)s)
#define dia_shape_path_need_update(s) dia_shape_need_update((DiaShape*)s)
#define dia_shape_path_set_visibility(s,v) dia_shape_set_visibility((DiaShape*)s,v)
#define dia_shape_path_get_bounds(s,b) dia_shape_get_bounds((DiaShape*)s,b)

#define DiaShapeBezier DiaShape
#define dia_shape_bezier_set_color(s, c) dia_shape_set_color((DiaShape*)s, c)
#define dia_shape_bezier_request_update(s) dia_shape_request_update((DiaShape*)s)
#define dia_shape_bezier_need_update(s) dia_shape_need_update((DiaShape*)s)
#define dia_shape_bezier_set_visibility(s,v) dia_shape_set_visibility((DiaShape*)s,v)
#define dia_shape_bezier_get_bounds(s,b) dia_shape_get_bounds((DiaShape*)s,b)

#define DiaShapeEllipse DiaShape
#define dia_shape_ellipse_set_color(s, c) dia_shape_set_color((DiaShape*)s, c)
#define dia_shape_ellipse_request_update(s) dia_shape_request_update((DiaShape*)s)
#define dia_shape_ellipse_need_update(s) dia_shape_need_update((DiaShape*)s)
#define dia_shape_ellipse_set_visibility(s,v) dia_shape_set_visibility((DiaShape*)s,v)
#define dia_shape_ellipse_get_bounds(s,b) dia_shape_get_bounds((DiaShape*)s,b)

#define DiaShapeText DiaShape
#define dia_shape_text_set_color(s, c) dia_shape_set_color((DiaShape*)s, c)
#define dia_shape_text_request_update(s) dia_shape_request_update((DiaShape*)s)
#define dia_shape_text_need_update(s) dia_shape_need_update((DiaShape*)s)
#define dia_shape_text_set_visibility(s,v) dia_shape_set_visibility((DiaShape*)s,v)
#define dia_shape_text_get_bounds(s,b) dia_shape_get_bounds((DiaShape*)s,b)

#define DiaShapeImage DiaShape
#define dia_shape_image_request_update(s) dia_shape_request_update((DiaShape*)s)
#define dia_shape_image_need_update(s) dia_shape_need_update((DiaShape*)s)
#define dia_shape_image_set_visibility(s,v) dia_shape_set_visibility((DiaShape*)s,v)
#define dia_shape_image_get_bounds(s,b) dia_shape_get_bounds((DiaShape*)s,b)

/* Return the number of points in **points. -1 is returned in case of an error.
 */
static gint
sequence_to_point_array (PyObject *seq, DiaPoint **points)
{
	gint len, i;
	GValue v = { 0, };
	DiaPoint *p = NULL;
	PyObject *sitem;
	
	len = PySequence_Length (seq);
	if (len < 0) {
		PyErr_SetString(PyExc_TypeError,
				"points should be a tuple of points");
		return -1;
	}

	p = g_new (DiaPoint, len);
	g_value_init (&v, DIA_TYPE_POINT);
	for (i = 0; i < len; i++) {
		sitem = PySequence_GetItem(seq, i);
		if (pyg_value_from_pyobject (&v, sitem)) {
			PyErr_SetString(PyExc_TypeError,
					"points should be a tuple of points");
			Py_XDECREF (sitem);
			g_free (p);
			return -1;
		}
		p[i] = *((DiaPoint*) g_value_get_boxed (&v));
		Py_DECREF(sitem);
		g_value_reset (&v);
	}
	g_value_unset (&v);

	*points = p;

	return len;
}

%%
import gtk.gdk.Drawable as PyGdkDrawable_Type
import gtk.gdk.Pixbuf as PyGdkPixbuf_Type
import pango.Layout as PyPangoLayout_Type
%%
ignore-glob
  *_get_type
  _*
  dia_shape_*_get_bounds
%%
override dia_shape_line kwargs
static PyObject *
_wrap_dia_shape_line(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "points", NULL };
	PyObject *py_points;
	DiaPoint *points = NULL;
	gint len;
	
	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
					 "O:DiaShapePath.line",
					 kwlist, &py_points))
		return NULL;

	len = sequence_to_point_array (py_points, &points);
	if (len < 0)
		return NULL;

	dia_shape_polyline(pyg_boxed_get(self, DiaShape), len, points);

	g_free (points);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_polygon kwargs
static PyObject *
_wrap_dia_shape_polygon(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "points", NULL };
	PyObject *py_points;
	DiaPoint *points = NULL;
	gint len;
	
	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
					 "O:DiaShapePath.line",
					 kwlist, &py_points))
		return NULL;

	len = sequence_to_point_array (py_points, &points);
	if (len < 0)
		return NULL;

	dia_shape_polygon (pyg_boxed_get(self, DiaShape), len, points);

	g_free (points);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_rectangle kwargs
static PyObject *
_wrap_dia_shape_rectangle(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "upper_left", "lower_right", NULL };
	PyObject *py_upper_left, *py_lower_right;
	GValue v_upper_left = { 0, }, v_lower_right = { 0, };
	DiaPoint *upper_left, *lower_right;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO:DiaShapePath.rectangle", kwlist, &py_upper_left, &py_lower_right))
		return NULL;

	g_value_init (&v_upper_left, DIA_TYPE_POINT);
	g_value_init (&v_lower_right, DIA_TYPE_POINT);

	if (pyg_value_from_pyobject (&v_upper_left, py_upper_left))
		return NULL;

	if (pyg_value_from_pyobject (&v_lower_right, py_lower_right))
		return NULL;

	upper_left = g_value_get_boxed (&v_upper_left);
	lower_right = g_value_get_boxed (&v_lower_right);

	dia_shape_rectangle(pyg_boxed_get(self, DiaShapePath), upper_left, lower_right);

	g_value_unset (&v_upper_left);
	g_value_unset (&v_lower_right);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_arc kwargs
static PyObject *
_wrap_dia_shape_arc(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "begin", "middle", "end", NULL };
	PyObject *py_begin, *py_middle, *py_end;
	GValue v_begin = { 0, }, v_middle = { 0, }, v_end = { 0, };
	DiaPoint *begin, *middle, *end;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OOO:DiaShapePath.arc", kwlist, &py_begin, &py_middle, &py_end))
		return NULL;

	g_value_init (&v_begin, DIA_TYPE_POINT);
	g_value_init (&v_middle, DIA_TYPE_POINT);
	g_value_init (&v_end, DIA_TYPE_POINT);

	begin = g_value_get_boxed (&v_begin);
	middle = g_value_get_boxed (&v_middle);
	end = g_value_get_boxed (&v_end);

	dia_shape_arc(pyg_boxed_get(self, DiaShapePath), begin, middle, end);

	g_value_unset (&v_begin);
	g_value_unset (&v_middle);
	g_value_unset (&v_end);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_path_set_dash kwargs
static PyObject*
_wrap_dia_shape_path_set_dash (PyGObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "offset", "dash", NULL };
	PyObject *py_dash;
	double offset;
	GValue vdash = { 0, };
	DiaDashStyle *dash;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				         "dO:DiaShapePath.set_dash",
					 kwlist, &offset, &py_dash))
		return NULL;

	g_value_init (&vdash, DIA_TYPE_DASH_STYLE);

	if (pyg_value_from_pyobject (&vdash, py_dash)) {
		return NULL;
	}

	dash = g_value_get_boxed (&vdash);

	dia_shape_path_set_dash (pyg_boxed_get (self, DiaShape),
				 offset, dash->n_dash, dash->dash);

	g_value_unset (&vdash);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_bezier kwargs
static PyObject *
_wrap_dia_shape_bezier(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "points", NULL };
	PyObject *py_points;
	int len;
	DiaPoint *points = NULL;

	if (!PyArg_ParseTupleAndKeywords (args, kwargs,
					  "O:DiaShapeBezier.bezier", kwlist,
					  &py_points))
		return NULL;

	if (!PySequence_Check (py_points)) {
		PyErr_SetString (PyExc_TypeError,
				 "points should be a sequence of points");
		return NULL;
	}

	len = PySequence_Size (py_points);
	if (len <= 0 && len % 3 != 1) {
		PyErr_SetString (PyExc_TypeError,
				 "the length of points should be a multiple "
				 "of 3 plus 1 (e.g. 4, 7)");
		return NULL;
	}

	len = sequence_to_point_array (py_points, &points);
	if (len < 0)
		return NULL;

	if (len > 0)
		dia_shape_bezier (pyg_boxed_get(self, DiaShapeBezier),
				  &points[0], len - 1, &points[1]);
	g_free (points);
	Py_INCREF (Py_None);
	return Py_None;
}
%%
override dia_shape_ellipse kwargs
static PyObject *
_wrap_dia_shape_ellipse(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "center", "width", "height", NULL };
	PyObject *py_center;
	GValue v_center = { 0, };
	DiaPoint *center;
	double width, height;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Odd:DiaShapeEllipse.ellipse", kwlist, &py_center, &width, &height))
		return NULL;

	g_value_init (&v_center, DIA_TYPE_POINT);

	if (pyg_value_from_pyobject (&v_center, py_center))
		return NULL;

	center = g_value_get_boxed (&v_center);

	dia_shape_ellipse(pyg_boxed_get(self, DiaShapeEllipse), center, width, height);

	g_value_unset (&v_center);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_text_cursor_from_pos kwargs
static PyObject*
_wrap_dia_shape_text_cursor_from_pos (PyGObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "pos", NULL };
	PyObject *py_pos;
	gint cursor;
	gboolean in;
	GValue vpos = { 0, };
	DiaPoint *pos;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				         "O:DiaShapeText.cursor_from_pos",
					 kwlist, &py_pos))
		return NULL;

	g_value_init (&vpos, DIA_TYPE_POINT);

	if (pyg_value_from_pyobject (&vpos, py_pos)) {
		return NULL;
	}

	pos = g_value_get_boxed (&vpos);

	in = dia_shape_text_cursor_from_pos (pyg_boxed_get (self, DiaShape),
					     pos, &cursor);

	g_value_unset (&vpos);

	return Py_BuildValue ("(ii)", in, cursor);
}
%%
override dia_shape_text_set_affine kwargs
static PyObject*
_wrap_dia_shape_text_set_affine (PyGObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "affine", NULL };
	PyObject *py_affine;
	GValue vaffine = { 0, };
	gdouble *affine;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				         "O:DiaShapeText.set_affine",
					 kwlist, &py_affine))
		return NULL;

	g_value_init (&vaffine, DIA_TYPE_AFFINE);

	if (pyg_value_from_pyobject (&vaffine, py_affine)) {
		return NULL;
	}

	affine = g_value_get_boxed (&vaffine);

	dia_shape_text_set_affine (pyg_boxed_get (self, DiaShape),
				   affine);

	g_value_unset (&vaffine);

	Py_INCREF (Py_None);
	return Py_None;
}
%%
override dia_shape_text_set_pos kwargs
static PyObject *
_wrap_dia_shape_text_set_pos(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "pos", NULL };
	PyObject *py_pos;
	GValue v_pos = { 0, };
	DiaPoint *pos;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:DiaShapeText.set_pos", kwlist, &py_pos))
		return NULL;

	g_value_init (&v_pos, DIA_TYPE_POINT);

	if (pyg_value_from_pyobject (&v_pos, py_pos))
		return NULL;

	pos = g_value_get_boxed (&v_pos);

	dia_shape_text_set_pos(pyg_boxed_get(self, DiaShapeText), pos);

	g_value_unset (&v_pos);

	Py_INCREF(Py_None);
	return Py_None;
}
%%
override dia_shape_image_set_affine kwargs
static PyObject*
_wrap_dia_shape_image_set_affine (PyGObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "affine", NULL };
	PyObject *py_affine;
	GValue vaffine = { 0, };
	gdouble *affine;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs,
				         "O:DiaShapeText.set_affine",
					 kwlist, &py_affine))
		return NULL;

	g_value_init (&vaffine, DIA_TYPE_AFFINE);

	if (pyg_value_from_pyobject (&vaffine, py_affine)) {
		return NULL;
	}

	affine = g_value_get_boxed (&vaffine);

	dia_shape_image_set_affine (pyg_boxed_get (self, DiaShape),
				   affine);

	g_value_unset (&vaffine);

	Py_INCREF (Py_None);
	return Py_None;
}
%%
override dia_shape_image_set_pos kwargs
static PyObject *
_wrap_dia_shape_image_set_pos(PyObject *self, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "pos", NULL };
	PyObject *py_pos;
	GValue v_pos = { 0, };
	DiaPoint *pos;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:DiaShapeImage.set_pos", kwlist, &py_pos))
        return NULL;

	g_value_init (&v_pos, DIA_TYPE_POINT);

	if (pyg_value_from_pyobject (&v_pos, py_pos))
		return NULL;

	pos = g_value_get_boxed (&v_pos);

	dia_shape_image_set_pos(pyg_boxed_get(self, DiaShapeImage), pos);

	g_value_unset (&v_pos);

	Py_INCREF(Py_None);
	return Py_None;
}