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 Python's thread macros
 
  18     wxPy_BEGIN_ALLOW_THREADS;
 
  20     wxPy_END_ALLOW_THREADS;
 
  23 //----------------------------------------------------------------------
 
  24 // LCOUNT and choices go together.  They allow a single Python list to be
 
  25 // converted to an integer count and an array count items long.
 
  27 %typemap(python,build) int LCOUNT {
 
  29         $target = PyList_Size(_in_choices);
 
  38 %typemap(python,in) byte* choices  {
 
  39     $target = byte_LIST_helper($source);
 
  40     if ($target == NULL) {
 
  44 %typemap(python,freearg) byte* choices {
 
  48 // wxDash is a signed char
 
  49 %typemap(python,in) wxDash* choices  {
 
  50     $target = (wxDash*)byte_LIST_helper($source);
 
  51     if ($target == NULL) {
 
  55 %typemap(python,freearg) wxDash* choices {
 
  60 %typemap(python,in) int* choices  {
 
  61     $target = int_LIST_helper($source);
 
  62     if ($target == NULL) {
 
  66 %typemap(python,freearg) int* choices {
 
  71 %typemap(python,in) long* choices {
 
  72     $target = long_LIST_helper($source);
 
  73     if ($target == NULL) {
 
  77 %typemap(python,freearg) long* choices {
 
  82 %typemap(python,in) unsigned long* choices {
 
  83     $target = (unsigned long*)long_LIST_helper($source);
 
  84     if ($target == NULL) {
 
  88 %typemap(python,freearg) unsigned long* choices {
 
  93 %typemap(python,in) char** choices {
 
  94     $target = string_LIST_helper($source);
 
  95     if ($target == NULL) {
 
  99 %typemap(python,freearg) char** choices {
 
 104 %typemap(python,in) wxBitmap** choices  {
 
 105     $target = wxBitmap_LIST_helper($source);
 
 106     if ($target == NULL) {
 
 110 %typemap(python,freearg) wxBitmap** choices {
 
 114 %typemap(python,in) wxString* choices  {
 
 115     $target = wxString_LIST_helper($source);
 
 116     if ($target == NULL) {
 
 120 %typemap(python,freearg) wxString* choices {
 
 124 %typemap(python,in) wxAcceleratorEntry* choices  {
 
 125     $target = wxAcceleratorEntry_LIST_helper($source);
 
 126     if ($target == NULL) {
 
 130 %typemap(python,freearg) wxAcceleratorEntry* choices {
 
 138 %typemap(python,build) int PCOUNT {
 
 140         $target = PyList_Size(_in_points);
 
 147 %typemap(python,in) wxPoint* points  {
 
 148     $target = wxPoint_LIST_helper($source);
 
 149     if ($target == NULL) {
 
 153 %typemap(python,freearg) wxPoint* points {
 
 159 //---------------------------------------------------------------------------
 
 162 static char* wxStringErrorMsg = "string type is required for parameter";
 
 165 // TODO:  Which works best???
 
 168 //  %typemap(python, in) wxString& (PyObject* temp, int tmpDoDecRef) {
 
 171 //  #if PYTHON_API_VERSION >= 1009
 
 172 //      if (PyUnicode_Check(temp) {
 
 173 //          temp = PyUnicode_AsUTF8String(temp);
 
 175 //              PyErr_SetString(PyExc_TypeError, "Unicode encoding to UTF8 failed.");
 
 180 //      if (!PyString_Check(temp)) {
 
 181 //          PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
 
 184 //      $target = new wxString(PyString_AsString(temp), PyString_Size(temp));
 
 185 //  #if PYTHON_API_VERESION >= 1009
 
 186 //      if (tmpDoDecRef) Py_DECREF(temp);
 
 192 %typemap(python, in) wxString& {
 
 193 #if PYTHON_API_VERSION >= 1009
 
 194     char* tmpPtr; int tmpSize;
 
 195     if (!PyString_Check($source) && !PyUnicode_Check($source)) {
 
 196         PyErr_SetString(PyExc_TypeError, "String or Unicode type required");
 
 199     if (PyString_AsStringAndSize($source, &tmpPtr, &tmpSize) == -1)
 
 201     $target = new wxString(tmpPtr, tmpSize);
 
 203     if (!PyString_Check($source)) {
 
 204         PyErr_SetString(PyExc_TypeError, wxStringErrorMsg);
 
 207     $target = new wxString(PyString_AS_STRING($source), PyString_GET_SIZE($source));
 
 214 %typemap(python, freearg) wxString& {
 
 221 %typemap(python, out) wxString {
 
 222     $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
 
 224 %typemap(python, ret) wxString {
 
 229 %typemap(python, out) wxString* {
 
 230     $target = PyString_FromStringAndSize($source->c_str(), $source->Len());
 
 237 //---------------------------------------------------------------------------
 
 238 // Typemaps to convert Python sequence objects (2-tuples, etc.) to
 
 239 // wxSize, wxPoint, wxRealPoint, and wxRect.
 
 241 %typemap(python,in) wxSize& (wxSize temp) {
 
 243     if (! wxSize_helper($source, &$target))
 
 247 %typemap(python,in) wxPoint& (wxPoint temp) {
 
 249     if (! wxPoint_helper($source, &$target))
 
 253 %typemap(python,in) wxRealPoint& (wxRealPoint temp) {
 
 255     if (! wxRealPoint_helper($source, &$target))
 
 259 %typemap(python,in) wxRect& (wxRect temp) {
 
 261     if (! wxRect_helper($source, &$target))
 
 265 //---------------------------------------------------------------------------
 
 266 // Typemap to convert strings to wxColour.  Two string formats are accepted,
 
 267 // either a colour name, or a hex colour spec like "#RRGGBB"
 
 269 %typemap(python,in) wxColour& (wxColour temp) {
 
 271     if (! wxColour_helper($source, &$target))
 
 276 //---------------------------------------------------------------------------
 
 277 // Map T_OUTPUTs for floats to return ints.
 
 280 %typemap(python,ignore) float          *T_OUTPUT_TOINT(float temp),
 
 281                         double         *T_OUTPUT_TOINT(double temp)
 
 287 %typemap(python,argout) float          *T_OUTPUT_TOINT,
 
 288                         double         *T_OUTPUT_TOINT
 
 291     o = PyInt_FromLong((long) (*$source));
 
 292     $target = t_output_helper($target, o);
 
 295 //---------------------------------------------------------------------------
 
 296 //---------------------------------------------------------------------------