X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b7c75283f2144469e8fa6a24ca285b42fab69a6b..ad3fca675f77c2903cafd096bbda8baa2e7689ff:/wxPython/src/my_typemaps.i diff --git a/wxPython/src/my_typemaps.i b/wxPython/src/my_typemaps.i index c1a37dfc22..f1bfc3cd7d 100644 --- a/wxPython/src/my_typemaps.i +++ b/wxPython/src/my_typemaps.i @@ -11,17 +11,6 @@ ///////////////////////////////////////////////////////////////////////////// -//--------------------------------------------------------------------------- -// Tell SWIG to wrap all the wrappers with our thread protection - -%exception { - PyThreadState* __tstate = wxPyBeginAllowThreads(); - $action - wxPyEndAllowThreads(__tstate); - if (PyErr_Occurred()) SWIG_fail; -} - - //---------------------------------------------------------------------- // Typemaps to convert a list of items to an int (size) and an array @@ -103,6 +92,7 @@ $1 = new wxMemoryBuffer(len); temp = True; memcpy($1->GetData(), str, len); + $1->SetDataLen(len); } %typemap(freearg) wxMemoryBuffer& { @@ -197,6 +187,7 @@ %#else PyObject* str = PyObject_Str(item); %#endif + if (PyErr_Occurred()) SWIG_fail; $1->Add(Py2wxString(str)); Py_DECREF(item); Py_DECREF(str); @@ -268,7 +259,65 @@ //--------------------------------------------------------------------------- -%typemap(out) bool "$result = PyBool_FromLong((bool)$1);" +%typemap(out) bool { + $result = $1 ? Py_True : Py_False; Py_INCREF($result); +} + + +// These fragments are iserted in modules that need to convert PyObjects to +// integer values, my versions allow any numeric type to be used, as long as +// it can be converted to a PyInt. (Specifically, I allow floats where the +// default SWIG_AsLong would raise an obsucre exception from within +// PyLong_AsLong.) + +%fragment("SWIG_AsLong","header") %{ +SWIGSTATICINLINE(long) +SWIG_AsLong(PyObject * obj) +{ + if (PyNumber_Check(obj)) + return PyInt_AsLong(obj); + else { + PyObject* errmsg = PyString_FromFormat("Expected number, got %s", + obj->ob_type->tp_name); + PyErr_SetObject(PyExc_TypeError, errmsg); + Py_DECREF(errmsg); + return 0; + } +} +%} + +%fragment("SWIG_AsUnsignedLong","header", fragment="SWIG_AsLong") %{ +SWIGSTATICINLINE(unsigned long) +SWIG_AsUnsignedLong(PyObject * obj) +{ + if (PyLong_Check(obj)) { + return PyLong_AsUnsignedLong(obj); + } else { + long i = SWIG_AsLong(obj); + if ( !PyErr_Occurred() && (i < 0)) { + PyErr_SetString(PyExc_TypeError, "negative value received for unsigned type"); + } + return i; + } +} +%} + + +%fragment("SWIG_AsDouble","header") %{ +SWIGSTATICINLINE(double) +SWIG_AsDouble(PyObject *obj) +{ + if (PyNumber_Check(obj)) + return PyFloat_AsDouble(obj); + else { + PyObject* errmsg = PyString_FromFormat("Expected number, got %s", + obj->ob_type->tp_name); + PyErr_SetObject(PyExc_TypeError, errmsg); + Py_DECREF(errmsg); + return 0; + } +} +%} //--------------------------------------------------------------------------- @@ -332,6 +381,8 @@ %typemap(out) wxHtmlWindow* { $result = wxPyMake_wxObject($1); } %typemap(out) wxPyHtmlWindow* { $result = wxPyMake_wxObject($1); } %typemap(out) wxWizardPage* { $result = wxPyMake_wxObject($1); } +%typemap(out) wxPanel* { $result = wxPyMake_wxObject($1); } +%typemap(out) wxDialog* { $result = wxPyMake_wxObject($1); } %typemap(out) wxSizer* { $result = wxPyMake_wxSizer($1); }