X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..bcb276d2ae57c512ad0dfe7a924efd9577235bca:/wxPython/src/helpers.h?ds=sidebyside diff --git a/wxPython/src/helpers.h b/wxPython/src/helpers.h index 38dd0cddc6..5030715b3e 100644 --- a/wxPython/src/helpers.h +++ b/wxPython/src/helpers.h @@ -67,7 +67,9 @@ PyObject* __wxSetDictionary(PyObject*, PyObject* args); void wxPyEventThunker(wxObject*, wxEvent& event); -HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, const char* className); +HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, + const char* className, + int setThisOwn=0); HELPEREXPORT bool wxPyRestoreThread(); HELPEREXPORT void wxPySaveThread(bool doSave); HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, const char* className); @@ -86,6 +88,44 @@ public: PyObject* m_obj; }; +//---------------------------------------------------------------------- +// Handle wxInputStreams by Joerg Baumann +// See stream.i for implementations + +// list class for return list of strings, e.g. readlines() +WX_DECLARE_LIST(wxString, wxStringPtrList); + + +// C++ class wxPyInputStream to act as base for python class wxInputStream +// Use it in python like a python file object +class wxPyInputStream{ +public: + // underlying wxInputStream + wxInputStream* wxi; + +public: + wxPyInputStream(wxInputStream* wxi_) : wxi(wxi_) {} + ~wxPyInputStream(); + + // python file object interface for input files (most of it) + void close(); + void flush(); + bool eof(); + wxString* read(int size=-1); + wxString* readline(int size=-1); + wxStringPtrList* readlines(int sizehint=-1); + void seek(int offset, int whence=0); + int tell(); + /* + bool isatty(); + int fileno(); + void truncate(int size=-1); + void write(wxString data); + void writelines(wxStringPtrList); + */ +}; + + //---------------------------------------------------------------------- // These are helpers used by the typemaps @@ -239,7 +279,7 @@ public: void _setSelf(PyObject* self, PyObject* _class, int incref=1) { \ m_myInst.setSelf(self, _class, incref); \ } \ - private: wxPyCallbackHelper m_myInst; + private: wxPyCallbackHelper m_myInst //--------------------------------------------------------------------------- @@ -285,6 +325,26 @@ public: //--------------------------------------------------------------------------- +#define DEC_PYCALLBACK_VOID_INTINT(CBNAME) \ + void CBNAME(int a, int b); \ + void base_##CBNAME(int a, int b); + + +#define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \ + void CLASS::CBNAME(int a, int b) { \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) \ + m_myInst.callCallback(Py_BuildValue("(ii)",a,b)); \ + else \ + PCLASS::CBNAME(a,b); \ + wxPySaveThread(doSave); \ + } \ + void CLASS::base_##CBNAME(int a, int b) { \ + PCLASS::CBNAME(a,b); \ + } + +//--------------------------------------------------------------------------- + #define DEC_PYCALLBACK_BOOL_INT(CBNAME) \ bool CBNAME(int a); \ bool base_##CBNAME(int a); @@ -672,6 +732,63 @@ public: //--------------------------------------------------------------------------- +#define DEC_PYCALLBACK_BOOL_STRING_pure(CBNAME) \ + bool CBNAME(const wxString& a); + \ +#define IMP_PYCALLBACK_BOOL_STRING_pure(CLASS, PCLASS, CBNAME) \ + bool CLASS::CBNAME(const wxString& a) { \ + bool rval; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) \ + rval = m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \ + wxPySaveThread(doSave); \ + return rval; \ + } \ + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_STRING_STRING_pure(CBNAME) \ + wxString CBNAME(const wxString& a); \ + +#define IMP_PYCALLBACK_STRING_STRING_pure(CLASS, PCLASS, CBNAME) \ + wxString CLASS::CBNAME(const wxString& a) { \ + wxString rval; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) { \ + PyObject* ro; \ + ro = m_myInst.callCallbackObj(Py_BuildValue("(s)", a.c_str())); \ + if (ro) { \ + rval = PyString_AsString(PyObject_Str(ro)); \ + Py_DECREF(ro); \ + } \ + } \ + wxPySaveThread(doSave); \ + return rval; \ + } \ + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_STRING_STRINGINT_pure(CBNAME) \ + wxString CBNAME(const wxString& a,int b); \ + +#define IMP_PYCALLBACK_STRING_STRINGINT_pure(CLASS, PCLASS, CBNAME) \ + wxString CLASS::CBNAME(const wxString& a,int b) { \ + wxString rval; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) { \ + PyObject* ro; \ + ro = m_myInst.callCallbackObj(Py_BuildValue("(si)", a.c_str(),b)); \ + if (ro) { \ + rval = PyString_AsString(PyObject_Str(ro)); \ + Py_DECREF(ro); \ + } \ + } \ + wxPySaveThread(doSave); \ + return rval; \ + } \ + +//--------------------------------------------------------------------------- + #define DEC_PYCALLBACK_BOOL_STRINGSTRING(CBNAME) \ bool CBNAME(const wxString& a, const wxString& b); \ bool base_##CBNAME(const wxString& a, const wxString& b); @@ -867,6 +984,28 @@ public: //--------------------------------------------------------------------------- +#define DEC_PYCALLBACK_FSF_FSSTRING_pure(CBNAME) \ + wxFSFile* CBNAME(wxFileSystem& fs, const wxString& location); \ + +#define IMP_PYCALLBACK_FSF_FSSTRING_pure(CLASS, PCLASS, CBNAME) \ + wxFSFile* CLASS::CBNAME(wxFileSystem& a,const wxString& b) { \ + bool doSave = wxPyRestoreThread(); \ + wxFSFile* rval=0; \ + if (m_myInst.findCallback(#CBNAME)) { \ + PyObject* ro; \ + ro=m_myInst.callCallbackObj(Py_BuildValue("(Os)", \ + wxPyConstructObject(&a, "(wxFileSystemC"),b.c_str())); \ + if (ro) { \ + SWIG_GetPtrObj(ro, (void **)&rval, "_wxFSFILE_p"); \ + Py_DECREF(ro); \ + } \ + } \ + wxPySaveThread(doSave); \ + return rval; \ + }; + +//--------------------------------------------------------------------------- + #define DEC_PYCALLBACK_BOOL_DR(CBNAME) \ bool CBNAME(wxDragResult a); \ bool base_##CBNAME(wxDragResult a);