From 389c55270a6ae54788329dde644c12746a326f68 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Mon, 13 Sep 1999 19:28:10 +0000 Subject: [PATCH 1/1] Moved wxPy_ConvertList function from oglhelpers to helpers git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3652 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/wxPython/modules/ogl/ogl.i | 1 + utils/wxPython/modules/ogl/oglhelpers.cpp | 32 ------- utils/wxPython/modules/ogl/oglhelpers.h | 2 - utils/wxPython/src/helpers.cpp | 23 ++++- utils/wxPython/src/helpers.h | 106 ++++++++++++++++++++++ 5 files changed, 129 insertions(+), 35 deletions(-) diff --git a/utils/wxPython/modules/ogl/ogl.i b/utils/wxPython/modules/ogl/ogl.i index 6c140befb5..490067bc14 100644 --- a/utils/wxPython/modules/ogl/ogl.i +++ b/utils/wxPython/modules/ogl/ogl.i @@ -156,6 +156,7 @@ extern "C" SWIGEXPORT(void) initoglshapes2c(); extern "C" SWIGEXPORT(void) initoglcanvasc(); %} + %init %{ initoglbasicc(); diff --git a/utils/wxPython/modules/ogl/oglhelpers.cpp b/utils/wxPython/modules/ogl/oglhelpers.cpp index 6b6e7b17b9..ab2152276a 100644 --- a/utils/wxPython/modules/ogl/oglhelpers.cpp +++ b/utils/wxPython/modules/ogl/oglhelpers.cpp @@ -92,42 +92,10 @@ wxList* wxPy_wxRealPoint_ListHelper(PyObject* pyList) { //--------------------------------------------------------------------------- -// Convert a wxList to a Python List -#include -PyObject* wxPy_ConvertList(wxList* list, char* className) { - PyObject* pyList; - PyObject* pyObj; - wxObject* wxObj; - wxNode* node = list->First(); - bool doSave = wxPyRestoreThread(); - pyList = PyList_New(0); - while (node) { - wxObj = node->Data(); -// printf("%s class at %x : %x\n", wxObj->GetClassInfo()->GetClassName(), (void*)wxObj, (void*)((wxShape*)wxObj)->GetParent()); - pyObj = wxPyConstructObject(wxObj, className); - PyList_Append(pyList, pyObj); - node = node->Next(); - } -// for (int x=0; xFirst(); + + bool doSave = wxPyRestoreThread(); + pyList = PyList_New(0); + while (node) { + wxObj = node->Data(); + pyObj = wxPyConstructObject(wxObj, className); + PyList_Append(pyList, pyObj); + node = node->Next(); + } + wxPySaveThread(doSave); + return pyList; +} + //---------------------------------------------------------------------- // Some helper functions for typemaps in my_typemaps.i, so they won't be -// imcluded in every file... +// included in every file... HELPEREXPORT byte* byte_LIST_helper(PyObject* source) { diff --git a/utils/wxPython/src/helpers.h b/utils/wxPython/src/helpers.h index 54baeab6f6..92cb512e08 100644 --- a/utils/wxPython/src/helpers.h +++ b/utils/wxPython/src/helpers.h @@ -67,6 +67,7 @@ void wxPyEventThunker(wxObject*, wxEvent& event); HELPEREXPORT PyObject* wxPyConstructObject(void* ptr, char* className); HELPEREXPORT bool wxPyRestoreThread(); HELPEREXPORT void wxPySaveThread(bool doSave); +HELPEREXPORT PyObject* wxPy_ConvertList(wxListBase* list, char* className); //---------------------------------------------------------------------- @@ -574,6 +575,111 @@ private: //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK__STRING(CBNAME) \ + void CBNAME(const wxString& a); \ + void base_##CBNAME(const wxString& a); + + +#define IMP_PYCALLBACK__STRING(CLASS, PCLASS, CBNAME) \ + void CLASS::CBNAME(const wxString& a) { \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) \ + m_myInst.callCallback(Py_BuildValue("(s)", a.c_str())); \ + else \ + PCLASS::CBNAME(a); \ + wxPySaveThread(doSave); \ + } \ + void CLASS::base_##CBNAME(const wxString& a) { \ + PCLASS::CBNAME(a); \ + } + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_BOOL_STRING(CBNAME) \ + bool CBNAME(const wxString& a); \ + bool base_##CBNAME(const wxString& a); + + +#define IMP_PYCALLBACK_BOOL_STRING(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())); \ + else \ + rval = PCLASS::CBNAME(a); \ + wxPySaveThread(doSave); \ + return rval; \ + } \ + bool CLASS::base_##CBNAME(const wxString& a) { \ + return PCLASS::CBNAME(a); \ + } + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_STRING_(CBNAME) \ + wxString CBNAME(); \ + wxString base_##CBNAME(); + + +#define IMP_PYCALLBACK_STRING_(CLASS, PCLASS, CBNAME) \ + wxString CLASS::CBNAME() { \ + wxString rval; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) { \ + PyObject* ro; \ + ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \ + rval = PyString_AsString(PyObject_Str(ro)); \ + } \ + else \ + rval = PCLASS::CBNAME(a); \ + wxPySaveThread(doSave); \ + return rval; \ + } \ + bool CLASS::base_##CBNAME(const wxString& a) { \ + return PCLASS::CBNAME(a); \ + } + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_STRING__pure(CBNAME) \ + wxString CBNAME(); + + +#define IMP_PYCALLBACK_STRING__pure(CLASS, PCLASS, CBNAME) \ + wxString CLASS::CBNAME() { \ + wxString rval; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) { \ + PyObject* ro; \ + ro = m_myInst.callCallbackObj(Py_BuildValue("()")); \ + rval = PyString_AsString(PyObject_Str(ro)); \ + } \ + wxPySaveThread(doSave); \ + return rval; \ + } + +//--------------------------------------------------------------------------- + +#define DEC_PYCALLBACK_BOOL_TAG_pure(CBNAME) \ + bool CBNAME(const wxHtmlTag& a); \ + + +#define IMP_PYCALLBACK_BOOL_TAG_pure(CLASS, PCLASS, CBNAME) \ + bool CLASS::CBNAME(const wxHtmlTag& a) { \ + bool rval = false; \ + bool doSave = wxPyRestoreThread(); \ + if (m_myInst.findCallback(#CBNAME)) \ + rval = m_myInst.callCallback(Py_BuildValue("(O)", \ + wxPyConstructObject((void*)&a,"wxHtmlTag"))); \ + wxPySaveThread(doSave); \ + return rval; \ + } + +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- +//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- -- 2.45.2