1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Special typemaps specifically for wxPython.
9 // Copyright: (c) 1998 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
14 //---------------------------------------------------------------------------
15 // Tell SWIG to wrap all the wrappers with our thread protection
18 PyThreadState* __tstate = wxPyBeginAllowThreads();
20 wxPyEndAllowThreads(__tstate);
21 if (PyErr_Occurred()) return NULL;
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.
28 %typemap(python,build) int LCOUNT {
30 $target = PyList_Size(_in_choices);
39 %typemap(python,in) byte* choices {
40 $target = byte_LIST_helper($source);
41 if ($target == NULL) {
45 %typemap(python,freearg) byte* choices {
49 // wxDash is a signed char
50 %typemap(python,in) wxDash* choices {
51 $target = (wxDash*)byte_LIST_helper($source);
52 if ($target == NULL) {
56 %typemap(python,freearg) wxDash* choices {
61 %typemap(python,in) int* choices {
62 $target = int_LIST_helper($source);
63 if ($target == NULL) {
67 %typemap(python,freearg) int* choices {
72 %typemap(python,in) long* choices {
73 $target = long_LIST_helper($source);
74 if ($target == NULL) {
78 %typemap(python,freearg) long* choices {
83 %typemap(python,in) unsigned long* choices {
84 $target = (unsigned long*)long_LIST_helper($source);
85 if ($target == NULL) {
89 %typemap(python,freearg) unsigned long* choices {
94 %typemap(python,in) char** choices {
95 $target = string_LIST_helper($source);
96 if ($target == NULL) {
100 %typemap(python,freearg) char** choices {
105 %typemap(python,in) wxBitmap** choices {
106 $target = wxBitmap_LIST_helper($source);
107 if ($target == NULL) {
111 %typemap(python,freearg) wxBitmap** choices {
115 %typemap(python,in) wxString* choices {
116 $target = wxString_LIST_helper($source);
117 if ($target == NULL) {
121 %typemap(python,freearg) wxString* choices {
125 %typemap(python,in) wxAcceleratorEntry* choices {
126 $target = wxAcceleratorEntry_LIST_helper($source);
127 if ($target == NULL) {
131 %typemap(python,freearg) wxAcceleratorEntry* choices {
135 %typemap(python,build) int PCOUNT {
139 %typemap(python,in) wxPoint* points (int NPOINTS) {
140 $target = wxPoint_LIST_helper($source, &NPOINTS);
141 if ($target == NULL) {
145 %typemap(python,freearg) wxPoint* points {
152 //---------------------------------------------------------------------------
155 %typemap(python, in) wxString& {
156 $target = wxString_in_helper($source);
162 %typemap(python, freearg) wxString& {
169 %typemap(python, out) wxString {
171 $target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
173 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
176 %typemap(python, ret) wxString {
181 %typemap(python, out) wxString* {
183 $target = PyUnicode_FromWideChar($source->c_str(), $source->Len());
185 $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
191 //---------------------------------------------------------------------------
194 %typemap(python, in) wxMemoryBuffer& {
195 if (!PyString_Check($source)) {
196 PyErr_SetString(PyExc_TypeError, "String buffer expected");
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);
205 %typemap(python, freearg) wxMemoryBuffer& {
210 %typemap(python, out) wxMemoryBuffer {
211 $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen());
214 %typemap(python, ret) wxMemoryBuffer {
219 //---------------------------------------------------------------------------
220 // Typemaps to convert Python sequence objects (tuples, etc.) to
221 // wxSize, wxPoint, wxRealPoint, and wxRect.
223 %typemap(python,in) wxSize& (wxSize temp) {
225 if (! wxSize_helper($source, &$target))
229 %typemap(python,in) wxPoint& (wxPoint temp) {
231 if (! wxPoint_helper($source, &$target))
235 %typemap(python,in) wxRealPoint& (wxRealPoint temp) {
237 if (! wxRealPoint_helper($source, &$target))
241 %typemap(python,in) wxRect& (wxRect temp) {
243 if (! wxRect_helper($source, &$target))
247 %typemap(python,in) wxPoint2DDouble& (wxPoint2DDouble temp) {
249 if (! wxPoint2DDouble_helper($source, &$target))
253 //---------------------------------------------------------------------------
254 // Typemap to convert strings to wxColour. Two string formats are accepted,
255 // either a colour name, or a hex colour spec like "#RRGGBB"
257 %typemap(python,in) wxColour& (wxColour temp) {
259 if (! wxColour_helper($source, &$target))
263 //---------------------------------------------------------------------------
264 // Typemap for wxArrayString from Python sequence objects
266 %typemap(python,in) wxArrayString& {
267 if (! PySequence_Check($source)) {
268 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
271 $target = new wxArrayString;
272 int i, len=PySequence_Length($source);
273 for (i=0; i<len; i++) {
274 PyObject* item = PySequence_GetItem($source, i);
276 PyObject* str = PyObject_Unicode(item);
278 PyObject* str = PyObject_Str(item);
280 $target->Add(Py2wxString(str));
286 %typemap(python, freearg) wxArrayString& {
291 //---------------------------------------------------------------------------
292 // Typemap for wxArrayInt from Python sequence objects
294 %typemap(python,in) wxArrayInt& {
295 if (! PySequence_Check($source)) {
296 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
299 $target = new wxArrayInt;
300 int i, len=PySequence_Length($source);
301 for (i=0; i<len; i++) {
302 PyObject* item = PySequence_GetItem($source, i);
303 PyObject* number = PyNumber_Int(item);
304 $target->Add(PyInt_AS_LONG(number));
310 %typemap(python, freearg) wxArrayInt& {
316 // Typemaps to convert an array of ints to a list
317 %typemap(python, out) wxArrayInt& {
318 $target = PyList_New(0);
320 for (idx = 0; idx < $source->GetCount(); idx += 1) {
321 PyObject* val = PyInt_FromLong($source->Item(idx));
322 PyList_Append($target, val);
327 %typemap(python, out) wxArrayInt {
328 $target = PyList_New(0);
330 for (idx = 0; idx < $source->GetCount(); idx += 1) {
331 PyObject* val = PyInt_FromLong($source->Item(idx));
332 PyList_Append($target, val);
339 //---------------------------------------------------------------------------
340 // Map T_OUTPUTs for floats to return ints.
343 %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
344 double *T_OUTPUT_TOINT(double temp)
350 %typemap(python,argout) float *T_OUTPUT_TOINT,
351 double *T_OUTPUT_TOINT
354 o = PyInt_FromLong((long) (*$source));
355 $target = t_output_helper($target, o);
359 %typemap(python,ignore) bool *T_OUTPUT(int temp)
361 $target = (bool*)&temp;
364 %typemap(python,argout) bool *T_OUTPUT
367 o = PyInt_FromLong((long) (*$source));
368 $target = t_output_helper($target, o);
371 %typemap(python,ignore) bool *OUTPUT = bool *T_OUTPUT;
372 %typemap(python,argout) bool *OUTPUT = bool *T_OUTPUT;
376 %typemap(python,ignore) byte *T_OUTPUT(int temp)
378 $target = (byte*)&temp;
381 %typemap(python,argout) byte *T_OUTPUT
384 o = PyInt_FromLong((long) (*$source));
385 $target = t_output_helper($target, o);
388 %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT;
389 %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT;
392 %typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT;
393 %typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT;
396 //---------------------------------------------------------------------------
397 // Typemaps to convert return values that are base class pointers
398 // to the real derived type, if possible. See wxPyMake_wxObject in
401 %typemap(python, out) wxEvtHandler* { $target = wxPyMake_wxObject($source); }
402 %typemap(python, out) wxMenu* { $target = wxPyMake_wxObject($source); }
403 %typemap(python, out) wxValidator* { $target = wxPyMake_wxObject($source); }
405 %typemap(python, out) wxApp* { $target = wxPyMake_wxObject($source); }
406 %typemap(python, out) wxPyApp* { $target = wxPyMake_wxObject($source); }
407 %typemap(python, out) wxDC* { $target = wxPyMake_wxObject($source); }
408 %typemap(python, out) wxFSFile* { $target = wxPyMake_wxObject($source); }
409 %typemap(python, out) wxFileSystem* { $target = wxPyMake_wxObject($source); }
410 %typemap(python, out) wxGridTableBase* { $target = wxPyMake_wxObject($source); }
411 %typemap(python, out) wxImageList* { $target = wxPyMake_wxObject($source); }
412 %typemap(python, out) wxListItem* { $target = wxPyMake_wxObject($source); }
413 %typemap(python, out) wxMenuItem* { $target = wxPyMake_wxObject($source); }
414 %typemap(python, out) wxMouseEvent* { $target = wxPyMake_wxObject($source); }
415 %typemap(python, out) wxObject* { $target = wxPyMake_wxObject($source); }
416 %typemap(python, out) wxPyPrintout* { $target = wxPyMake_wxObject($source); }
417 %typemap(python, out) wxToolBarToolBase* { $target = wxPyMake_wxObject($source); }
418 %typemap(python, out) wxToolTip* { $target = wxPyMake_wxObject($source); }
421 %typemap(python, out) wxBitmapButton* { $target = wxPyMake_wxObject($source); }
422 %typemap(python, out) wxButton* { $target = wxPyMake_wxObject($source); }
423 %typemap(python, out) wxControl* { $target = wxPyMake_wxObject($source); }
424 %typemap(python, out) wxFrame* { $target = wxPyMake_wxObject($source); }
425 %typemap(python, out) wxGrid* { $target = wxPyMake_wxObject($source); }
426 %typemap(python, out) wxListCtrl* { $target = wxPyMake_wxObject($source); }
427 %typemap(python, out) wxMDIChildFrame* { $target = wxPyMake_wxObject($source); }
428 %typemap(python, out) wxMDIClientWindow* { $target = wxPyMake_wxObject($source); }
429 %typemap(python, out) wxMenuBar* { $target = wxPyMake_wxObject($source); }
430 %typemap(python, out) wxNotebook* { $target = wxPyMake_wxObject($source); }
431 %typemap(python, out) wxStaticBox* { $target = wxPyMake_wxObject($source); }
432 %typemap(python, out) wxStatusBar* { $target = wxPyMake_wxObject($source); }
433 %typemap(python, out) wxTextCtrl* { $target = wxPyMake_wxObject($source); }
434 %typemap(python, out) wxToolBar* { $target = wxPyMake_wxObject($source); }
435 %typemap(python, out) wxToolBarBase* { $target = wxPyMake_wxObject($source); }
436 %typemap(python, out) wxTreeCtrl* { $target = wxPyMake_wxObject($source); }
437 %typemap(python, out) wxWindow* { $target = wxPyMake_wxObject($source); }
438 %typemap(python, out) wxHtmlWindow* { $target = wxPyMake_wxObject($source); }
439 %typemap(python, out) wxWizardPage* { $target = wxPyMake_wxObject($source); }
441 %typemap(python, out) wxSizer* { $target = wxPyMake_wxSizer($source); }
444 //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); }
445 //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); }
446 //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); }
447 //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); }
449 //---------------------------------------------------------------------------
450 //---------------------------------------------------------------------------