Add code to reinitialize the wxModules into an API function

This commit is contained in:
Robin Dunn
2017-06-08 17:00:19 -07:00
parent 324b6ff0b5
commit e5bf8ac1fe
2 changed files with 24 additions and 1 deletions

View File

@@ -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

View File

@@ -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