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 #if PYTHON_API_VERSION >= 1009
 
 156     static char* wxStringErrorMsg = "String or Unicode type required";
 
 158     static char* wxStringErrorMsg = "String type required";
 
 162 // TODO:  Which works best???
 
 165 //  %typemap(python, in) wxString& (PyObject* temp, int tmpDoDecRef) {
 
 168 //  #if PYTHON_API_VERSION >= 1009
 
 169 //      if (PyUnicode_Check(temp) {
 
 170 //          temp = PyUnicode_AsUTF8String(temp);
 
 172 //              PyErr_SetString(PyExc_TypeError, "Unicode encoding to UTF8 failed.");
 
 177 //      if (!PyString_Check(temp)) {
 
 178 //          PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
 
 181 //      $target = new wxString(PyString_AsString(temp), PyString_Size(temp));
 
 182 //  #if PYTHON_API_VERESION >= 1009
 
 183 //      if (tmpDoDecRef) Py_DECREF(temp);
 
 189 %typemap(python, in) wxString& {
 
 190 #if PYTHON_API_VERSION >= 1009
 
 191     char* tmpPtr; int tmpSize;
 
 192     if (!PyString_Check($source) && !PyUnicode_Check($source)) {
 
 193         PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
 
 196     if (PyString_AsStringAndSize($source, &tmpPtr, &tmpSize) == -1)
 
 198     $target = new wxString(tmpPtr, tmpSize);
 
 200     if (!PyString_Check($source)) {
 
 201         PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
 
 204     $target = new wxString(PyString_AS_STRING($source), PyString_GET_SIZE($source));
 
 211 %typemap(python, freearg) wxString& {
 
 218 %typemap(python, out) wxString {
 
 219     $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
 
 221 %typemap(python, ret) wxString {
 
 226 %typemap(python, out) wxString* {
 
 227     $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
 
 234 //---------------------------------------------------------------------------
 
 235 // Typemaps to convert Python sequence objects (tuples, etc.) to
 
 236 // wxSize, wxPoint, wxRealPoint, and wxRect.
 
 238 %typemap(python,in) wxSize& (wxSize temp) {
 
 240     if (! wxSize_helper($source, &$target))
 
 244 %typemap(python,in) wxPoint& (wxPoint temp) {
 
 246     if (! wxPoint_helper($source, &$target))
 
 250 %typemap(python,in) wxRealPoint& (wxRealPoint temp) {
 
 252     if (! wxRealPoint_helper($source, &$target))
 
 256 %typemap(python,in) wxRect& (wxRect temp) {
 
 258     if (! wxRect_helper($source, &$target))
 
 262 //---------------------------------------------------------------------------
 
 263 // Typemap to convert strings to wxColour.  Two string formats are accepted,
 
 264 // either a colour name, or a hex colour spec like "#RRGGBB"
 
 266 %typemap(python,in) wxColour& (wxColour temp) {
 
 268     if (! wxColour_helper($source, &$target))
 
 272 //---------------------------------------------------------------------------
 
 273 // Typemap for wxArrayString from Python sequence objects
 
 275 %typemap(python,in) wxArrayString& {
 
 276     if (! PySequence_Check($source)) {
 
 277         PyErr_SetString(PyExc_TypeError, "Sequence of strings expected.");
 
 280     $target = new wxArrayString;
 
 281     int i, len=PySequence_Length($source);
 
 282     for (i=0; i<len; i++) {
 
 283         PyObject* item = PySequence_GetItem($source, i);
 
 284         PyObject* str  = PyObject_Str(item);
 
 285         $target->Add(PyString_AsString(item));
 
 291 %typemap(python, freearg) wxArrayString& {
 
 296 //---------------------------------------------------------------------------
 
 297 // Map T_OUTPUTs for floats to return ints.
 
 300 %typemap(python,ignore) float          *T_OUTPUT_TOINT(float temp),
 
 301                         double         *T_OUTPUT_TOINT(double temp)
 
 307 %typemap(python,argout) float          *T_OUTPUT_TOINT,
 
 308                         double         *T_OUTPUT_TOINT
 
 311     o = PyInt_FromLong((long) (*$source));
 
 312     $target = t_output_helper($target, o);
 
 315 //---------------------------------------------------------------------------
 
 316 // Typemaps to convert return values that are base class pointers
 
 317 // to the real derived type, if possible.  See wxPyMake_wxObject in
 
 320 %typemap(python, out) wxEvtHandler*             { $target = wxPyMake_wxObject($source); }
 
 321 %typemap(python, out) wxMenu*                   { $target = wxPyMake_wxObject($source); }
 
 322 %typemap(python, out) wxValidator*              { $target = wxPyMake_wxObject($source); }
 
 324 %typemap(python, out) wxDC*                     { $target = wxPyMake_wxObject($source); }
 
 325 %typemap(python, out) wxFSFile*                 { $target = wxPyMake_wxObject($source); }
 
 326 %typemap(python, out) wxFileSystem*             { $target = wxPyMake_wxObject($source); }
 
 327 %typemap(python, out) wxGridTableBase*          { $target = wxPyMake_wxObject($source); }
 
 328 %typemap(python, out) wxImageList*              { $target = wxPyMake_wxObject($source); }
 
 329 %typemap(python, out) wxListItem*               { $target = wxPyMake_wxObject($source); }
 
 330 %typemap(python, out) wxMenuItem*               { $target = wxPyMake_wxObject($source); }
 
 331 %typemap(python, out) wxMouseEvent*             { $target = wxPyMake_wxObject($source); }
 
 332 %typemap(python, out) wxObject*                 { $target = wxPyMake_wxObject($source); }
 
 333 %typemap(python, out) wxPyPrintout*             { $target = wxPyMake_wxObject($source); }
 
 334 %typemap(python, out) wxToolBarToolBase*        { $target = wxPyMake_wxObject($source); }
 
 335 %typemap(python, out) wxToolTip*                { $target = wxPyMake_wxObject($source); }
 
 338 %typemap(python, out) wxButton*                 { $target = wxPyMake_wxObject($source); }
 
 339 %typemap(python, out) wxControl*                { $target = wxPyMake_wxObject($source); }
 
 340 %typemap(python, out) wxFrame*                  { $target = wxPyMake_wxObject($source); }
 
 341 %typemap(python, out) wxGrid*                   { $target = wxPyMake_wxObject($source); }
 
 342 %typemap(python, out) wxMDIChildFrame*          { $target = wxPyMake_wxObject($source); }
 
 343 %typemap(python, out) wxMDIClientWindow*        { $target = wxPyMake_wxObject($source); }
 
 344 %typemap(python, out) wxMenuBar*                { $target = wxPyMake_wxObject($source); }
 
 345 %typemap(python, out) wxNotebook*               { $target = wxPyMake_wxObject($source); }
 
 346 %typemap(python, out) wxStaticBox*              { $target = wxPyMake_wxObject($source); }
 
 347 %typemap(python, out) wxStatusBar*              { $target = wxPyMake_wxObject($source); }
 
 348 %typemap(python, out) wxTextCtrl*               { $target = wxPyMake_wxObject($source); }
 
 349 %typemap(python, out) wxToolBar*                { $target = wxPyMake_wxObject($source); }
 
 350 %typemap(python, out) wxToolBarBase*            { $target = wxPyMake_wxObject($source); }
 
 351 %typemap(python, out) wxWindow*                 { $target = wxPyMake_wxObject($source); }
 
 353 %typemap(python, out) wxSizer*                  { $target = wxPyMake_wxSizer($source); }
 
 356 //%typemap(python, out) wxHtmlCell*               { $target = wxPyMake_wxObject($source); }
 
 357 //%typemap(python, out) wxHtmlContainerCell*      { $target = wxPyMake_wxObject($source); }
 
 358 //%typemap(python, out) wxHtmlParser*             { $target = wxPyMake_wxObject($source); }
 
 359 //%typemap(python, out) wxHtmlWinParser*          { $target = wxPyMake_wxObject($source); }
 
 361 //---------------------------------------------------------------------------
 
 362 //---------------------------------------------------------------------------