]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: my_typemaps.i | |
3 | // Purpose: Special typemaps specifically for wxPython. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 7/3/97 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 1998 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | ||
14 | //--------------------------------------------------------------------------- | |
15 | // Tell SWIG to wrap all the wrappers with our thread protection | |
16 | ||
17 | %except(python) { | |
18 | PyThreadState* __tstate = wxPyBeginAllowThreads(); | |
19 | $function | |
20 | wxPyEndAllowThreads(__tstate); | |
21 | if (PyErr_Occurred()) return NULL; | |
22 | } | |
23 | ||
24 | //---------------------------------------------------------------------- | |
25 | // LCOUNT and choices go together. They allow a single Python list to be | |
26 | // converted to an integer count and an array count items long. | |
27 | ||
28 | %typemap(python,build) int LCOUNT { | |
29 | if (_in_choices) { | |
30 | $target = PyList_Size(_in_choices); | |
31 | } | |
32 | else { | |
33 | $target = 0; | |
34 | } | |
35 | } | |
36 | ||
37 | ||
38 | ||
39 | %typemap(python,in) byte* choices { | |
40 | $target = byte_LIST_helper($source); | |
41 | if ($target == NULL) { | |
42 | return NULL; | |
43 | } | |
44 | } | |
45 | %typemap(python,freearg) byte* choices { | |
46 | delete [] $source; | |
47 | } | |
48 | ||
49 | // wxDash is a signed char | |
50 | %typemap(python,in) wxDash* choices { | |
51 | $target = (wxDash*)byte_LIST_helper($source); | |
52 | if ($target == NULL) { | |
53 | return NULL; | |
54 | } | |
55 | } | |
56 | %typemap(python,freearg) wxDash* choices { | |
57 | delete [] $source; | |
58 | } | |
59 | ||
60 | ||
61 | %typemap(python,in) int* choices { | |
62 | $target = int_LIST_helper($source); | |
63 | if ($target == NULL) { | |
64 | return NULL; | |
65 | } | |
66 | } | |
67 | %typemap(python,freearg) int* choices { | |
68 | delete [] $source; | |
69 | } | |
70 | ||
71 | ||
72 | %typemap(python,in) long* choices { | |
73 | $target = long_LIST_helper($source); | |
74 | if ($target == NULL) { | |
75 | return NULL; | |
76 | } | |
77 | } | |
78 | %typemap(python,freearg) long* choices { | |
79 | delete [] $source; | |
80 | } | |
81 | ||
82 | ||
83 | %typemap(python,in) unsigned long* choices { | |
84 | $target = (unsigned long*)long_LIST_helper($source); | |
85 | if ($target == NULL) { | |
86 | return NULL; | |
87 | } | |
88 | } | |
89 | %typemap(python,freearg) unsigned long* choices { | |
90 | delete [] $source; | |
91 | } | |
92 | ||
93 | ||
94 | %typemap(python,in) char** choices { | |
95 | $target = string_LIST_helper($source); | |
96 | if ($target == NULL) { | |
97 | return NULL; | |
98 | } | |
99 | } | |
100 | %typemap(python,freearg) char** choices { | |
101 | delete [] $source; | |
102 | } | |
103 | ||
104 | ||
105 | %typemap(python,in) wxBitmap** choices { | |
106 | $target = wxBitmap_LIST_helper($source); | |
107 | if ($target == NULL) { | |
108 | return NULL; | |
109 | } | |
110 | } | |
111 | %typemap(python,freearg) wxBitmap** choices { | |
112 | delete [] $source; | |
113 | } | |
114 | ||
115 | %typemap(python,in) wxString* choices { | |
116 | $target = wxString_LIST_helper($source); | |
117 | if ($target == NULL) { | |
118 | return NULL; | |
119 | } | |
120 | } | |
121 | %typemap(python,freearg) wxString* choices { | |
122 | delete [] $source; | |
123 | } | |
124 | ||
125 | %typemap(python,in) wxAcceleratorEntry* choices { | |
126 | $target = wxAcceleratorEntry_LIST_helper($source); | |
127 | if ($target == NULL) { | |
128 | return NULL; | |
129 | } | |
130 | } | |
131 | %typemap(python,freearg) wxAcceleratorEntry* choices { | |
132 | delete [] $source; | |
133 | } | |
134 | ||
135 | %typemap(python,build) int PCOUNT { | |
136 | $target = NPOINTS; | |
137 | } | |
138 | ||
139 | %typemap(python,in) wxPoint* points (int NPOINTS) { | |
140 | $target = wxPoint_LIST_helper($source, &NPOINTS); | |
141 | if ($target == NULL) { | |
142 | return NULL; | |
143 | } | |
144 | } | |
145 | %typemap(python,freearg) wxPoint* points { | |
146 | delete [] $source; | |
147 | } | |
148 | ||
149 | ||
150 | ||
151 | ||
152 | //--------------------------------------------------------------------------- | |
153 | ||
154 | ||
155 | %typemap(python, in) wxString& { | |
156 | $target = wxString_in_helper($source); | |
157 | if ($target == NULL) | |
158 | return NULL; | |
159 | } | |
160 | ||
161 | ||
162 | %typemap(python, freearg) wxString& { | |
163 | if ($target) | |
164 | delete $source; | |
165 | } | |
166 | ||
167 | ||
168 | ||
169 | %typemap(python, out) wxString { | |
170 | #if wxUSE_UNICODE | |
171 | $target = PyUnicode_FromUnicode($source->c_str(), $source->Len()); | |
172 | #else | |
173 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); | |
174 | #endif | |
175 | } | |
176 | %typemap(python, ret) wxString { | |
177 | delete $source; | |
178 | } | |
179 | ||
180 | ||
181 | %typemap(python, out) wxString* { | |
182 | #if wxUSE_UNICODE | |
183 | $target = PyUnicode_FromUnicode($source->c_str(), $source->Len()); | |
184 | #else | |
185 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); | |
186 | #endif | |
187 | } | |
188 | ||
189 | ||
190 | ||
191 | //--------------------------------------------------------------------------- | |
192 | ||
193 | ||
194 | %typemap(python, in) wxMemoryBuffer& { | |
195 | if (!PyString_Check($source)) { | |
196 | PyErr_SetString(PyExc_TypeError, "String buffer expected"); | |
197 | return NULL; | |
198 | } | |
199 | char* str = PyString_AS_STRING($source); | |
200 | int len = PyString_GET_SIZE($source); | |
201 | $target = new wxMemoryBuffer(len); | |
202 | memcpy($target->GetData(), str, len); | |
203 | } | |
204 | ||
205 | %typemap(python, freearg) wxMemoryBuffer& { | |
206 | if ($target) | |
207 | delete $source; | |
208 | } | |
209 | ||
210 | %typemap(python, out) wxMemoryBuffer { | |
211 | $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen()); | |
212 | } | |
213 | ||
214 | %typemap(python, ret) wxMemoryBuffer { | |
215 | delete $source; | |
216 | } | |
217 | ||
218 | ||
219 | //--------------------------------------------------------------------------- | |
220 | // Typemaps to convert Python sequence objects (tuples, etc.) to | |
221 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
222 | ||
223 | %typemap(python,in) wxSize& (wxSize temp) { | |
224 | $target = &temp; | |
225 | if (! wxSize_helper($source, &$target)) | |
226 | return NULL; | |
227 | } | |
228 | ||
229 | %typemap(python,in) wxPoint& (wxPoint temp) { | |
230 | $target = &temp; | |
231 | if (! wxPoint_helper($source, &$target)) | |
232 | return NULL; | |
233 | } | |
234 | ||
235 | %typemap(python,in) wxRealPoint& (wxRealPoint temp) { | |
236 | $target = &temp; | |
237 | if (! wxRealPoint_helper($source, &$target)) | |
238 | return NULL; | |
239 | } | |
240 | ||
241 | %typemap(python,in) wxRect& (wxRect temp) { | |
242 | $target = &temp; | |
243 | if (! wxRect_helper($source, &$target)) | |
244 | return NULL; | |
245 | } | |
246 | ||
247 | //--------------------------------------------------------------------------- | |
248 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
249 | // either a colour name, or a hex colour spec like "#RRGGBB" | |
250 | ||
251 | %typemap(python,in) wxColour& (wxColour temp) { | |
252 | $target = &temp; | |
253 | if (! wxColour_helper($source, &$target)) | |
254 | return NULL; | |
255 | } | |
256 | ||
257 | //--------------------------------------------------------------------------- | |
258 | // Typemap for wxArrayString from Python sequence objects | |
259 | ||
260 | %typemap(python,in) wxArrayString& { | |
261 | if (! PySequence_Check($source)) { | |
262 | PyErr_SetString(PyExc_TypeError, "Sequence of strings expected."); | |
263 | return NULL; | |
264 | } | |
265 | $target = new wxArrayString; | |
266 | int i, len=PySequence_Length($source); | |
267 | for (i=0; i<len; i++) { | |
268 | PyObject* item = PySequence_GetItem($source, i); | |
269 | #if wxUSE_UNICODE | |
270 | PyObject* str = PyObject_Unicode(item); | |
271 | $target->Add(PyUnicode_AsUnicode(str)); | |
272 | #else | |
273 | PyObject* str = PyObject_Str(item); | |
274 | $target->Add(PyString_AsString(str)); | |
275 | #endif | |
276 | Py_DECREF(item); | |
277 | Py_DECREF(str); | |
278 | } | |
279 | } | |
280 | ||
281 | %typemap(python, freearg) wxArrayString& { | |
282 | if ($target) | |
283 | delete $source; | |
284 | } | |
285 | ||
286 | //--------------------------------------------------------------------------- | |
287 | // Typemap for wxArrayInt from Python sequence objects | |
288 | ||
289 | %typemap(python,in) wxArrayInt& { | |
290 | if (! PySequence_Check($source)) { | |
291 | PyErr_SetString(PyExc_TypeError, "Sequence of integers expected."); | |
292 | return NULL; | |
293 | } | |
294 | $target = new wxArrayInt; | |
295 | int i, len=PySequence_Length($source); | |
296 | for (i=0; i<len; i++) { | |
297 | PyObject* item = PySequence_GetItem($source, i); | |
298 | PyObject* number = PyNumber_Int(item); | |
299 | $target->Add(PyInt_AS_LONG(number)); | |
300 | Py_DECREF(item); | |
301 | Py_DECREF(number); | |
302 | } | |
303 | } | |
304 | ||
305 | %typemap(python, freearg) wxArrayInt& { | |
306 | if ($target) | |
307 | delete $source; | |
308 | } | |
309 | ||
310 | ||
311 | //--------------------------------------------------------------------------- | |
312 | // Map T_OUTPUTs for floats to return ints. | |
313 | ||
314 | ||
315 | %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp), | |
316 | double *T_OUTPUT_TOINT(double temp) | |
317 | { | |
318 | $target = &temp; | |
319 | } | |
320 | ||
321 | ||
322 | %typemap(python,argout) float *T_OUTPUT_TOINT, | |
323 | double *T_OUTPUT_TOINT | |
324 | { | |
325 | PyObject *o; | |
326 | o = PyInt_FromLong((long) (*$source)); | |
327 | $target = t_output_helper($target, o); | |
328 | } | |
329 | ||
330 | ||
331 | %typemap(python,ignore) bool *T_OUTPUT(int temp) | |
332 | { | |
333 | $target = (bool*)&temp; | |
334 | } | |
335 | ||
336 | %typemap(python,argout) bool *T_OUTPUT | |
337 | { | |
338 | PyObject *o; | |
339 | o = PyInt_FromLong((long) (*$source)); | |
340 | $target = t_output_helper($target, o); | |
341 | } | |
342 | ||
343 | %typemap(python,ignore) bool *OUTPUT = bool *T_OUTPUT; | |
344 | %typemap(python,argout) bool *OUTPUT = bool *T_OUTPUT; | |
345 | ||
346 | ||
347 | ||
348 | %typemap(python,ignore) byte *T_OUTPUT(int temp) | |
349 | { | |
350 | $target = (byte*)&temp; | |
351 | } | |
352 | ||
353 | %typemap(python,argout) byte *T_OUTPUT | |
354 | { | |
355 | PyObject *o; | |
356 | o = PyInt_FromLong((long) (*$source)); | |
357 | $target = t_output_helper($target, o); | |
358 | } | |
359 | ||
360 | %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT; | |
361 | %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT; | |
362 | ||
363 | //--------------------------------------------------------------------------- | |
364 | // Typemaps to convert return values that are base class pointers | |
365 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
366 | // helpers.cpp | |
367 | ||
368 | %typemap(python, out) wxEvtHandler* { $target = wxPyMake_wxObject($source); } | |
369 | %typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); } | |
370 | %typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); } | |
371 | ||
372 | %typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); } | |
373 | %typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); } | |
374 | %typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); } | |
375 | %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxObject($source); } | |
376 | %typemap(python, out) wxImageList* { $target = wxPyMake_wxObject($source); } | |
377 | %typemap(python, out) wxListItem* { $target = wxPyMake_wxObject($source); } | |
378 | %typemap(python, out) wxMenuItem* { $target = wxPyMake_wxObject($source); } | |
379 | %typemap(python, out) wxMouseEvent* { $target = wxPyMake_wxObject($source); } | |
380 | %typemap(python, out) wxObject* { $target = wxPyMake_wxObject($source); } | |
381 | %typemap(python, out) wxPyPrintout* { $target = wxPyMake_wxObject($source); } | |
382 | %typemap(python, out) wxToolBarToolBase* { $target = wxPyMake_wxObject($source); } | |
383 | %typemap(python, out) wxToolTip* { $target = wxPyMake_wxObject($source); } | |
384 | ||
385 | ||
386 | %typemap(python, out) wxButton* { $target = wxPyMake_wxObject($source); } | |
387 | %typemap(python, out) wxControl* { $target = wxPyMake_wxObject($source); } | |
388 | %typemap(python, out) wxFrame* { $target = wxPyMake_wxObject($source); } | |
389 | %typemap(python, out) wxGrid* { $target = wxPyMake_wxObject($source); } | |
390 | %typemap(python, out) wxMDIChildFrame* { $target = wxPyMake_wxObject($source); } | |
391 | %typemap(python, out) wxMDIClientWindow* { $target = wxPyMake_wxObject($source); } | |
392 | %typemap(python, out) wxMenuBar* { $target = wxPyMake_wxObject($source); } | |
393 | %typemap(python, out) wxNotebook* { $target = wxPyMake_wxObject($source); } | |
394 | %typemap(python, out) wxStaticBox* { $target = wxPyMake_wxObject($source); } | |
395 | %typemap(python, out) wxStatusBar* { $target = wxPyMake_wxObject($source); } | |
396 | %typemap(python, out) wxTextCtrl* { $target = wxPyMake_wxObject($source); } | |
397 | %typemap(python, out) wxToolBar* { $target = wxPyMake_wxObject($source); } | |
398 | %typemap(python, out) wxToolBarBase* { $target = wxPyMake_wxObject($source); } | |
399 | %typemap(python, out) wxWindow* { $target = wxPyMake_wxObject($source); } | |
400 | %typemap(python, out) wxHtmlWindow* { $target = wxPyMake_wxObject($source); } | |
401 | ||
402 | %typemap(python, out) wxSizer* { $target = wxPyMake_wxSizer($source); } | |
403 | ||
404 | ||
405 | //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); } | |
406 | //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); } | |
407 | //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); } | |
408 | //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); } | |
409 | ||
410 | //--------------------------------------------------------------------------- | |
411 | //--------------------------------------------------------------------------- | |
412 | ||
413 | ||
414 | ||
415 | ||
416 | ||
417 |