X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8af26133d9906216890eecf33fd47186d9e5b76d..b01fb5c34046e6595d1a02e099fd70aab3ed52ed:/wxPython/src/helpers.cpp diff --git a/wxPython/src/helpers.cpp b/wxPython/src/helpers.cpp index 9c4cb6ecda..7b29004df3 100644 --- a/wxPython/src/helpers.cpp +++ b/wxPython/src/helpers.cpp @@ -287,14 +287,16 @@ PyObject* wxPyClassExists(const char* className) { } -PyObject* wxPyMake_wxObject(wxObject* source) { +PyObject* wxPyMake_wxObject(wxObject* source, bool checkEvtHandler) { PyObject* target = NULL; bool isEvtHandler = FALSE; if (source) { // If it's derived from wxEvtHandler then there may - // already be a pointer to a Python objec that we can use. - if (wxIsKindOf(source, wxEvtHandler)) { + // already be a pointer to a Python object that we can use + // in the OOR data. + if (checkEvtHandler && wxIsKindOf(source, wxEvtHandler)) { + isEvtHandler = TRUE; wxEvtHandler* eh = (wxEvtHandler*)source; wxPyClientData* data = (wxPyClientData*)eh->GetClientObject(); if (data) { @@ -302,15 +304,6 @@ PyObject* wxPyMake_wxObject(wxObject* source) { Py_INCREF(target); } } - else if (wxIsKindOf(source, wxSizer)) { - // wxSizers also track the original object - wxSizer* sz = (wxSizer*)source; - wxPyClientData* data = (wxPyClientData*)sz->GetClientObject(); - if (data) { - target = data->m_obj; - Py_INCREF(target); - } - } if (! target) { // Otherwise make it the old fashioned way by making a @@ -341,6 +334,30 @@ PyObject* wxPyMake_wxObject(wxObject* source) { } +PyObject* wxPyMake_wxSizer(wxSizer* source) { + PyObject* target = NULL; + + if (source && wxIsKindOf(source, wxSizer)) { + // If it's derived from wxSizer then there may + // already be a pointer to a Python object that we can use + // in the OOR data. + wxSizer* sz = (wxSizer*)source; + wxPyClientData* data = (wxPyClientData*)sz->GetClientObject(); + if (data) { + target = data->m_obj; + Py_INCREF(target); + } + } + if (! target) { + target = wxPyMake_wxObject(source, FALSE); + if (target != Py_None) + ((wxSizer*)source)->SetClientObject(new wxPyClientData(target)); + } + return target; +} + + + //--------------------------------------------------------------------------- PyObject* wxPyConstructObject(void* ptr, @@ -385,8 +402,10 @@ PyObject* wxPyConstructObject(void* ptr, } char buff[64]; // should always be big enough... - sprintf(buff, "%sPtr", className); + + wxASSERT_MSG(wxPython_dict, "wxPython_dict is not set yet!!"); + PyObject* classobj = PyDict_GetItemString(wxPython_dict, buff); if (! classobj) { char temp[128];