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 }
27 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
30 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
32 %include _ogl_rename.i
37 %include _oglshapes2.i
42 ShapeCanvas = PyShapeCanvas
43 ShapeEvtHandler = PyShapeEvtHandler
45 RectangleShape = PyRectangleShape
46 BitmapShape = PyBitmapShape
47 DrawnShape = PyDrawnShape
48 CompositeShape = PyCompositeShape
49 DividedShape = PyDividedShape
50 DivisionShape = PyDivisionShape
51 EllipseShape = PyEllipseShape
52 CircleShape = PyCircleShape
53 LineShape = PyLineShape
54 PolygonShape = PyPolygonShape
55 TextShape = PyTextShape
56 ControlPoint = PyControlPoint
60 //---------------------------------------------------------------------------
79 CONTROL_POINT_VERTICAL,
80 CONTROL_POINT_HORIZONTAL,
81 CONTROL_POINT_DIAGONAL,
82 CONTROL_POINT_ENDPOINT_TO,
83 CONTROL_POINT_ENDPOINT_FROM,
88 FORMAT_SIZE_TO_CONTENTS,
91 LINE_ALIGNMENT_TO_NEXT_HANDLE,
102 // SHAPE_DIVIDED_RECTANGLE,
104 // SHAPE_CONTROL_POINT,
107 // SHAPE_LABEL_OBJECT,
109 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
116 ATTACHMENT_MODE_NONE,
117 ATTACHMENT_MODE_EDGE,
118 ATTACHMENT_MODE_BRANCHING,
119 BRANCHING_ATTACHMENT_NORMAL,
120 BRANCHING_ATTACHMENT_BLOB,
122 gyCONSTRAINT_CENTRED_VERTICALLY,
123 gyCONSTRAINT_CENTRED_HORIZONTALLY,
124 gyCONSTRAINT_CENTRED_BOTH,
125 gyCONSTRAINT_LEFT_OF,
126 gyCONSTRAINT_RIGHT_OF,
129 gyCONSTRAINT_ALIGNED_TOP,
130 gyCONSTRAINT_ALIGNED_BOTTOM,
131 gyCONSTRAINT_ALIGNED_LEFT,
132 gyCONSTRAINT_ALIGNED_RIGHT,
133 gyCONSTRAINT_MIDALIGNED_TOP,
134 gyCONSTRAINT_MIDALIGNED_BOTTOM,
135 gyCONSTRAINT_MIDALIGNED_LEFT,
136 gyCONSTRAINT_MIDALIGNED_RIGHT,
142 DIVISION_SIDE_BOTTOM,
148 //---------------------------------------------------------------------------
150 void wxOGLInitialize();
155 //---------------------------------------------------------------------------
157 // Convert from a Python list to a list of className objects. This one will
158 // work for any class for the VERY generic cases, but beyond that the helper
159 // needs to know more about the type.
160 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
161 bool blocked = wxPyBeginBlockThreads();
162 if (!PyList_Check(pyList)) {
163 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
164 wxPyEndBlockThreads(blocked);
167 int count = PyList_Size(pyList);
168 wxList* list = new wxList;
170 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
171 wxPyEndBlockThreads(blocked);
174 for (int x=0; x<count; x++) {
175 PyObject* pyo = PyList_GetItem(pyList, x);
176 wxObject* wxo = NULL;
178 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
180 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
181 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
182 wxPyEndBlockThreads(blocked);
187 wxPyEndBlockThreads(blocked);
191 //---------------------------------------------------------------------------
193 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
194 bool blocked = wxPyBeginBlockThreads();
195 if (!PyList_Check(pyList)) {
196 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
197 wxPyEndBlockThreads(blocked);
200 int count = PyList_Size(pyList);
201 wxList* list = new wxList;
203 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
204 wxPyEndBlockThreads(blocked);
207 for (int x=0; x<count; x++) {
208 PyObject* pyo = PyList_GetItem(pyList, x);
210 if (PyTuple_Check(pyo)) {
211 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
212 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
214 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
215 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
217 list->Append((wxObject*) new wxRealPoint(val1, val2));
220 wxRealPoint* wxo = NULL;
221 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
222 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
223 wxPyEndBlockThreads(blocked);
226 list->Append((wxObject*) new wxRealPoint(*wxo));
229 wxPyEndBlockThreads(blocked);
233 //---------------------------------------------------------------------------
235 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
236 PyObject* target = NULL;
238 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
239 // If it's derived from wxShapeEvtHandler then there may
240 // already be a pointer to a Python object that we can use
242 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
243 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
245 target = data->m_obj;
250 target = wxPyMake_wxObject2(source, FALSE);
251 if (target != Py_None)
252 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
257 //---------------------------------------------------------------------------
259 PyObject* wxPy_ConvertRealPointList(wxListBase* listbase) {
260 wxList* list = (wxList*)listbase;
264 wxNode* node = list->GetFirst();
266 bool blocked = wxPyBeginBlockThreads();
267 pyList = PyList_New(0);
269 wxObj = node->GetData();
270 pyObj = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0);
271 PyList_Append(pyList, pyObj);
272 node = node->GetNext();
274 wxPyEndBlockThreads(blocked);
278 //---------------------------------------------------------------------------
280 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
281 wxList* list = (wxList*)listbase;
285 wxNode* node = list->GetFirst();
287 bool blocked = wxPyBeginBlockThreads();
288 pyList = PyList_New(0);
290 wxObj = node->GetData();
291 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
292 PyList_Append(pyList, pyObj);
293 node = node->GetNext();
295 wxPyEndBlockThreads(blocked);
300 //---------------------------------------------------------------------------
302 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
303 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
304 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
305 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
306 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
307 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
308 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
309 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
310 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
311 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
312 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
313 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
314 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
315 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
316 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
318 //---------------------------------------------------------------------------
320 // extern "C" SWIGEXPORT(void) initoglbasicc();
321 // extern "C" SWIGEXPORT(void) initoglshapesc();
322 // extern "C" SWIGEXPORT(void) initoglshapes2c();
323 // extern "C" SWIGEXPORT(void) initoglcanvasc();
331 // initoglshapes2c();
335 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
336 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
337 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
338 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
339 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
340 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
341 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
342 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
343 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
344 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
345 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
346 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
347 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
348 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
352 //---------------------------------------------------------------------------
353 //---------------------------------------------------------------------------