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
15 of 2D objects. (This version is deprecated, please use wx.lib.ogl instead.)"
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()) }
34 warnings.warn("This module is deprecated. Please use the wx.lib.ogl pacakge instead.",
35 DeprecationWarning, stacklevel=2)
39 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
41 %include _ogl_rename.i
46 %include _oglshapes2.i
51 ShapeCanvas = PyShapeCanvas
52 ShapeEvtHandler = PyShapeEvtHandler
54 RectangleShape = PyRectangleShape
55 BitmapShape = PyBitmapShape
56 DrawnShape = PyDrawnShape
57 CompositeShape = PyCompositeShape
58 DividedShape = PyDividedShape
59 DivisionShape = PyDivisionShape
60 EllipseShape = PyEllipseShape
61 CircleShape = PyCircleShape
62 LineShape = PyLineShape
63 PolygonShape = PyPolygonShape
64 TextShape = PyTextShape
65 ControlPoint = PyControlPoint
69 //---------------------------------------------------------------------------
88 CONTROL_POINT_VERTICAL,
89 CONTROL_POINT_HORIZONTAL,
90 CONTROL_POINT_DIAGONAL,
91 CONTROL_POINT_ENDPOINT_TO,
92 CONTROL_POINT_ENDPOINT_FROM,
97 FORMAT_SIZE_TO_CONTENTS,
100 LINE_ALIGNMENT_TO_NEXT_HANDLE,
111 // SHAPE_DIVIDED_RECTANGLE,
113 // SHAPE_CONTROL_POINT,
116 // SHAPE_LABEL_OBJECT,
118 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
125 ATTACHMENT_MODE_NONE,
126 ATTACHMENT_MODE_EDGE,
127 ATTACHMENT_MODE_BRANCHING,
128 BRANCHING_ATTACHMENT_NORMAL,
129 BRANCHING_ATTACHMENT_BLOB,
131 gyCONSTRAINT_CENTRED_VERTICALLY,
132 gyCONSTRAINT_CENTRED_HORIZONTALLY,
133 gyCONSTRAINT_CENTRED_BOTH,
134 gyCONSTRAINT_LEFT_OF,
135 gyCONSTRAINT_RIGHT_OF,
138 gyCONSTRAINT_ALIGNED_TOP,
139 gyCONSTRAINT_ALIGNED_BOTTOM,
140 gyCONSTRAINT_ALIGNED_LEFT,
141 gyCONSTRAINT_ALIGNED_RIGHT,
142 gyCONSTRAINT_MIDALIGNED_TOP,
143 gyCONSTRAINT_MIDALIGNED_BOTTOM,
144 gyCONSTRAINT_MIDALIGNED_LEFT,
145 gyCONSTRAINT_MIDALIGNED_RIGHT,
151 DIVISION_SIDE_BOTTOM,
157 //---------------------------------------------------------------------------
159 void wxOGLInitialize();
164 //---------------------------------------------------------------------------
166 // Convert from a Python list to a list of className objects. This one will
167 // work for any class for the VERY generic cases, but beyond that the helper
168 // needs to know more about the type.
169 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
170 bool blocked = wxPyBeginBlockThreads();
171 if (!PyList_Check(pyList)) {
172 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
173 wxPyEndBlockThreads(blocked);
176 int count = PyList_Size(pyList);
177 wxList* list = new wxList;
179 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
180 wxPyEndBlockThreads(blocked);
183 for (int x=0; x<count; x++) {
184 PyObject* pyo = PyList_GetItem(pyList, x);
185 wxObject* wxo = NULL;
187 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
189 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
190 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
191 wxPyEndBlockThreads(blocked);
196 wxPyEndBlockThreads(blocked);
200 //---------------------------------------------------------------------------
202 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
203 bool blocked = wxPyBeginBlockThreads();
204 if (!PyList_Check(pyList)) {
205 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
206 wxPyEndBlockThreads(blocked);
209 int count = PyList_Size(pyList);
210 wxList* list = new wxList;
212 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
213 wxPyEndBlockThreads(blocked);
216 for (int x=0; x<count; x++) {
217 PyObject* pyo = PyList_GetItem(pyList, x);
219 if (PyTuple_Check(pyo)) {
220 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
221 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
223 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
224 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
226 list->Append((wxObject*) new wxRealPoint(val1, val2));
229 wxRealPoint* wxo = NULL;
230 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
231 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
232 wxPyEndBlockThreads(blocked);
235 list->Append((wxObject*) new wxRealPoint(*wxo));
238 wxPyEndBlockThreads(blocked);
242 //---------------------------------------------------------------------------
244 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source) {
245 PyObject* target = NULL;
247 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
248 // If it's derived from wxShapeEvtHandler then there may
249 // already be a pointer to a Python object that we can use
251 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
252 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
254 target = data->m_obj;
259 target = wxPyMake_wxObject2(source, FALSE);
260 if (target != Py_None)
261 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
266 //---------------------------------------------------------------------------
268 PyObject* wxPy_ConvertRealPointList(wxListBase* listbase) {
269 wxList* list = (wxList*)listbase;
273 wxNode* node = list->GetFirst();
275 bool blocked = wxPyBeginBlockThreads();
276 pyList = PyList_New(0);
278 wxObj = node->GetData();
279 pyObj = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0);
280 PyList_Append(pyList, pyObj);
281 node = node->GetNext();
283 wxPyEndBlockThreads(blocked);
287 //---------------------------------------------------------------------------
289 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
290 wxList* list = (wxList*)listbase;
294 wxNode* node = list->GetFirst();
296 bool blocked = wxPyBeginBlockThreads();
297 pyList = PyList_New(0);
299 wxObj = node->GetData();
300 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj);
301 PyList_Append(pyList, pyObj);
302 node = node->GetNext();
304 wxPyEndBlockThreads(blocked);
309 //---------------------------------------------------------------------------
311 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
312 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
313 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
314 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
315 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
316 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
317 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
318 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
319 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
320 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
321 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
322 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
323 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
324 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
325 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
327 //---------------------------------------------------------------------------
329 // extern "C" SWIGEXPORT(void) initoglbasicc();
330 // extern "C" SWIGEXPORT(void) initoglshapesc();
331 // extern "C" SWIGEXPORT(void) initoglshapes2c();
332 // extern "C" SWIGEXPORT(void) initoglcanvasc();
340 // initoglshapes2c();
344 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
345 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
346 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
347 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
348 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
349 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
350 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
351 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
352 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
353 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
354 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
355 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
356 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
357 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
361 //---------------------------------------------------------------------------
362 //---------------------------------------------------------------------------