Only initialize wxWidgets once
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28928 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -378,58 +378,67 @@ void wxPyApp::SetMacHelpMenuTitleName(const wxString& val) {
|
|||||||
// that should be present in the derived (Python) class.
|
// that should be present in the derived (Python) class.
|
||||||
void wxPyApp::_BootstrapApp()
|
void wxPyApp::_BootstrapApp()
|
||||||
{
|
{
|
||||||
bool result;
|
static bool haveInitialized = false;
|
||||||
|
bool result, blocked;
|
||||||
PyObject* retval = NULL;
|
PyObject* retval = NULL;
|
||||||
PyObject* pyint = NULL;
|
PyObject* pyint = NULL;
|
||||||
|
|
||||||
|
|
||||||
// Get any command-line args passed to this program from the sys module
|
// Only initialize wxWidgets once
|
||||||
int argc = 0;
|
if (! haveInitialized) {
|
||||||
char** argv = NULL;
|
|
||||||
bool blocked = wxPyBeginBlockThreads();
|
// Get any command-line args passed to this program from the sys module
|
||||||
PyObject* sysargv = PySys_GetObject("argv");
|
int argc = 0;
|
||||||
if (sysargv != NULL) {
|
char** argv = NULL;
|
||||||
argc = PyList_Size(sysargv);
|
blocked = wxPyBeginBlockThreads();
|
||||||
argv = new char*[argc+1];
|
PyObject* sysargv = PySys_GetObject("argv");
|
||||||
int x;
|
if (sysargv != NULL) {
|
||||||
for(x=0; x<argc; x++) {
|
argc = PyList_Size(sysargv);
|
||||||
PyObject *pyArg = PyList_GetItem(sysargv, x);
|
argv = new char*[argc+1];
|
||||||
argv[x] = PyString_AsString(pyArg);
|
int x;
|
||||||
|
for(x=0; x<argc; x++) {
|
||||||
|
PyObject *pyArg = PyList_GetItem(sysargv, x);
|
||||||
|
argv[x] = PyString_AsString(pyArg);
|
||||||
|
}
|
||||||
|
argv[argc] = NULL;
|
||||||
}
|
}
|
||||||
argv[argc] = NULL;
|
wxPyEndBlockThreads(blocked);
|
||||||
}
|
|
||||||
wxPyEndBlockThreads(blocked);
|
|
||||||
|
|
||||||
// Initialize wxWidgets
|
// Initialize wxWidgets
|
||||||
result = wxEntryStart(argc, argv);
|
result = wxEntryStart(argc, argv);
|
||||||
delete [] argv;
|
delete [] argv;
|
||||||
|
|
||||||
blocked = wxPyBeginBlockThreads();
|
blocked = wxPyBeginBlockThreads();
|
||||||
if (! result) {
|
if (! result) {
|
||||||
PyErr_SetString(PyExc_SystemError,
|
PyErr_SetString(PyExc_SystemError,
|
||||||
"wxEntryStart failed, unable to initialize wxWidgets!"
|
"wxEntryStart failed, unable to initialize wxWidgets!"
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
" (Is DISPLAY set properly?)"
|
" (Is DISPLAY set properly?)"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On wxGTK the locale will be changed to match the system settings, but
|
// On wxGTK the locale will be changed to match the system settings, but
|
||||||
// Python needs to have LC_NUMERIC set to "C" in order for the floating
|
// Python needs to have LC_NUMERIC set to "C" in order for the floating
|
||||||
// point conversions and such to work right.
|
// point conversions and such to work right.
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
setlocale(LC_NUMERIC, "C");
|
setlocale(LC_NUMERIC, "C");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// The stock objects were all NULL when they were loaded into
|
// The stock objects were all NULL when they were loaded into
|
||||||
// SWIG generated proxies, so re-init those now...
|
// SWIG generated proxies, so re-init those now...
|
||||||
wxPy_ReinitStockObjects(3);
|
wxPy_ReinitStockObjects(3);
|
||||||
|
|
||||||
|
wxPyEndBlockThreads(blocked);
|
||||||
|
haveInitialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
// It's now ok to generate exceptions for assertion errors.
|
// It's now ok to generate exceptions for assertion errors.
|
||||||
wxPythonApp->SetStartupComplete(True);
|
wxPythonApp->SetStartupComplete(True);
|
||||||
|
|
||||||
// Call the Python wxApp's OnInit function
|
// Call the Python wxApp's OnInit function
|
||||||
|
blocked = wxPyBeginBlockThreads();
|
||||||
if (wxPyCBH_findCallback(m_myInst, "OnInit")) {
|
if (wxPyCBH_findCallback(m_myInst, "OnInit")) {
|
||||||
|
|
||||||
PyObject* method = m_myInst.GetLastFound();
|
PyObject* method = m_myInst.GetLastFound();
|
||||||
|
Reference in New Issue
Block a user