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 /////////////////////////////////////////////////////////////////////////////
14 "The Object Graphics Library provides for simple drawing and manipulation
17 %module(docstring=DOCSTRING) ogl
20 #include "wx/wxPython/wxPython.h"
21 #include "wx/wxPython/pyclasses.h"
22 #include "oglhelpers.h"
26 //---------------------------------------------------------------------------
29 %pythoncode { wx = _core }
30 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
33 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
35 %include _ogl_rename.i
40 %include _oglshapes2.i
45 ShapeCanvas = PyShapeCanvas
46 ShapeEvtHandler = PyShapeEvtHandler
48 RectangleShape = PyRectangleShape
49 BitmapShape = PyBitmapShape
50 DrawnShape = PyDrawnShape
51 CompositeShape = PyCompositeShape
52 DividedShape = PyDividedShape
53 DivisionShape = PyDivisionShape
54 EllipseShape = PyEllipseShape
55 CircleShape = PyCircleShape
56 LineShape = PyLineShape
57 PolygonShape = PyPolygonShape
58 TextShape = PyTextShape
59 ControlPoint = PyControlPoint
63 //---------------------------------------------------------------------------
82 CONTROL_POINT_VERTICAL,
83 CONTROL_POINT_HORIZONTAL,
84 CONTROL_POINT_DIAGONAL,
85 CONTROL_POINT_ENDPOINT_TO,
86 CONTROL_POINT_ENDPOINT_FROM,
91 FORMAT_SIZE_TO_CONTENTS,
94 LINE_ALIGNMENT_TO_NEXT_HANDLE,
105 // SHAPE_DIVIDED_RECTANGLE,
107 // SHAPE_CONTROL_POINT,
110 // SHAPE_LABEL_OBJECT,
112 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
119 ATTACHMENT_MODE_NONE,
120 ATTACHMENT_MODE_EDGE,
121 ATTACHMENT_MODE_BRANCHING,
122 BRANCHING_ATTACHMENT_NORMAL,
123 BRANCHING_ATTACHMENT_BLOB,
125 gyCONSTRAINT_CENTRED_VERTICALLY,
126 gyCONSTRAINT_CENTRED_HORIZONTALLY,
127 gyCONSTRAINT_CENTRED_BOTH,
128 gyCONSTRAINT_LEFT_OF,
129 gyCONSTRAINT_RIGHT_OF,
132 gyCONSTRAINT_ALIGNED_TOP,
133 gyCONSTRAINT_ALIGNED_BOTTOM,
134 gyCONSTRAINT_ALIGNED_LEFT,
135 gyCONSTRAINT_ALIGNED_RIGHT,
136 gyCONSTRAINT_MIDALIGNED_TOP,
137 gyCONSTRAINT_MIDALIGNED_BOTTOM,
138 gyCONSTRAINT_MIDALIGNED_LEFT,
139 gyCONSTRAINT_MIDALIGNED_RIGHT,
145 DIVISION_SIDE_BOTTOM,
151 //---------------------------------------------------------------------------
153 void wxOGLInitialize();
158 //---------------------------------------------------------------------------
160 // Convert from a Python list to a list of className objects. This one will
161 // work for any class for the VERY generic cases, but beyond that the helper
162 // needs to know more about the type.
163 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
164 bool blocked = wxPyBeginBlockThreads();
165 if (!PyList_Check(pyList)) {
166 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
167 wxPyEndBlockThreads(blocked);
170 int count = PyList_Size(pyList);
171 wxList* list = new wxList;
173 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
174 wxPyEndBlockThreads(blocked);
177 for (int x=0; x<count; x++) {
178 PyObject* pyo = PyList_GetItem(pyList, x);
179 wxObject* wxo = NULL;
181 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
183 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
184 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
185 wxPyEndBlockThreads(blocked);
190 wxPyEndBlockThreads(blocked);
194 //---------------------------------------------------------------------------
196 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
197 bool blocked = wxPyBeginBlockThreads();
198 if (!PyList_Check(pyList)) {
199 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
200 wxPyEndBlockThreads(blocked);
203 int count = PyList_Size(pyList);
204 wxList* list = new wxList;
206 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
207 wxPyEndBlockThreads(blocked);
210 for (int x=0; x<count; x++) {
211 PyObject* pyo = PyList_GetItem(pyList, x);
213 if (PyTuple_Check(pyo)) {
214 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
215 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
217 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
218 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
220 list->Append((wxObject*) new wxRealPoint(val1, val2));
223 wxRealPoint* wxo = NULL;
224 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
225 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
226 wxPyEndBlockThreads(blocked);
229 list->Append((wxObject*) new wxRealPoint(*wxo));
232 wxPyEndBlockThreads(blocked);
236 //---------------------------------------------------------------------------
238 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
239 PyObject* target = NULL;
241 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
242 // If it's derived from wxShapeEvtHandler then there may
243 // already be a pointer to a Python object that we can use
245 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
246 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
248 target = data->m_obj;
253 target = wxPyMake_wxObject2(source, FALSE);
254 if (target != Py_None)
255 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
260 //---------------------------------------------------------------------------
262 PyObject* wxPy_ConvertRealPointList(wxListBase* listbase) {
263 wxList* list = (wxList*)listbase;
267 wxNode* node = list->GetFirst();
269 bool blocked = wxPyBeginBlockThreads();
270 pyList = PyList_New(0);
272 wxObj = node->GetData();
273 pyObj = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0);
274 PyList_Append(pyList, pyObj);
275 node = node->GetNext();
277 wxPyEndBlockThreads(blocked);
281 //---------------------------------------------------------------------------
283 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
284 wxList* list = (wxList*)listbase;
288 wxNode* node = list->GetFirst();
290 bool blocked = wxPyBeginBlockThreads();
291 pyList = PyList_New(0);
293 wxObj = node->GetData();
294 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
295 PyList_Append(pyList, pyObj);
296 node = node->GetNext();
298 wxPyEndBlockThreads(blocked);
303 //---------------------------------------------------------------------------
305 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
306 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
307 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
308 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
309 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
310 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
311 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
312 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
313 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
314 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
315 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
316 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
317 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
318 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
319 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
321 //---------------------------------------------------------------------------
323 // extern "C" SWIGEXPORT(void) initoglbasicc();
324 // extern "C" SWIGEXPORT(void) initoglshapesc();
325 // extern "C" SWIGEXPORT(void) initoglshapes2c();
326 // extern "C" SWIGEXPORT(void) initoglcanvasc();
334 // initoglshapes2c();
338 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
339 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
340 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
341 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
342 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
343 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
344 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
345 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
346 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
347 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
348 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
349 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
350 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
351 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
355 //---------------------------------------------------------------------------
356 //---------------------------------------------------------------------------