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
|
/* -*- Mode: C; c-basic-offset: 4 -*-
* pygtk- Python bindings for the GTK toolkit.
* Copyright (C) 1998-2003 James Henstridge
*
* gdkrectangle.override: gtk.gdk.Rectangle overrides
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
%%
override gdk_rectangle_new kwargs
static int
_wrap_gdk_rectangle_new(PyGBoxed *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = { "x", "y", "width", "height", NULL };
GdkRectangle rect = {0, 0, 0, 0};
if (!PyArg_ParseTupleAndKeywords(args, kwargs,
"|iiii:GdkRectangle.__init__",
kwlist, &(rect.x), &(rect.y),
&(rect.width), &(rect.height)))
return -1;
self->boxed = g_boxed_copy(GDK_TYPE_RECTANGLE, &rect);
self->free_on_dealloc = TRUE;
self->gtype = GDK_TYPE_RECTANGLE;
return 0;
}
%%
override-slot GdkRectangle.tp_as_sequence
static Py_ssize_t
_wrap_gdk_rectangle_length(PyGBoxed *self)
{
return 4;
}
static PyObject *
_wrap_gdk_rectangle_getitem(PyGBoxed *self, Py_ssize_t pos)
{
GdkRectangle *rect;
if (pos < 0) pos += 4;
if (pos < 0 || pos >= 4) {
PyErr_SetString(PyExc_IndexError, "index out of range");
return NULL;
}
rect = pyg_boxed_get(self, GdkRectangle);
switch (pos) {
case 0: return PyInt_FromLong(rect->x);
case 1: return PyInt_FromLong(rect->y);
case 2: return PyInt_FromLong(rect->width);
case 3: return PyInt_FromLong(rect->height);
default:
g_assert_not_reached();
return NULL;
}
}
static int
_wrap_gdk_rectangle_setitem(PyGBoxed *self, Py_ssize_t pos, PyObject *value)
{
GdkRectangle *rect;
gint val;
if (pos < 0) pos += 4;
if (pos < 0 || pos >= 4) {
PyErr_SetString(PyExc_IndexError, "index out of range");
return -1;
}
rect = pyg_boxed_get(self, GdkRectangle);
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
switch(pos) {
case 0: rect->x = val; break;
case 1: rect->y = val; break;
case 2: rect->width = val; break;
case 3: rect->height = val; break;
default:
g_assert_not_reached();
return -1;
}
return 0;
}
static PySequenceMethods _wrap_gdk_rectangle_tp_as_sequence = {
(lenfunc)_wrap_gdk_rectangle_length,
0,
0,
(ssizeargfunc)_wrap_gdk_rectangle_getitem,
0,
(ssizeobjargproc)_wrap_gdk_rectangle_setitem,
0,
};
%%
override-attr GdkRectangle.x
static int
_wrap_gdk_rectangle__set_x(PyGBoxed *self, PyObject *value, void *closure)
{
gint val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, GdkRectangle)->x = val;
return 0;
}
%%
override-attr GdkRectangle.y
static int
_wrap_gdk_rectangle__set_y(PyGBoxed *self, PyObject *value, void *closure)
{
gint val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, GdkRectangle)->y = val;
return 0;
}
%%
override-attr GdkRectangle.width
static int
_wrap_gdk_rectangle__set_width(PyGBoxed *self, PyObject *value, void *closure)
{
gint val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, GdkRectangle)->width = val;
return 0;
}
%%
override-attr GdkRectangle.height
static int
_wrap_gdk_rectangle__set_height(PyGBoxed *self, PyObject *value, void *closure)
{
gint val;
val = PyInt_AsLong(value);
if (PyErr_Occurred())
return -1;
pyg_boxed_get(self, GdkRectangle)->height = val;
return 0;
}
%%
override gdk_rectangle_intersect kwargs
static PyObject *
_wrap_gdk_rectangle_intersect(PyGObject *self, PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "src", NULL };
PyObject *py_src;
GdkRectangle src, dest = {0, 0, 0, 0};
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GdkRectangle.intersect",
kwlist, &py_src)) {
return NULL;
}
if (!pyg_boxed_check(py_src, GDK_TYPE_RECTANGLE)) {
if (!pygdk_rectangle_from_pyobject(py_src, &src)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"src must be a GdkRectangle or 4-tuple");
return NULL;
}
} else {
src = *pyg_boxed_get(py_src, GdkRectangle);
}
gdk_rectangle_intersect(pyg_boxed_get(self, GdkRectangle), &src, &dest);
return pyg_boxed_new(GDK_TYPE_RECTANGLE, &dest, TRUE, TRUE);
}
%%
override gdk_rectangle_union kwargs
static PyObject *
_wrap_gdk_rectangle_union(PyGObject *self, PyObject *args,
PyObject *kwargs)
{
static char *kwlist[] = { "src", NULL };
PyObject *py_src;
GdkRectangle src, dest;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:GdkRectangle.union",
kwlist, &py_src)) {
return NULL;
}
if (!pyg_boxed_check(py_src, GDK_TYPE_RECTANGLE)) {
if (!pygdk_rectangle_from_pyobject(py_src, &src)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError,
"src must be a GdkRectangle or 4-tuple");
return NULL;
}
} else {
src = *pyg_boxed_get(py_src, GdkRectangle);
}
gdk_rectangle_union(pyg_boxed_get(self, GdkRectangle), &src, &dest);
return pyg_boxed_new(GDK_TYPE_RECTANGLE, &dest, TRUE, TRUE);
}
%%
override-slot GdkRectangle.tp_richcompare
static PyObject *
_wrap_gdk_rectangle_tp_richcompare(PyObject *self, PyObject *other, int op)
{
PyObject *result;
if (PyObject_TypeCheck(self, &PyGdkRectangle_Type)
&& PyObject_TypeCheck(other, &PyGdkRectangle_Type)) {
GdkRectangle *rect1 = pyg_boxed_get(self, GdkRectangle);
GdkRectangle *rect2 = pyg_boxed_get(other, GdkRectangle);
switch (op) {
case Py_EQ:
result = (rect1->x == rect2->x && rect1->y == rect2->y
&& rect1->width == rect2->width && rect1->height == rect2->height
? Py_True : Py_False);
break;
case Py_NE:
result = (rect1->x != rect2->x || rect1->y != rect2->y
|| rect1->width != rect2->width || rect1->height != rect2->height
? Py_True : Py_False);
break;
default:
result = Py_NotImplemented;
}
}
else
result = Py_NotImplemented;
Py_INCREF(result);
return result;
}
%%
override-slot GdkRectangle.tp_repr
static PyObject *
_wrap_gdk_rectangle_tp_repr(PyGBoxed *self)
{
GdkRectangle *rect = pyg_boxed_get(self, GdkRectangle);
return PyString_FromFormat("%s(%d, %d, %d, %d)", self->ob_type->tp_name,
rect->x, rect->y, rect->width, rect->height);
}
|