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()) SWIG_fail;
25 //----------------------------------------------------------------------
26 // Typemaps to convert a list of items to an int (size) and an array
28 %typemap(in) (int choices, wxString* choices_array ) {
29 $1 = PyList_Size($input);
30 $2 = wxString_LIST_helper($input);
31 if ($2 == NULL) SWIG_fail;
33 %typemap(freearg) (int choices, wxString* choices_array ) {
40 // %typemap(python,build) int LCOUNT {
42 // $target = PyList_Size(_in_choices);
51 // %typemap(python,in) byte* choices {
52 // $target = byte_LIST_helper($source);
53 // if ($target == NULL) {
57 // %typemap(python,freearg) byte* choices {
61 // // wxDash is a signed char
62 // %typemap(python,in) wxDash* choices {
63 // $target = (wxDash*)byte_LIST_helper($source);
64 // if ($target == NULL) {
68 // %typemap(python,freearg) wxDash* choices {
73 // %typemap(python,in) int* choices {
74 // $target = int_LIST_helper($source);
75 // if ($target == NULL) {
79 // %typemap(python,freearg) int* choices {
84 // %typemap(python,in) long* choices {
85 // $target = long_LIST_helper($source);
86 // if ($target == NULL) {
90 // %typemap(python,freearg) long* choices {
95 // %typemap(python,in) unsigned long* choices {
96 // $target = (unsigned long*)long_LIST_helper($source);
97 // if ($target == NULL) {
101 // %typemap(python,freearg) unsigned long* choices {
102 // delete [] $source;
106 // %typemap(python,in) char** choices {
107 // $target = string_LIST_helper($source);
108 // if ($target == NULL) {
112 // %typemap(python,freearg) char** choices {
113 // delete [] $source;
117 // %typemap(python,in) wxBitmap** choices {
118 // $target = wxBitmap_LIST_helper($source);
119 // if ($target == NULL) {
123 // %typemap(python,freearg) wxBitmap** choices {
124 // delete [] $source;
127 // %typemap(python,in) wxString* choices {
128 // $target = wxString_LIST_helper($source);
129 // if ($target == NULL) {
133 // %typemap(python,freearg) wxString* choices {
134 // delete [] $source;
137 // %typemap(python,in) wxAcceleratorEntry* choices {
138 // $target = wxAcceleratorEntry_LIST_helper($source);
139 // if ($target == NULL) {
143 // %typemap(python,freearg) wxAcceleratorEntry* choices {
144 // delete [] $source;
147 // %typemap(python,build) int PCOUNT {
148 // $target = NPOINTS;
151 // %typemap(python,in) wxPoint* points (int NPOINTS) {
152 // $target = wxPoint_LIST_helper($source, &NPOINTS);
153 // if ($target == NULL) {
157 // %typemap(python,freearg) wxPoint* points {
158 // delete [] $source;
164 //---------------------------------------------------------------------------
167 %typemap(in) wxString& (bool temp=false) {
168 $1 = wxString_in_helper($input);
169 if ($1 == NULL) SWIG_fail;
174 %typemap(freearg) wxString& {
181 %typemap(out) wxString {
183 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
185 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
189 %typemap(python, out) wxString* {
191 $result = PyUnicode_FromWideChar($1->c_str(), $1->Len());
193 $result = PyString_FromStringAndSize($1->c_str(), $1->Len());
197 %typemap(python, varout) wxString {
199 $result = PyUnicode_FromWideChar($1.c_str(), $1.Len());
201 $result = PyString_FromStringAndSize($1.c_str(), $1.Len());
207 // //---------------------------------------------------------------------------
210 // %typemap(python, in) wxMemoryBuffer& {
211 // if (!PyString_Check($source)) {
212 // PyErr_SetString(PyExc_TypeError, "String buffer expected");
215 // char* str = PyString_AS_STRING($source);
216 // int len = PyString_GET_SIZE($source);
217 // $target = new wxMemoryBuffer(len);
218 // memcpy($target->GetData(), str, len);
221 // %typemap(python, freearg) wxMemoryBuffer& {
226 // %typemap(python, out) wxMemoryBuffer {
227 // $target = PyString_FromStringAndSize((char*)$source->GetData(), $source->GetDataLen());
230 // %typemap(python, ret) wxMemoryBuffer {
235 //---------------------------------------------------------------------------
236 // Typemaps to convert Python sequence objects (tuples, etc.) to
237 // wxSize, wxPoint, wxRealPoint, and wxRect.
240 %typemap(in) wxSize& (wxSize temp) {
242 if ( ! wxSize_helper($input, &$1)) SWIG_fail;
244 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxSize& {
245 $1 = wxPySimple_typecheck($input, wxT("wxSize"), 2);
249 %typemap(in) wxPoint& (wxPoint temp) {
251 if ( ! wxPoint_helper($input, &$1)) SWIG_fail;
253 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint& {
254 $1 = wxPySimple_typecheck($input, wxT("wxPoint"), 2);
258 %typemap(in) wxRealPoint& (wxRealPoint temp) {
260 if ( ! wxRealPoint_helper($input, &$1)) SWIG_fail;
262 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRealPoint& {
263 $1 = wxPySimple_typecheck($input, wxT("wxRealPoint"), 2);
267 %typemap(in) wxRect& (wxRect temp) {
269 if ( ! wxRect_helper($input, &$1)) SWIG_fail;
271 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxRect& {
272 $1 = wxPySimple_typecheck($input, wxT("wxRect"), 4);
276 %typemap(in) wxPoint2D& (wxPoint2D temp) {
278 if ( ! wxPoint2D_helper($input, &$1)) SWIG_fail;
280 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxPoint2D& {
281 $1 = wxPySimple_typecheck($input, wxT("wxPoint2D"), 2);
285 //---------------------------------------------------------------------------
286 // Typemap to convert strings to wxColour. Two string formats are accepted,
287 // either a colour name, or a hex colour spec like "#RRGGBB"
289 %typemap(in) wxColour& (wxColour temp) {
291 if ( ! wxColour_helper($input, &$1)) SWIG_fail;
293 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxColour& {
294 $1 = wxColour_typecheck($input);
299 //---------------------------------------------------------------------------
300 // Typemap for wxArrayString from Python sequence objects
302 %typemap(in) wxArrayString& {
303 if (! PySequence_Check($input)) {
304 PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
307 $1 = new wxArrayString;
308 int i, len=PySequence_Length($input);
309 for (i=0; i<len; i++) {
310 PyObject* item = PySequence_GetItem($input, i);
312 PyObject* str = PyObject_Unicode(item);
314 PyObject* str = PyObject_Str(item);
316 $1->Add(Py2wxString(str));
322 %typemap(freearg) wxArrayString& {
326 //---------------------------------------------------------------------------
327 // Typemap for wxArrayInt from Python sequence objects
329 %typemap(in) wxArrayInt& {
330 if (! PySequence_Check($input)) {
331 PyErr_SetString(PyExc_TypeError, "Sequence of integers expected.");
335 int i, len=PySequence_Length($input);
336 for (i=0; i<len; i++) {
337 PyObject* item = PySequence_GetItem($input, i);
338 PyObject* number = PyNumber_Int(item);
339 $1->Add(PyInt_AS_LONG(number));
345 %typemap(freearg) wxArrayInt& {
350 //---------------------------------------------------------------------------
351 // Typemaps to convert an array of ints to a list for return values
352 %typemap(out) wxArrayInt& {
353 $result = PyList_New(0);
355 for (idx = 0; idx < $1->GetCount(); idx += 1) {
356 PyObject* val = PyInt_FromLong( $1->Item(idx) );
357 PyList_Append($result, val);
362 %typemap(out) wxArrayInt {
363 $result = PyList_New(0);
365 for (idx = 0; idx < $1.GetCount(); idx += 1) {
366 PyObject* val = PyInt_FromLong( $1.Item(idx) );
367 PyList_Append($result, val);
374 // Typemaps to convert an array of ints to a list for return values
375 %typemap(out) wxArrayString& {
376 $result = wxArrayString2PyList_helper(*$1);
379 %typemap(out) wxArrayString {
380 $result = wxArrayString2PyList_helper($1);
384 // //---------------------------------------------------------------------------
385 // // Map T_OUTPUTs for floats to return ints.
388 // %typemap(python,ignore) float *T_OUTPUT_TOINT(float temp),
389 // double *T_OUTPUT_TOINT(double temp)
395 // %typemap(python,argout) float *T_OUTPUT_TOINT,
396 // double *T_OUTPUT_TOINT
399 // o = PyInt_FromLong((long) (*$source));
400 // $target = t_output_helper($target, o);
404 // %typemap(python,ignore) bool *T_OUTPUT(int temp)
406 // $target = (bool*)&temp;
409 // %typemap(python,argout) bool *T_OUTPUT
412 // o = PyInt_FromLong((long) (*$source));
413 // $target = t_output_helper($target, o);
416 // %typemap(python,ignore) bool *OUTPUT = bool *T_OUTPUT;
417 // %typemap(python,argout) bool *OUTPUT = bool *T_OUTPUT;
421 // %typemap(python,ignore) byte *T_OUTPUT(int temp)
423 // $target = (byte*)&temp;
426 // %typemap(python,argout) byte *T_OUTPUT
429 // o = PyInt_FromLong((long) (*$source));
430 // $target = t_output_helper($target, o);
433 // %typemap(python,ignore) byte *OUTPUT = byte *T_OUTPUT;
434 // %typemap(python,argout) byte *OUTPUT = byte *T_OUTPUT;
437 // %typemap(python,ignore) wxCoord *OUTPUT = int *OUTPUT;
438 // %typemap(python,argout) wxCoord *OUTPUT = int *OUTPUT;
441 //---------------------------------------------------------------------------
442 // Typemaps to convert return values that are base class pointers
443 // to the real derived type, if possible. See wxPyMake_wxObject in
446 %typemap(out) wxEvtHandler* { $result = wxPyMake_wxObject($1); }
447 %typemap(out) wxMenu* { $result = wxPyMake_wxObject($1); }
448 %typemap(out) wxValidator* { $result = wxPyMake_wxObject($1); }
450 %typemap(out) wxApp* { $result = wxPyMake_wxObject($1); }
451 %typemap(out) wxPyApp* { $result = wxPyMake_wxObject($1); }
452 %typemap(out) wxDC* { $result = wxPyMake_wxObject($1); }
453 %typemap(out) wxFSFile* { $result = wxPyMake_wxObject($1); }
454 %typemap(out) wxFileSystem* { $result = wxPyMake_wxObject($1); }
455 %typemap(out) wxGridTableBase* { $result = wxPyMake_wxObject($1); }
456 %typemap(out) wxImageList* { $result = wxPyMake_wxObject($1); }
457 %typemap(out) wxListItem* { $result = wxPyMake_wxObject($1); }
458 %typemap(out) wxMenuItem* { $result = wxPyMake_wxObject($1); }
459 %typemap(out) wxMouseEvent* { $result = wxPyMake_wxObject($1); }
460 %typemap(out) wxObject* { $result = wxPyMake_wxObject($1); }
461 %typemap(out) wxPyPrintout* { $result = wxPyMake_wxObject($1); }
462 %typemap(out) wxToolBarToolBase* { $result = wxPyMake_wxObject($1); }
463 %typemap(out) wxToolTip* { $result = wxPyMake_wxObject($1); }
466 %typemap(out) wxBitmapButton* { $result = wxPyMake_wxObject($1); }
467 %typemap(out) wxButton* { $result = wxPyMake_wxObject($1); }
468 %typemap(out) wxControl* { $result = wxPyMake_wxObject($1); }
469 %typemap(out) wxFrame* { $result = wxPyMake_wxObject($1); }
470 %typemap(out) wxGrid* { $result = wxPyMake_wxObject($1); }
471 %typemap(out) wxListCtrl* { $result = wxPyMake_wxObject($1); }
472 %typemap(out) wxMDIChildFrame* { $result = wxPyMake_wxObject($1); }
473 %typemap(out) wxMDIClientWindow* { $result = wxPyMake_wxObject($1); }
474 %typemap(out) wxMenuBar* { $result = wxPyMake_wxObject($1); }
475 %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1); }
476 %typemap(out) wxStaticBox* { $result = wxPyMake_wxObject($1); }
477 %typemap(out) wxStatusBar* { $result = wxPyMake_wxObject($1); }
478 %typemap(out) wxTextCtrl* { $result = wxPyMake_wxObject($1); }
479 %typemap(out) wxToolBar* { $result = wxPyMake_wxObject($1); }
480 %typemap(out) wxToolBarBase* { $result = wxPyMake_wxObject($1); }
481 %typemap(out) wxTreeCtrl* { $result = wxPyMake_wxObject($1); }
482 %typemap(out) wxWindow* { $result = wxPyMake_wxObject($1); }
483 %typemap(out) wxHtmlWindow* { $result = wxPyMake_wxObject($1); }
484 %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1); }
485 %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1); }
487 %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1); }
490 //%typemap(python, out) wxHtmlCell* { $target = wxPyMake_wxObject($source); }
491 //%typemap(python, out) wxHtmlContainerCell* { $target = wxPyMake_wxObject($source); }
492 //%typemap(python, out) wxHtmlParser* { $target = wxPyMake_wxObject($source); }
493 //%typemap(python, out) wxHtmlWinParser* { $target = wxPyMake_wxObject($source); }
495 //---------------------------------------------------------------------------
496 //---------------------------------------------------------------------------