+// This finishes the initialization of wxWindows and then calls the OnInit
+// that should be present in the derived (Python) class.
+void wxPyApp::_BootstrapApp()
+{
+ static bool haveInitialized = false;
+ bool result;
+ wxPyBlock_t blocked;
+ PyObject* retval = NULL;
+ PyObject* pyint = NULL;
+
+
+ // Only initialize wxWidgets once
+ if (! haveInitialized) {
+
+ // Get any command-line args passed to this program from the sys module
+ int argc = 0;
+ char** argv = NULL;
+ blocked = wxPyBeginBlockThreads();
+
+ PyObject* sysargv = PySys_GetObject("argv");
+ PyObject* executable = PySys_GetObject("executable");
+
+ if (sysargv != NULL && executable != NULL) {
+ argc = PyList_Size(sysargv) + 1;
+ argv = new char*[argc+1];
+ argv[0] = strdup(PyString_AsString(executable));
+ int x;
+ for(x=1; x<argc; x++) {
+ PyObject *pyArg = PyList_GetItem(sysargv, x-1);
+ argv[x] = strdup(PyString_AsString(pyArg));
+ }
+ argv[argc] = NULL;
+ }
+ wxPyEndBlockThreads(blocked);
+
+ // Initialize wxWidgets
+ result = wxEntryStart(argc, argv);
+ // wxApp takes ownership of the argv array, don't delete it here
+
+ blocked = wxPyBeginBlockThreads();
+ if (! result) {
+ PyErr_SetString(PyExc_SystemError,
+ "wxEntryStart failed, unable to initialize wxWidgets!"
+#ifdef __WXGTK__
+ " (Is DISPLAY set properly?)"
+#endif
+ );
+ goto error;
+ }
+
+ // On wxGTK the locale will be changed to match the system settings,
+ // but Python before 2.4 needs to have LC_NUMERIC set to "C" in order
+ // for the floating point conversions and such to work right.
+#if defined(__WXGTK__) && PY_VERSION_HEX < 0x02040000
+ setlocale(LC_NUMERIC, "C");
+#endif
+
+// wxSystemOptions::SetOption(wxT("mac.textcontrol-use-mlte"), 1);
+
+ // The stock objects were all NULL when they were loaded into
+ // SWIG generated proxies, so re-init those now...
+ wxPy_ReinitStockObjects(3);
+
+ wxPyEndBlockThreads(blocked);
+ haveInitialized = true;
+ }
+ else {
+ this->argc = 0;
+ this->argv = NULL;
+ }
+
+
+ // It's now ok to generate exceptions for assertion errors.
+ wxPythonApp->SetStartupComplete(true);
+
+ // Call the Python wxApp's OnInit function
+ blocked = wxPyBeginBlockThreads();
+ if (wxPyCBH_findCallback(m_myInst, "OnInit")) {
+
+ PyObject* method = m_myInst.GetLastFound();
+ PyObject* argTuple = PyTuple_New(0);
+ retval = PyEval_CallObject(method, argTuple);
+ Py_DECREF(argTuple);
+ Py_DECREF(method);
+ if (retval == NULL)
+ goto error;
+
+ pyint = PyNumber_Int(retval);
+ if (! pyint) {
+ PyErr_SetString(PyExc_TypeError, "OnInit should return a boolean value");
+ goto error;
+ }
+ result = PyInt_AS_LONG(pyint);
+ }
+ else {
+ // Is it okay if there is no OnInit? Probably so...
+ result = true;
+ }
+
+ if (! result) {
+ PyErr_SetString(PyExc_SystemExit, "OnInit returned false, exiting...");
+ }
+
+ error:
+ Py_XDECREF(retval);
+ Py_XDECREF(pyint);
+
+ wxPyEndBlockThreads(blocked);
+};