]>
Commit | Line | Data |
---|---|---|
7bf85405 RD |
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 | ||
cf694132 RD |
14 | //--------------------------------------------------------------------------- |
15 | // Tell SWIG to wrap all the wrappers with Python's thread macros | |
16 | ||
17 | %except(python) { | |
18 | wxPy_BEGIN_ALLOW_THREADS; | |
19 | $function | |
20 | wxPy_END_ALLOW_THREADS; | |
493f1553 | 21 | if (PyErr_Occurred()) return NULL; |
cf694132 RD |
22 | } |
23 | ||
7bf85405 | 24 | //---------------------------------------------------------------------- |
eec92d76 | 25 | // LCOUNT and choices go together. They allow a single Python list to be |
2f90df85 | 26 | // converted to an integer count and an array count items long. |
7bf85405 RD |
27 | |
28 | %typemap(python,build) int LCOUNT { | |
eec92d76 RD |
29 | if (_in_choices) { |
30 | $target = PyList_Size(_in_choices); | |
cf694132 RD |
31 | } |
32 | else { | |
33 | $target = 0; | |
34 | } | |
7bf85405 RD |
35 | } |
36 | ||
37 | ||
38 | ||
eec92d76 | 39 | %typemap(python,in) byte* choices { |
b639c3c5 RD |
40 | $target = byte_LIST_helper($source); |
41 | if ($target == NULL) { | |
42 | return NULL; | |
43 | } | |
44 | } | |
eec92d76 | 45 | %typemap(python,freearg) byte* choices { |
b639c3c5 RD |
46 | delete [] $source; |
47 | } | |
48 | ||
de9d9ed2 RD |
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 | ||
b639c3c5 | 60 | |
eec92d76 | 61 | %typemap(python,in) int* choices { |
7bf85405 RD |
62 | $target = int_LIST_helper($source); |
63 | if ($target == NULL) { | |
64 | return NULL; | |
65 | } | |
66 | } | |
eec92d76 | 67 | %typemap(python,freearg) int* choices { |
7bf85405 RD |
68 | delete [] $source; |
69 | } | |
70 | ||
71 | ||
eec92d76 | 72 | %typemap(python,in) long* choices { |
7bf85405 RD |
73 | $target = long_LIST_helper($source); |
74 | if ($target == NULL) { | |
75 | return NULL; | |
76 | } | |
77 | } | |
eec92d76 | 78 | %typemap(python,freearg) long* choices { |
7bf85405 RD |
79 | delete [] $source; |
80 | } | |
81 | ||
82 | ||
eec92d76 | 83 | %typemap(python,in) unsigned long* choices { |
7bf85405 RD |
84 | $target = (unsigned long*)long_LIST_helper($source); |
85 | if ($target == NULL) { | |
86 | return NULL; | |
87 | } | |
88 | } | |
eec92d76 | 89 | %typemap(python,freearg) unsigned long* choices { |
7bf85405 RD |
90 | delete [] $source; |
91 | } | |
92 | ||
93 | ||
eec92d76 | 94 | %typemap(python,in) char** choices { |
7bf85405 RD |
95 | $target = string_LIST_helper($source); |
96 | if ($target == NULL) { | |
97 | return NULL; | |
98 | } | |
99 | } | |
eec92d76 | 100 | %typemap(python,freearg) char** choices { |
7bf85405 RD |
101 | delete [] $source; |
102 | } | |
103 | ||
104 | ||
eec92d76 RD |
105 | %typemap(python,in) wxBitmap** choices { |
106 | $target = wxBitmap_LIST_helper($source); | |
7bf85405 RD |
107 | if ($target == NULL) { |
108 | return NULL; | |
109 | } | |
110 | } | |
eec92d76 | 111 | %typemap(python,freearg) wxBitmap** choices { |
7bf85405 RD |
112 | delete [] $source; |
113 | } | |
114 | ||
eec92d76 RD |
115 | %typemap(python,in) wxString* choices { |
116 | $target = wxString_LIST_helper($source); | |
7bf85405 RD |
117 | if ($target == NULL) { |
118 | return NULL; | |
119 | } | |
120 | } | |
eec92d76 | 121 | %typemap(python,freearg) wxString* choices { |
7bf85405 RD |
122 | delete [] $source; |
123 | } | |
124 | ||
eec92d76 RD |
125 | %typemap(python,in) wxAcceleratorEntry* choices { |
126 | $target = wxAcceleratorEntry_LIST_helper($source); | |
7bf85405 RD |
127 | if ($target == NULL) { |
128 | return NULL; | |
129 | } | |
130 | } | |
eec92d76 | 131 | %typemap(python,freearg) wxAcceleratorEntry* choices { |
7bf85405 RD |
132 | delete [] $source; |
133 | } | |
134 | ||
eec92d76 | 135 | %typemap(python,build) int PCOUNT { |
e0672e2f | 136 | $target = NPOINTS; |
eec92d76 RD |
137 | } |
138 | ||
e0672e2f RD |
139 | %typemap(python,in) wxPoint* points (int NPOINTS) { |
140 | $target = wxPoint_LIST_helper($source, &NPOINTS); | |
141 | if ($target == NULL) { | |
142 | return NULL; | |
143 | } | |
7bf85405 | 144 | } |
eec92d76 | 145 | %typemap(python,freearg) wxPoint* points { |
7bf85405 RD |
146 | delete [] $source; |
147 | } | |
148 | ||
149 | ||
eec92d76 | 150 | |
e0672e2f | 151 | |
7bf85405 RD |
152 | //--------------------------------------------------------------------------- |
153 | ||
154 | %{ | |
7a446686 RD |
155 | #if PYTHON_API_VERSION >= 1009 |
156 | static char* wxStringErrorMsg = "String or Unicode type required"; | |
157 | #else | |
158 | static char* wxStringErrorMsg = "string type is required for parameter"; | |
159 | #endif | |
7bf85405 RD |
160 | %} |
161 | ||
185d7c3e RD |
162 | // TODO: Which works best??? |
163 | ||
164 | // Implementation #1 | |
165 | // %typemap(python, in) wxString& (PyObject* temp, int tmpDoDecRef) { | |
166 | // temp = $source; | |
167 | // tmpDoDecRef = 0; | |
168 | // #if PYTHON_API_VERSION >= 1009 | |
169 | // if (PyUnicode_Check(temp) { | |
170 | // temp = PyUnicode_AsUTF8String(temp); | |
171 | // if (! temp) { | |
172 | // PyErr_SetString(PyExc_TypeError, "Unicode encoding to UTF8 failed."); | |
173 | // return NULL; | |
174 | // } | |
175 | // tmpDoDecRef = 1; | |
176 | // #endif | |
177 | // if (!PyString_Check(temp)) { | |
178 | // PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); | |
179 | // return NULL; | |
180 | // } | |
181 | // $target = new wxString(PyString_AsString(temp), PyString_Size(temp)); | |
182 | // #if PYTHON_API_VERESION >= 1009 | |
183 | // if (tmpDoDecRef) Py_DECREF(temp); | |
184 | // #endif | |
185 | // } | |
186 | ||
187 | ||
188 | // Implementation #2 | |
7bf85405 | 189 | %typemap(python, in) wxString& { |
185d7c3e RD |
190 | #if PYTHON_API_VERSION >= 1009 |
191 | char* tmpPtr; int tmpSize; | |
192 | if (!PyString_Check($source) && !PyUnicode_Check($source)) { | |
7a446686 | 193 | PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); |
185d7c3e RD |
194 | return NULL; |
195 | } | |
196 | if (PyString_AsStringAndSize($source, &tmpPtr, &tmpSize) == -1) | |
197 | return NULL; | |
198 | $target = new wxString(tmpPtr, tmpSize); | |
199 | #else | |
7bf85405 RD |
200 | if (!PyString_Check($source)) { |
201 | PyErr_SetString(PyExc_TypeError, wxStringErrorMsg); | |
202 | return NULL; | |
203 | } | |
185d7c3e RD |
204 | $target = new wxString(PyString_AS_STRING($source), PyString_GET_SIZE($source)); |
205 | #endif | |
7bf85405 | 206 | } |
185d7c3e RD |
207 | |
208 | ||
209 | ||
210 | ||
7bf85405 RD |
211 | %typemap(python, freearg) wxString& { |
212 | if ($target) | |
213 | delete $source; | |
214 | } | |
215 | ||
216 | ||
217 | ||
218 | %typemap(python, out) wxString { | |
eec92d76 | 219 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); |
7bf85405 RD |
220 | } |
221 | %typemap(python, ret) wxString { | |
222 | delete $source; | |
223 | } | |
224 | ||
225 | ||
226 | %typemap(python, out) wxString* { | |
eec92d76 | 227 | $target = PyString_FromStringAndSize($source->c_str(), $source->Len()); |
7bf85405 RD |
228 | } |
229 | ||
230 | ||
2f90df85 RD |
231 | |
232 | ||
233 | ||
7bf85405 | 234 | //--------------------------------------------------------------------------- |
2f90df85 RD |
235 | // Typemaps to convert Python sequence objects (2-tuples, etc.) to |
236 | // wxSize, wxPoint, wxRealPoint, and wxRect. | |
237 | ||
238 | %typemap(python,in) wxSize& (wxSize temp) { | |
239 | $target = &temp; | |
240 | if (! wxSize_helper($source, &$target)) | |
241 | return NULL; | |
242 | } | |
243 | ||
244 | %typemap(python,in) wxPoint& (wxPoint temp) { | |
245 | $target = &temp; | |
246 | if (! wxPoint_helper($source, &$target)) | |
247 | return NULL; | |
248 | } | |
249 | ||
250 | %typemap(python,in) wxRealPoint& (wxRealPoint temp) { | |
251 | $target = &temp; | |
252 | if (! wxRealPoint_helper($source, &$target)) | |
253 | return NULL; | |
254 | } | |
7bf85405 | 255 | |
2f90df85 RD |
256 | %typemap(python,in) wxRect& (wxRect temp) { |
257 | $target = &temp; | |
258 | if (! wxRect_helper($source, &$target)) | |
259 | return NULL; | |
260 | } | |
7bf85405 | 261 | |
f6bcfd97 BP |
262 | //--------------------------------------------------------------------------- |
263 | // Typemap to convert strings to wxColour. Two string formats are accepted, | |
de20db99 | 264 | // either a colour name, or a hex colour spec like "#RRGGBB" |
f6bcfd97 BP |
265 | |
266 | %typemap(python,in) wxColour& (wxColour temp) { | |
267 | $target = &temp; | |
268 | if (! wxColour_helper($source, &$target)) | |
269 | return NULL; | |
270 | } | |
271 | ||
7bf85405 | 272 | |
2f90df85 | 273 | //--------------------------------------------------------------------------- |
7bf85405 RD |
274 | // Map T_OUTPUTs for floats to return ints. |
275 | ||
276 | ||
277 | %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp), | |
278 | double *T_OUTPUT_TOINT(double temp) | |
279 | { | |
280 | $target = &temp; | |
281 | } | |
282 | ||
283 | ||
284 | %typemap(python,argout) float *T_OUTPUT_TOINT, | |
285 | double *T_OUTPUT_TOINT | |
286 | { | |
287 | PyObject *o; | |
288 | o = PyInt_FromLong((long) (*$source)); | |
289 | $target = t_output_helper($target, o); | |
290 | } | |
291 | ||
9416aa89 RD |
292 | //--------------------------------------------------------------------------- |
293 | // Typemaps to convert return values that are base class pointers | |
294 | // to the real derived type, if possible. See wxPyMake_wxObject in | |
295 | // helpers.cpp | |
296 | ||
297 | ||
298 | %typemap(python, out) wxButton* { $target = wxPyMake_wxObject($source); } | |
299 | %typemap(python, out) wxControl* { $target = wxPyMake_wxObject($source); } | |
300 | %typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); } | |
301 | %typemap(python, out) wxEvtHandler* { $target = wxPyMake_wxObject($source); } | |
302 | %typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); } | |
303 | %typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); } | |
304 | %typemap(python, out) wxFrame* { $target = wxPyMake_wxObject($source); } | |
305 | %typemap(python, out) wxGrid* { $target = wxPyMake_wxObject($source); } | |
306 | %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxObject($source); } | |
307 | %typemap(python, out) wxImageList* { $target = wxPyMake_wxObject($source); } | |
308 | %typemap(python, out) wxListItem* { $target = wxPyMake_wxObject($source); } | |
309 | %typemap(python, out) wxMDIChildFrame* { $target = wxPyMake_wxObject($source); } | |
310 | %typemap(python, out) wxMDIClientWindow* { $target = wxPyMake_wxObject($source); } | |
311 | %typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); } | |
312 | %typemap(python, out) wxMenuBar* { $target = wxPyMake_wxObject($source); } | |
313 | %typemap(python, out) wxMenuItem* { $target = wxPyMake_wxObject($source); } | |
314 | %typemap(python, out) wxMouseEvent* { $target = wxPyMake_wxObject($source); } | |
315 | %typemap(python, out) wxNotebook* { $target = wxPyMake_wxObject($source); } | |
316 | %typemap(python, out) wxObject* { $target = wxPyMake_wxObject($source); } | |
317 | %typemap(python, out) wxPyPrintout* { $target = wxPyMake_wxObject($source); } | |
318 | %typemap(python, out) wxSizer* { $target = wxPyMake_wxObject($source); } | |
319 | %typemap(python, out) wxSizer* { $target = wxPyMake_wxObject($source); } | |
320 | %typemap(python, out) wxStaticBox* { $target = wxPyMake_wxObject($source); } | |
321 | %typemap(python, out) wxStatusBar* { $target = wxPyMake_wxObject($source); } | |
322 | %typemap(python, out) wxTextCtrl* { $target = wxPyMake_wxObject($source); } | |
323 | %typemap(python, out) wxToolBar* { $target = wxPyMake_wxObject($source); } | |
324 | %typemap(python, out) wxToolBarBase* { $target = wxPyMake_wxObject($source); } | |
325 | %typemap(python, out) wxToolBarToolBase* { $target = wxPyMake_wxObject($source); } | |
326 | %typemap(python, out) wxToolTip* { $target = wxPyMake_wxObject($source); } | |
327 | %typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); } | |
328 | %typemap(python, out) wxWindow* { $target = wxPyMake_wxObject($source); } | |
329 | ||
330 | ||
331 | //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); } | |
332 | //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); } | |
333 | //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); } | |
334 | //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); } | |
335 | ||
7bf85405 | 336 | //--------------------------------------------------------------------------- |
2f90df85 | 337 | //--------------------------------------------------------------------------- |
7bf85405 | 338 | |
9416aa89 RD |
339 | |
340 | ||
341 | ||
342 | ||
343 |