+bool wxPyApp::OnInitGui() {
+ bool rval=True;
+ wxApp::OnInitGui(); // in this case always call the base class version
+ wxPyBeginBlockThreads();
+ if (wxPyCBH_findCallback(m_myInst, "OnInitGui"))
+ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
+ wxPyEndBlockThreads();
+ return rval;
+}
+
+
+int wxPyApp::OnExit() {
+ int rval=0;
+ wxPyBeginBlockThreads();
+ if (wxPyCBH_findCallback(m_myInst, "OnExit"))
+ rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()"));
+ wxPyEndBlockThreads();
+ wxApp::OnExit(); // in this case always call the base class version
+ return rval;
+}
+
+
+#ifdef __WXDEBUG__
+void wxPyApp::OnAssert(const wxChar *file,
+ int line,
+ const wxChar *cond,
+ const wxChar *msg) {
+
+ // if we're not fully initialized then just log the error
+ if (! m_startupComplete) {
+ wxString buf;
+ buf.Alloc(4096);
+ buf.Printf(wxT("%s(%d): assert \"%s\" failed"),
+ file, line, cond);
+ if (msg != NULL) {
+ buf += wxT(": ");
+ buf += msg;
+ }
+ wxLogDebug(buf);
+ return;
+ }
+
+ // If the OnAssert is overloaded in the Python class then call it...
+ bool found;
+ wxPyBeginBlockThreads();
+ if ((found = wxPyCBH_findCallback(m_myInst, "OnAssert"))) {
+ PyObject* fso = wx2PyString(file);
+ PyObject* cso = wx2PyString(file);
+ PyObject* mso;
+ if (msg != NULL)
+ mso = wx2PyString(file);
+ else {
+ mso = Py_None; Py_INCREF(Py_None);
+ }
+ wxPyCBH_callCallback(m_myInst, Py_BuildValue("(OiOO)", fso, line, cso, mso));
+ Py_DECREF(fso);
+ Py_DECREF(cso);
+ Py_DECREF(mso);
+ }
+ wxPyEndBlockThreads();
+
+ // ...otherwise do our own thing with it
+ if (! found) {
+ // ignore it?
+ if (m_assertMode & wxPYAPP_ASSERT_SUPPRESS)
+ return;
+
+ // turn it into a Python exception?
+ if (m_assertMode & wxPYAPP_ASSERT_EXCEPTION) {
+ wxString buf;
+ buf.Alloc(4096);
+ buf.Printf(wxT("C++ assertion \"%s\" failed in %s(%d)"), cond, file, line);
+ if (msg != NULL) {
+ buf += wxT(": ");
+ buf += msg;
+ }
+
+ // set the exception
+ wxPyBeginBlockThreads();
+ PyObject* s = wx2PyString(buf);
+ PyErr_SetObject(wxPyAssertionError, s);
+ Py_DECREF(s);
+ wxPyEndBlockThreads();
+
+ // Now when control returns to whatever API wrapper was called from
+ // Python it should detect that an exception is set and will return
+ // NULL, signalling the exception to Python.
+ }
+
+ // Send it to the normal log destination, but only if
+ // not _DIALOG because it will call this too
+ if ( (m_assertMode & wxPYAPP_ASSERT_LOG) && !(m_assertMode & wxPYAPP_ASSERT_DIALOG)) {
+ wxString buf;
+ buf.Alloc(4096);
+ buf.Printf(wxT("%s(%d): assert \"%s\" failed"),
+ file, line, cond);
+ if (msg != NULL) {
+ buf += wxT(": ");
+ buf += msg;
+ }
+ wxLogDebug(buf);
+ }
+
+ // do the normal wx assert dialog?
+ if (m_assertMode & wxPYAPP_ASSERT_DIALOG)
+ wxApp::OnAssert(file, line, cond, msg);
+ }
+}
+#endif
+
+
+
+/*static*/
+bool wxPyApp::GetMacSupportPCMenuShortcuts() {
+#ifdef __WXMAC__
+ return s_macSupportPCMenuShortcuts;
+#else
+ return 0;
+#endif
+}
+
+/*static*/
+long wxPyApp::GetMacAboutMenuItemId() {
+#ifdef __WXMAC__
+ return s_macAboutMenuItemId;
+#else
+ return 0;
+#endif
+}
+
+/*static*/
+long wxPyApp::GetMacPreferencesMenuItemId() {
+#ifdef __WXMAC__
+ return s_macPreferencesMenuItemId;
+#else
+ return 0;
+#endif
+}
+
+/*static*/
+long wxPyApp::GetMacExitMenuItemId() {
+#ifdef __WXMAC__
+ return s_macExitMenuItemId;
+#else
+ return 0;
+#endif
+}
+
+/*static*/
+wxString wxPyApp::GetMacHelpMenuTitleName() {
+#ifdef __WXMAC__
+ return s_macHelpMenuTitleName;
+#else
+ return wxEmptyString;
+#endif
+}
+
+/*static*/
+void wxPyApp::SetMacSupportPCMenuShortcuts(bool val) {
+#ifdef __WXMAC__
+ s_macSupportPCMenuShortcuts = val;
+#endif
+}
+
+/*static*/
+void wxPyApp::SetMacAboutMenuItemId(long val) {
+#ifdef __WXMAC__
+ s_macAboutMenuItemId = val;
+#endif
+}
+
+/*static*/
+void wxPyApp::SetMacPreferencesMenuItemId(long val) {
+#ifdef __WXMAC__
+ s_macPreferencesMenuItemId = val;
+#endif
+}
+
+/*static*/
+void wxPyApp::SetMacExitMenuItemId(long val) {
+#ifdef __WXMAC__
+ s_macExitMenuItemId = val;
+#endif
+}
+
+/*static*/
+void wxPyApp::SetMacHelpMenuTitleName(const wxString& val) {
+#ifdef __WXMAC__
+ s_macHelpMenuTitleName = val;
+#endif
+}
+
+
+// This finishes the initialization of wxWindows and then calls the OnInit
+// that should be present in the derived (Python) class.
+void wxPyApp::_BootstrapApp()
+{
+ bool result;
+ PyObject* retval = NULL;
+ PyObject* pyint = NULL;
+
+
+ // Get any command-line args passed to this program from the sys module
+ int argc = 0;
+ char** argv = NULL;
+ wxPyBeginBlockThreads();
+ PyObject* sysargv = PySys_GetObject("argv");
+ if (sysargv != NULL) {
+ argc = PyList_Size(sysargv);
+ argv = new char*[argc+1];
+ int x;
+ for(x=0; x<argc; x++) {
+ PyObject *pyArg = PyList_GetItem(sysargv, x);
+ argv[x] = PyString_AsString(pyArg);
+ }
+ argv[argc] = NULL;
+ }
+ wxPyEndBlockThreads();
+
+ result = wxEntryStart(argc, argv);
+ delete [] argv;
+
+ wxPyBeginBlockThreads();
+ if (! result) {
+ PyErr_SetString(PyExc_SystemError, "wxEntryStart failed!");
+ goto error;
+ }
+
+ // The stock objects were all NULL when they were loaded into
+ // SWIG generated proxies, so re-init those now...
+ wxPy_ReinitStockObjects(False);
+
+ // It's now ok to generate exceptions for assertion errors.
+ wxPythonApp->SetStartupComplete(True);
+
+ // Call the Python wxApp's OnInit function
+ 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();
+};