]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/ogl/ogl.i
todos, cleanups, detabified
[wxWidgets.git] / wxPython / contrib / ogl / ogl.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: ogl.i
3 // Purpose: SWIG definitions for the wxWindows Object Graphics Library
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 30-June-1999
8 // RCS-ID: $Id$
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 %define DOCSTRING
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.)"
16 %enddef
17
18 %module(package="wx", docstring=DOCSTRING) ogl
19
20 %{
21 #include "wx/wxPython/wxPython.h"
22 #include "wx/wxPython/pyclasses.h"
23 #include "oglhelpers.h"
24
25 %}
26
27 //---------------------------------------------------------------------------
28
29 %import windows.i
30 %pythoncode { wx = _core }
31 %pythoncode { __docfilter__ = wx.__DocFilter(globals()) }
32
33 %pythoncode {
34 import warnings
35 warnings.warn("This module is deprecated. Please use the wx.lib.ogl package instead.",
36 DeprecationWarning, stacklevel=2)
37 }
38
39
40 MAKE_CONST_WXSTRING_NOSWIG(EmptyString);
41
42 %include _ogl_rename.i
43
44 %include _ogldefs.i
45 %include _oglbasic.i
46 %include _oglshapes.i
47 %include _oglshapes2.i
48 %include _oglcanvas.i
49
50 %pythoncode {
51 %# Aliases
52 ShapeCanvas = PyShapeCanvas
53 ShapeEvtHandler = PyShapeEvtHandler
54 Shape = PyShape
55 RectangleShape = PyRectangleShape
56 BitmapShape = PyBitmapShape
57 DrawnShape = PyDrawnShape
58 CompositeShape = PyCompositeShape
59 DividedShape = PyDividedShape
60 DivisionShape = PyDivisionShape
61 EllipseShape = PyEllipseShape
62 CircleShape = PyCircleShape
63 LineShape = PyLineShape
64 PolygonShape = PyPolygonShape
65 TextShape = PyTextShape
66 ControlPoint = PyControlPoint
67 }
68
69
70 //---------------------------------------------------------------------------
71
72
73 enum {
74 KEY_SHIFT,
75 KEY_CTRL,
76 ARROW_NONE,
77 ARROW_END,
78 ARROW_BOTH,
79 ARROW_MIDDLE,
80 ARROW_START,
81 ARROW_HOLLOW_CIRCLE,
82 ARROW_FILLED_CIRCLE,
83 ARROW_ARROW,
84 ARROW_SINGLE_OBLIQUE,
85 ARROW_DOUBLE_OBLIQUE,
86 ARROW_METAFILE,
87 ARROW_POSITION_END,
88 ARROW_POSITION_START,
89 CONTROL_POINT_VERTICAL,
90 CONTROL_POINT_HORIZONTAL,
91 CONTROL_POINT_DIAGONAL,
92 CONTROL_POINT_ENDPOINT_TO,
93 CONTROL_POINT_ENDPOINT_FROM,
94 CONTROL_POINT_LINE,
95 FORMAT_NONE,
96 FORMAT_CENTRE_HORIZ,
97 FORMAT_CENTRE_VERT,
98 FORMAT_SIZE_TO_CONTENTS,
99 LINE_ALIGNMENT_HORIZ,
100 LINE_ALIGNMENT_VERT,
101 LINE_ALIGNMENT_TO_NEXT_HANDLE,
102 LINE_ALIGNMENT_NONE,
103 SHADOW_NONE,
104 SHADOW_LEFT,
105 SHADOW_RIGHT,
106 // SHAPE_BASIC,
107 // SHAPE_RECTANGLE,
108 // SHAPE_ELLIPSE,
109 // SHAPE_POLYGON,
110 // SHAPE_CIRCLE,
111 // SHAPE_LINE,
112 // SHAPE_DIVIDED_RECTANGLE,
113 // SHAPE_COMPOSITE,
114 // SHAPE_CONTROL_POINT,
115 // SHAPE_DRAWN,
116 // SHAPE_DIVISION,
117 // SHAPE_LABEL_OBJECT,
118 // SHAPE_BITMAP,
119 // SHAPE_DIVIDED_OBJECT_CONTROL_POINT,
120 // OBJECT_REGION,
121 OP_CLICK_LEFT,
122 OP_CLICK_RIGHT,
123 OP_DRAG_LEFT,
124 OP_DRAG_RIGHT,
125 OP_ALL,
126 ATTACHMENT_MODE_NONE,
127 ATTACHMENT_MODE_EDGE,
128 ATTACHMENT_MODE_BRANCHING,
129 BRANCHING_ATTACHMENT_NORMAL,
130 BRANCHING_ATTACHMENT_BLOB,
131
132 gyCONSTRAINT_CENTRED_VERTICALLY,
133 gyCONSTRAINT_CENTRED_HORIZONTALLY,
134 gyCONSTRAINT_CENTRED_BOTH,
135 gyCONSTRAINT_LEFT_OF,
136 gyCONSTRAINT_RIGHT_OF,
137 gyCONSTRAINT_ABOVE,
138 gyCONSTRAINT_BELOW,
139 gyCONSTRAINT_ALIGNED_TOP,
140 gyCONSTRAINT_ALIGNED_BOTTOM,
141 gyCONSTRAINT_ALIGNED_LEFT,
142 gyCONSTRAINT_ALIGNED_RIGHT,
143 gyCONSTRAINT_MIDALIGNED_TOP,
144 gyCONSTRAINT_MIDALIGNED_BOTTOM,
145 gyCONSTRAINT_MIDALIGNED_LEFT,
146 gyCONSTRAINT_MIDALIGNED_RIGHT,
147
148 DIVISION_SIDE_NONE,
149 DIVISION_SIDE_LEFT,
150 DIVISION_SIDE_TOP,
151 DIVISION_SIDE_RIGHT,
152 DIVISION_SIDE_BOTTOM,
153
154 };
155
156
157
158 //---------------------------------------------------------------------------
159
160 MustHaveApp(wxOGLInitialize);
161 void wxOGLInitialize();
162
163 MustHaveApp(wxOGLCleanUp);
164 void wxOGLCleanUp();
165
166
167 %{
168 //---------------------------------------------------------------------------
169
170 // Convert from a Python list to a list of className objects. This one will
171 // work for any class for the VERY generic cases, but beyond that the helper
172 // needs to know more about the type.
173 wxList* wxPy_wxListHelper(PyObject* pyList, const wxChar* className) {
174 bool blocked = wxPyBeginBlockThreads();
175 if (!PyList_Check(pyList)) {
176 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
177 wxPyEndBlockThreads(blocked);
178 return NULL;
179 }
180 int count = PyList_Size(pyList);
181 wxList* list = new wxList;
182 if (! list) {
183 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
184 wxPyEndBlockThreads(blocked);
185 return NULL;
186 }
187 for (int x=0; x<count; x++) {
188 PyObject* pyo = PyList_GetItem(pyList, x);
189 wxObject* wxo = NULL;
190
191 if ( !wxPyConvertSwigPtr(pyo, (void **)&wxo, className) ) {
192 wxString errmsg;
193 errmsg.Printf(wxT("Type error, expected list of %s objects"), className);
194 PyErr_SetString(PyExc_TypeError, errmsg.mb_str());
195 wxPyEndBlockThreads(blocked);
196 return NULL;
197 }
198 list->Append(wxo);
199 }
200 wxPyEndBlockThreads(blocked);
201 return list;
202 }
203
204 //---------------------------------------------------------------------------
205
206 wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) {
207 bool blocked = wxPyBeginBlockThreads();
208 if (!PyList_Check(pyList)) {
209 PyErr_SetString(PyExc_TypeError, "Expected a list object.");
210 wxPyEndBlockThreads(blocked);
211 return NULL;
212 }
213 int count = PyList_Size(pyList);
214 wxList* list = new wxList;
215 if (! list) {
216 PyErr_SetString(PyExc_MemoryError, "Unable to allocate wxList object");
217 wxPyEndBlockThreads(blocked);
218 return NULL;
219 }
220 for (int x=0; x<count; x++) {
221 PyObject* pyo = PyList_GetItem(pyList, x);
222
223 if (PyTuple_Check(pyo)) {
224 PyObject* o1 = PyNumber_Float(PyTuple_GetItem(pyo, 0));
225 PyObject* o2 = PyNumber_Float(PyTuple_GetItem(pyo, 1));
226
227 double val1 = (o1 ? PyFloat_AsDouble(o1) : 0.0);
228 double val2 = (o2 ? PyFloat_AsDouble(o2) : 0.0);
229
230 list->Append((wxObject*) new wxRealPoint(val1, val2));
231
232 } else {
233 wxRealPoint* wxo = NULL;
234 if (wxPyConvertSwigPtr(pyo, (void **)&wxo, wxT("wxRealPoint"))) {
235 PyErr_SetString(PyExc_TypeError, "Type error, expected list of wxRealPoint objects or 2-tuples");
236 wxPyEndBlockThreads(blocked);
237 return NULL;
238 }
239 list->Append((wxObject*) new wxRealPoint(*wxo));
240 }
241 }
242 wxPyEndBlockThreads(blocked);
243 return list;
244 }
245
246 //---------------------------------------------------------------------------
247
248 PyObject* wxPyMake_wxShapeEvtHandler(wxShapeEvtHandler* source, bool setThisOwn) {
249 PyObject* target = NULL;
250
251 if (source && wxIsKindOf(source, wxShapeEvtHandler)) {
252 // If it's derived from wxShapeEvtHandler then there may
253 // already be a pointer to a Python object that we can use
254 // in the OOR data.
255 wxShapeEvtHandler* seh = (wxShapeEvtHandler*)source;
256 wxPyOORClientData* data = (wxPyOORClientData*)seh->GetClientObject();
257 if (data) {
258 target = data->m_obj;
259 Py_INCREF(target);
260 }
261 }
262 if (! target) {
263 target = wxPyMake_wxObject2(source, setThisOwn, false);
264 if (target != Py_None)
265 ((wxShapeEvtHandler*)source)->SetClientObject(new wxPyOORClientData(target));
266 }
267 return target;
268 }
269
270 //---------------------------------------------------------------------------
271
272 PyObject* wxPy_ConvertRealPointList(wxListBase* listbase) {
273 wxList* list = (wxList*)listbase;
274 PyObject* pyList;
275 PyObject* pyObj;
276 wxObject* wxObj;
277 wxNode* node = list->GetFirst();
278
279 bool blocked = wxPyBeginBlockThreads();
280 pyList = PyList_New(0);
281 while (node) {
282 wxObj = node->GetData();
283 pyObj = wxPyConstructObject(wxObj, wxT("wxRealPoint"), 0);
284 PyList_Append(pyList, pyObj);
285 node = node->GetNext();
286 }
287 wxPyEndBlockThreads(blocked);
288 return pyList;
289 }
290
291 //---------------------------------------------------------------------------
292
293 PyObject* wxPy_ConvertShapeList(wxListBase* listbase) {
294 wxList* list = (wxList*)listbase;
295 PyObject* pyList;
296 PyObject* pyObj;
297 wxObject* wxObj;
298 wxNode* node = list->GetFirst();
299
300 bool blocked = wxPyBeginBlockThreads();
301 pyList = PyList_New(0);
302 while (node) {
303 wxObj = node->GetData();
304 pyObj = wxPyMake_wxShapeEvtHandler((wxShapeEvtHandler*)wxObj, false);
305 PyList_Append(pyList, pyObj);
306 node = node->GetNext();
307 }
308 wxPyEndBlockThreads(blocked);
309 return pyList;
310 }
311
312
313 //---------------------------------------------------------------------------
314
315 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeCanvas, wxShapeCanvas);
316 IMPLEMENT_DYNAMIC_CLASS(wxPyShapeEvtHandler, wxShapeEvtHandler);
317 IMPLEMENT_ABSTRACT_CLASS(wxPyShape, wxShape);
318 IMPLEMENT_DYNAMIC_CLASS(wxPyRectangleShape, wxRectangleShape);
319 IMPLEMENT_DYNAMIC_CLASS(wxPyControlPoint, wxControlPoint);
320 IMPLEMENT_DYNAMIC_CLASS(wxPyBitmapShape, wxBitmapShape);
321 IMPLEMENT_DYNAMIC_CLASS(wxPyDrawnShape, wxDrawnShape);
322 IMPLEMENT_DYNAMIC_CLASS(wxPyCompositeShape, wxCompositeShape);
323 IMPLEMENT_DYNAMIC_CLASS(wxPyDividedShape, wxDividedShape);
324 IMPLEMENT_DYNAMIC_CLASS(wxPyDivisionShape, wxDivisionShape);
325 IMPLEMENT_DYNAMIC_CLASS(wxPyEllipseShape, wxEllipseShape);
326 IMPLEMENT_DYNAMIC_CLASS(wxPyCircleShape, wxCircleShape);
327 IMPLEMENT_DYNAMIC_CLASS(wxPyLineShape, wxLineShape);
328 IMPLEMENT_DYNAMIC_CLASS(wxPyPolygonShape, wxPolygonShape);
329 IMPLEMENT_DYNAMIC_CLASS(wxPyTextShape, wxTextShape);
330
331 //---------------------------------------------------------------------------
332
333 // extern "C" SWIGEXPORT(void) initoglbasicc();
334 // extern "C" SWIGEXPORT(void) initoglshapesc();
335 // extern "C" SWIGEXPORT(void) initoglshapes2c();
336 // extern "C" SWIGEXPORT(void) initoglcanvasc();
337 %}
338
339
340 %init %{
341
342 // initoglbasicc();
343 // initoglshapesc();
344 // initoglshapes2c();
345 // initoglcanvasc();
346
347
348 wxPyPtrTypeMap_Add("wxControlPoint", "wxPyControlPoint");
349 wxPyPtrTypeMap_Add("wxShapeCanvas", "wxPyShapeCanvas");
350 wxPyPtrTypeMap_Add("wxShapeEvtHandler", "wxPyShapeEvtHandler");
351 wxPyPtrTypeMap_Add("wxShape", "wxPyShape");
352 wxPyPtrTypeMap_Add("wxRectangleShape", "wxPyRectangleShape");
353 wxPyPtrTypeMap_Add("wxDrawnShape", "wxPyDrawnShape");
354 wxPyPtrTypeMap_Add("wxCompositeShape", "wxPyCompositeShape");
355 wxPyPtrTypeMap_Add("wxDividedShape", "wxPyDividedShape");
356 wxPyPtrTypeMap_Add("wxDivisionShape", "wxPyDivisionShape");
357 wxPyPtrTypeMap_Add("wxEllipseShape", "wxPyEllipseShape");
358 wxPyPtrTypeMap_Add("wxCircleShape", "wxPyCircleShape");
359 wxPyPtrTypeMap_Add("wxLineShape", "wxPyLineShape");
360 wxPyPtrTypeMap_Add("wxPolygonShape", "wxPyPolygonShape");
361 wxPyPtrTypeMap_Add("wxTextShape", "wxPyTextShape");
362
363 %}
364
365 //---------------------------------------------------------------------------
366 //---------------------------------------------------------------------------