diff --git a/src/wxpy_api.h b/src/wxpy_api.h index d5f5e2b7..bb7846f8 100644 --- a/src/wxpy_api.h +++ b/src/wxpy_api.h @@ -165,6 +165,7 @@ struct wxPyAPI { bool (*p_wxPyNumberSequenceCheck)(PyObject* obj, int reqLength); void* (*p_wxPyGetCppPtr)(sipSimpleWrapper* sipPyObj); PyObject* (*p_wxPyMethod_Self)(PyObject* method); + void (*p_wxPyReinitializeModules)(); // Always add new items here at the end. }; @@ -265,6 +266,11 @@ inline PyObject* wxPyMethod_Self(PyObject* method) { return wxPyGetAPIPtr()->p_wxPyMethod_Self(method); } +inline void wxPyReinitializeModules() + { return wxPyGetAPIPtr()->p_wxPyReinitializeModules(); } + + + //-------------------------------------------------------------------------- // Convenience helper for RAII-style thread blocking diff --git a/src/wxpy_api.sip b/src/wxpy_api.sip index 9865183e..f2da5599 100644 --- a/src/wxpy_api.sip +++ b/src/wxpy_api.sip @@ -528,6 +528,22 @@ inline PyObject* i_wxPyMethod_Self(PyObject* method) { } + +//-------------------------------------------------------------------------- +// Cleanup and reinitialize the wxModules. This is needed because sometimes an +// Extension module will first be imported *after* the wx.App has been +// created, so the wxModules in that extension will not have been registered +// and initialized because they were not yet in memory. + +void i_wxPyReinitializeModules() { + if (i_wxPyCheckForApp(false)) { + wxModule::CleanUpModules(); + wxModule::RegisterModules(); + wxModule::InitializeModules(); + } +} + + //-------------------------------------------------------------------------- // An instance of the API structure static wxPyAPI API = { @@ -546,7 +562,8 @@ static wxPyAPI API = { i_wxPyMakeBuffer, i_wxPyNumberSequenceCheck, i_wxPyGetCppPtr, - i_wxPyMethod_Self + i_wxPyMethod_Self, + i_wxPyReinitializeModules }; %End