Merged modifications from the 2.6 branch

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36607 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2005-12-30 23:02:03 +00:00
parent a780a8dc19
commit 02b800ce7c
104 changed files with 14102 additions and 46560 deletions

View File

@@ -701,21 +701,6 @@ PyObject* __wxPySetDictionary(PyObject* /* self */, PyObject* args)
}
//---------------------------------------------------------------------------
// Python's PyInstance_Check does not return True for instances of new-style
// classes. This should get close enough for both new and old classes but I
// should re-evaluate the need for doing instance checks...
bool wxPyInstance_Check(PyObject* obj) {
return PyObject_HasAttrString(obj, "__class__") != 0;
}
// This one checks if the object is an instance of a SWIG proxy class (it has
// a .this attribute)
bool wxPySwigInstance_Check(PyObject* obj) {
return PyObject_HasAttrString(obj, "this") != 0;
}
//---------------------------------------------------------------------------
@@ -2725,6 +2710,145 @@ PyObject* wxArrayInt2PyList_helper(const wxArrayInt& arr) {
}
//----------------------------------------------------------------------
// wxPyImageHandler methods
//
// TODO: Switch these to use wxPython's standard macros and helper classes
// for calling callbacks.
PyObject* wxPyImageHandler::m_DoCanRead_Name = NULL;
PyObject* wxPyImageHandler::m_GetImageCount_Name = NULL;
PyObject* wxPyImageHandler::m_LoadFile_Name = NULL;
PyObject* wxPyImageHandler::m_SaveFile_Name = NULL;
PyObject* wxPyImageHandler::py_InputStream(wxInputStream* stream) {
return wxPyConstructObject(new wxPyInputStream(stream),
wxT("wxPyInputStream"), 0);
}
PyObject* wxPyImageHandler::py_Image(wxImage* image) {
return wxPyConstructObject(image, wxT("wxImage"), 0);
}
PyObject* wxPyImageHandler::py_OutputStream(wxOutputStream* stream) {
return wxPyConstructObject(stream, wxT("wxOutputStream"), 0);
}
wxPyImageHandler::wxPyImageHandler():
m_self(NULL)
{
if (!m_DoCanRead_Name) {
m_DoCanRead_Name = PyString_FromString("DoCanRead");
m_GetImageCount_Name = PyString_FromString("GetImageCount");
m_LoadFile_Name = PyString_FromString("LoadFile");
m_SaveFile_Name = PyString_FromString("SaveFile");
}
}
wxPyImageHandler::~wxPyImageHandler() {
if (m_self) {
Py_DECREF(m_self);
m_self = NULL;
}
}
void wxPyImageHandler::_SetSelf(PyObject *self) {
// should check here for isinstance(PyImageHandler) ??
m_self = self;
Py_INCREF(m_self);
}
bool wxPyImageHandler::DoCanRead(wxInputStream& stream) {
// check if our object has this method
wxPyBlock_t blocked = wxPyBeginBlockThreads();
if (!m_self || !PyObject_HasAttr(m_self, m_DoCanRead_Name)) {
wxPyEndBlockThreads(blocked);
return false;
}
PyObject* res = PyObject_CallMethodObjArgs(m_self, m_DoCanRead_Name,
py_InputStream(&stream), NULL);
bool retval = false;
if (res) {
retval = PyInt_AsLong(res);
Py_DECREF(res);
PyErr_Clear();
}
else
PyErr_Print();
wxPyEndBlockThreads(blocked);
return retval;
}
bool wxPyImageHandler::LoadFile( wxImage* image, wxInputStream& stream,
bool verbose, int index ) {
// check if our object has this method
wxPyBlock_t blocked = wxPyBeginBlockThreads();
if (!m_self || !PyObject_HasAttr(m_self, m_LoadFile_Name)) {
wxPyEndBlockThreads(blocked);
return false;
}
PyObject* res = PyObject_CallMethodObjArgs(m_self, m_LoadFile_Name,
py_Image(image),
py_InputStream(&stream),
PyInt_FromLong(verbose),
PyInt_FromLong(index),
NULL);
bool retval = false;
if (res) {
retval = PyInt_AsLong(res);
Py_DECREF(res);
PyErr_Clear();
} else
PyErr_Print();
wxPyEndBlockThreads(blocked);
return retval;
}
bool wxPyImageHandler::SaveFile( wxImage* image, wxOutputStream& stream,
bool verbose ) {
wxPyBlock_t blocked = wxPyBeginBlockThreads();
if (!m_self || !PyObject_HasAttr(m_self, m_SaveFile_Name)) {
wxPyEndBlockThreads(blocked);
return false;
}
PyObject* res = PyObject_CallMethodObjArgs(m_self, m_SaveFile_Name,
py_Image(image),
py_OutputStream(&stream),
PyInt_FromLong(verbose),
NULL);
bool retval = false;
if(res) {
retval=PyInt_AsLong(res);
Py_DECREF(res);
PyErr_Clear();
} else
PyErr_Print();
wxPyEndBlockThreads(blocked);
return retval;
}
int wxPyImageHandler::GetImageCount( wxInputStream& stream ) {
wxPyBlock_t blocked = wxPyBeginBlockThreads();
if (!m_self || !PyObject_HasAttr(m_self, m_GetImageCount_Name)) {
wxPyEndBlockThreads(blocked);
return 1;
}
PyObject *res=PyObject_CallMethodObjArgs(m_self, m_GetImageCount_Name,
py_InputStream(&stream),
NULL);
int retval = 1;
if(res) {
retval=PyInt_AsLong(res);
Py_DECREF(res);
PyErr_Clear();
} else
PyErr_Print();
wxPyEndBlockThreads(blocked);
return retval;
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------