1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG definitions for the wxWindows Object Graphics Library
7 // Created: 30-June-1999
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
17 #include "wx/wxPython/wxPython.h"
18 #include "wx/wxPython/pyclasses.h"
19 #include "oglhelpers.h"
23 //---------------------------------------------------------------------------
26 %pythoncode { wx = core }
29 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
31 %include _ogl_rename.i
36 %include _oglshapes2.i
41 ShapeCanvas = PyShapeCanvas
42 ShapeEvtHandler = PyShapeEvtHandler
44 RectangleShape = PyRectangleShape
45 BitmapShape = PyBitmapShape
46 DrawnShape = PyDrawnShape
47 CompositeShape = PyCompositeShape
48 DividedShape = PyDividedShape
49 DivisionShape = PyDivisionShape
50 EllipseShape = PyEllipseShape
51 CircleShape = PyCircleShape
52 LineShape = PyLineShape
53 PolygonShape = PyPolygonShape
54 TextShape = PyTextShape
55 ControlPoint = PyControlPoint
59 //---------------------------------------------------------------------------
78 CONTROL_POINT_VERTICAL,
79 CONTROL_POINT_HORIZONTAL,
80 CONTROL_POINT_DIAGONAL,
81 CONTROL_POINT_ENDPOINT_TO,
82 CONTROL_POINT_ENDPOINT_FROM,
87 FORMAT_SIZE_TO_CONTENTS,
90 LINE_ALIGNMENT_TO_NEXT_HANDLE,
101 // SHAPE_DIVIDED_RECTANGLE,
103 // SHAPE_CONTROL_POINT,
106 // SHAPE_LABEL_OBJECT,
108 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
115 ATTACHMENT_MODE_NONE,
116 ATTACHMENT_MODE_EDGE,
117 ATTACHMENT_MODE_BRANCHING,
118 BRANCHING_ATTACHMENT_NORMAL,
119 BRANCHING_ATTACHMENT_BLOB,
121 gyCONSTRAINT_CENTRED_VERTICALLY,
122 gyCONSTRAINT_CENTRED_HORIZONTALLY,
123 gyCONSTRAINT_CENTRED_BOTH,
124 gyCONSTRAINT_LEFT_OF,
125 gyCONSTRAINT_RIGHT_OF,
128 gyCONSTRAINT_ALIGNED_TOP,
129 gyCONSTRAINT_ALIGNED_BOTTOM,
130 gyCONSTRAINT_ALIGNED_LEFT,
131 gyCONSTRAINT_ALIGNED_RIGHT,
132 gyCONSTRAINT_MIDALIGNED_TOP,
133 gyCONSTRAINT_MIDALIGNED_BOTTOM,
134 gyCONSTRAINT_MIDALIGNED_LEFT,
135 gyCONSTRAINT_MIDALIGNED_RIGHT,
141 DIVISION_SIDE_BOTTOM,
147 //---------------------------------------------------------------------------
149 void wxOGLInitialize();
154 //---------------------------------------------------------------------------
156 // Convert from a Python list to a list of className objects. This one will
157 // work for any class for the VERY generic cases, but beyond that the helper
158 // needs to know more about the type.
159 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
160 wxPyBeginBlockThreads();
161 if (!PyList_Check(pyList)) {
162 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
163 wxPyEndBlockThreads();
166 int count = PyList_Size(pyList);
167 wxList* list = new wxList;
169 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
170 wxPyEndBlockThreads();
173 for (int x=0; x<count; x++) {
174 PyObject* pyo = PyList_GetItem(pyList, x);
175 wxObject* wxo = NULL;
177 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
179 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
180 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
181 wxPyEndBlockThreads();
186 wxPyEndBlockThreads();
190 //---------------------------------------------------------------------------
192 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
193 wxPyBeginBlockThreads();
194 if (!PyList_Check(pyList)) {
195 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
196 wxPyEndBlockThreads();
199 int count = PyList_Size(pyList);
200 wxList* list = new wxList;
202 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
203 wxPyEndBlockThreads();
206 for (int x=0; x<count; x++) {
207 PyObject* pyo = PyList_GetItem(pyList, x);
209 if (PyTuple_Check(pyo)) {
210 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
211 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
213 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
214 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
216 list->Append((wxObject*) new wxRealPoint(val1, val2));
219 wxRealPoint* wxo = NULL;
220 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
221 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
222 wxPyEndBlockThreads();
225 list->Append((wxObject*) new wxRealPoint(*wxo));
228 wxPyEndBlockThreads();
232 //---------------------------------------------------------------------------
234 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
235 PyObject* target = NULL;
237 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
238 // If it's derived from wxShapeEvtHandler then there may
239 // already be a pointer to a Python object that we can use
241 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
242 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
244 target = data->m_obj;
249 target = wxPyMake_wxObject2(source, FALSE);
250 if (target != Py_None)
251 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
256 //---------------------------------------------------------------------------
258 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
259 wxList* list = (wxList*)listbase;
263 wxNode* node = list->GetFirst();
265 wxPyBeginBlockThreads();
266 pyList = PyList_New(0);
268 wxObj = node->GetData();
269 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
270 PyList_Append(pyList, pyObj);
271 node = node->GetNext();
273 wxPyEndBlockThreads();
278 //---------------------------------------------------------------------------
280 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
281 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
282 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
283 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
284 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
285 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
286 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
287 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
288 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
289 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
290 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
291 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
292 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
293 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
294 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
296 //---------------------------------------------------------------------------
298 // extern "C" SWIGEXPORT(void) initoglbasicc();
299 // extern "C" SWIGEXPORT(void) initoglshapesc();
300 // extern "C" SWIGEXPORT(void) initoglshapes2c();
301 // extern "C" SWIGEXPORT(void) initoglcanvasc();
309 // initoglshapes2c();
313 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
314 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
315 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
316 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
317 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
318 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
319 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
320 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
321 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
322 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
323 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
324 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
325 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
326 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
330 //---------------------------------------------------------------------------
331 //---------------------------------------------------------------------------