1 /* Copyright (C) 2013-2020 Roland Lutz
3 AUTOMATICALLY GENERATED FROM data_box.m4 -- DO NOT EDIT
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
20 #include <structmember.h>
23 PyObject
*construct_box(const struct xornsch_box
*data
)
25 PyObject
*no_args
= PyTuple_New(0);
26 Box
*self
= (Box
*)PyObject_CallObject(
27 (PyObject
*)&BoxType
, no_args
);
34 ((LineAttr
*)self
->line
)->data
= data
->line
;
35 ((FillAttr
*)self
->fill
)->data
= data
->fill
;
36 return (PyObject
*)self
;
39 void prepare_box(Box
*self
,
40 xorn_obtype_t
*type_return
, const void **data_return
)
42 self
->data
.line
= ((LineAttr
*)self
->line
)->data
;
43 self
->data
.fill
= ((FillAttr
*)self
->fill
)->data
;
44 *type_return
= xornsch_obtype_box
;
45 *data_return
= &self
->data
;
48 static PyObject
*Box_new(
49 PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
51 Box
*self
= (Box
*)type
->tp_alloc(type
, 0);
55 PyObject
*no_args
= PyTuple_New(0);
56 self
->line
= PyObject_CallObject((PyObject
*)&LineAttrType
, no_args
);
57 self
->fill
= PyObject_CallObject((PyObject
*)&FillAttrType
, no_args
);
60 if (self
->line
== NULL
) {
64 if (self
->fill
== NULL
) {
68 return (PyObject
*)self
;
71 static int Box_init(Box
*self
, PyObject
*args
, PyObject
*kwds
)
73 double x_arg
= 0., y_arg
= 0.;
74 double width_arg
= 0., height_arg
= 0.;
76 PyObject
*line_arg
= NULL
;
77 PyObject
*fill_arg
= NULL
;
79 static char *kwlist
[] = {
88 if (!PyArg_ParseTupleAndKeywords(
89 args
, kwds
, "|ddddiOO:Box", kwlist
,
91 &width_arg
, &height_arg
,
97 if (line_arg
!= NULL
&& !PyObject_TypeCheck(line_arg
, &LineAttrType
)) {
100 "line attribute must be %.50s, not %.50s",
101 LineAttrType
.tp_name
, line_arg
->ob_type
->tp_name
);
102 PyErr_SetString(PyExc_TypeError
, buf
);
105 if (fill_arg
!= NULL
&& !PyObject_TypeCheck(fill_arg
, &FillAttrType
)) {
107 snprintf(buf
, BUFSIZ
,
108 "fill attribute must be %.50s, not %.50s",
109 FillAttrType
.tp_name
, fill_arg
->ob_type
->tp_name
);
110 PyErr_SetString(PyExc_TypeError
, buf
);
114 self
->data
.pos
.x
= x_arg
;
115 self
->data
.pos
.y
= y_arg
;
116 self
->data
.size
.x
= width_arg
;
117 self
->data
.size
.y
= height_arg
;
118 self
->data
.color
= color_arg
;
119 if (line_arg
!= NULL
) {
121 Py_DECREF(self
->line
);
122 self
->line
= line_arg
;
124 if (fill_arg
!= NULL
) {
126 Py_DECREF(self
->fill
);
127 self
->fill
= fill_arg
;
133 static int Box_traverse(Box
*self
, visitproc visit
, void *arg
)
135 Py_VISIT(self
->line
);
136 Py_VISIT(self
->fill
);
140 static int Box_clear(Box
*self
)
142 Py_CLEAR(self
->line
);
143 Py_CLEAR(self
->fill
);
147 static void Box_dealloc(Box
*self
)
150 self
->ob_type
->tp_free((PyObject
*)self
);
153 static PyMemberDef Box_members
[] = {
154 { "x", T_DOUBLE
, offsetof(Box
, data
.pos
.x
), 0,
156 { "y", T_DOUBLE
, offsetof(Box
, data
.pos
.y
), 0,
158 { "width", T_DOUBLE
, offsetof(Box
, data
.size
.x
), 0,
160 { "height", T_DOUBLE
, offsetof(Box
, data
.size
.y
), 0,
162 { "color", T_INT
, offsetof(Box
, data
.color
), 0,
164 { NULL
, 0, 0, 0, NULL
} /* Sentinel */
167 static PyObject
*Box_getline(Box
*self
, void *closure
)
169 Py_INCREF(self
->line
);
173 static int Box_setline(Box
*self
, PyObject
*value
, void *closure
)
176 PyErr_SetString(PyExc_TypeError
,
177 "line attribute cannot be deleted");
181 if (!PyObject_TypeCheck(value
, &LineAttrType
)) {
183 snprintf(buf
, BUFSIZ
,
184 "line attribute must be %.50s, not %.50s",
185 LineAttrType
.tp_name
, value
->ob_type
->tp_name
);
186 PyErr_SetString(PyExc_TypeError
, buf
);
191 Py_DECREF(self
->line
);
196 static PyObject
*Box_getfill(Box
*self
, void *closure
)
198 Py_INCREF(self
->fill
);
202 static int Box_setfill(Box
*self
, PyObject
*value
, void *closure
)
205 PyErr_SetString(PyExc_TypeError
,
206 "fill attribute cannot be deleted");
210 if (!PyObject_TypeCheck(value
, &FillAttrType
)) {
212 snprintf(buf
, BUFSIZ
,
213 "fill attribute must be %.50s, not %.50s",
214 FillAttrType
.tp_name
, value
->ob_type
->tp_name
);
215 PyErr_SetString(PyExc_TypeError
, buf
);
220 Py_DECREF(self
->fill
);
225 static PyGetSetDef Box_getset
[] = {
226 { "line", (getter
)Box_getline
, (setter
)Box_setline
,
227 PyDoc_STR(""), NULL
},
228 { "fill", (getter
)Box_getfill
, (setter
)Box_setfill
,
229 PyDoc_STR(""), NULL
},
230 { NULL
, NULL
, NULL
, NULL
, NULL
} /* Sentinel */
233 PyTypeObject BoxType
= {
234 PyObject_HEAD_INIT(NULL
)
237 /* For printing, in format "<module>.<name>" */
238 "xorn.storage.Box", /* const char *tp_name */
241 sizeof(Box
), /* Py_ssize_t tp_basicsize */
242 0, /* Py_ssize_t tp_itemsize */
244 /* Methods to implement standard operations */
245 (destructor
)Box_dealloc
, /* destructor tp_dealloc */
246 NULL
, /* printfunc tp_print */
247 NULL
, /* getattrfunc tp_getattr */
248 NULL
, /* setattrfunc tp_setattr */
249 NULL
, /* cmpfunc tp_compare */
250 NULL
, /* reprfunc tp_repr */
252 /* Method suites for standard classes */
253 NULL
, /* PyNumberMethods *tp_as_number */
254 NULL
, /* PySequenceMethods *tp_as_sequence */
255 NULL
, /* PyMappingMethods *tp_as_mapping */
257 /* More standard operations (here for binary compatibility) */
258 NULL
, /* hashfunc tp_hash */
259 NULL
, /* ternaryfunc tp_call */
260 NULL
, /* reprfunc tp_str */
261 NULL
, /* getattrofunc tp_getattro */
262 NULL
, /* setattrofunc tp_setattro */
264 /* Functions to access object as input/output buffer */
265 NULL
, /* PyBufferProcs *tp_as_buffer */
267 /* Flags to define presence of optional/expanded features */
268 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_BASETYPE
| Py_TPFLAGS_HAVE_GC
,
271 /* Documentation string */
272 PyDoc_STR("Schematic box."),
273 /* const char *tp_doc */
275 /* Assigned meaning in release 2.0 */
276 /* call function for all accessible objects */
277 (traverseproc
)Box_traverse
,/* traverseproc tp_traverse */
279 /* delete references to contained objects */
280 (inquiry
)Box_clear
, /* inquiry tp_clear */
282 /* Assigned meaning in release 2.1 */
283 /* rich comparisons */
284 NULL
, /* richcmpfunc tp_richcompare */
286 /* weak reference enabler */
287 0, /* Py_ssize_t tp_weaklistoffset */
289 /* Added in release 2.2 */
291 NULL
, /* getiterfunc tp_iter */
292 NULL
, /* iternextfunc tp_iternext */
294 /* Attribute descriptor and subclassing stuff */
295 NULL
, /* struct PyMethodDef *tp_methods */
296 Box_members
, /* struct PyMemberDef *tp_members */
297 Box_getset
, /* struct PyGetSetDef *tp_getset */
298 NULL
, /* struct _typeobject *tp_base */
299 NULL
, /* PyObject *tp_dict */
300 NULL
, /* descrgetfunc tp_descr_get */
301 NULL
, /* descrsetfunc tp_descr_set */
302 0, /* Py_ssize_t tp_dictoffset */
303 (initproc
)Box_init
, /* initproc tp_init */
304 NULL
, /* allocfunc tp_alloc */
305 Box_new
, /* newfunc tp_new */
306 NULL
, /* freefunc tp_free--Low-level free-memory routine */
307 NULL
, /* inquiry tp_is_gc--For PyObject_IS_GC */
308 NULL
, /* PyObject *tp_bases */
309 NULL
, /* PyObject *tp_mro--method resolution order */
310 NULL
, /* PyObject *tp_cache */
311 NULL
, /* PyObject *tp_subclasses */
312 NULL
, /* PyObject *tp_weaklist */
313 NULL
, /* destructor tp_del */
315 /* Type attribute cache version tag. Added in version 2.6 */
316 0, /* unsigned int tp_version_tag */