-// #ifdef WXP_WITH_THREAD
-// PyEval_RestoreThread(wxPyEventThreadState);
-// wxPyInEvent = true;
-// #endif
-// evtobj = wxPyConstructObject((void*)&evt, "wxCommandEvent");
-// menuobj = wxPyConstructObject((void*)&menu, "wxMenu");
-// if (PyErr_Occurred()) {
-// // bail out if a problem
-// PyErr_Print();
-// goto done;
-// }
-// // Now call the callback...
-// func = ((wxPyMenu*)&menu)->func;
-// args = PyTuple_New(2);
-// PyTuple_SET_ITEM(args, 0, menuobj);
-// PyTuple_SET_ITEM(args, 1, evtobj);
-// res = PyEval_CallObject(func, args);
-// Py_DECREF(args);
-// Py_XDECREF(res); /* In case res is a NULL pointer */
-// done:
-// #ifdef WXP_WITH_THREAD
-// PyEval_SaveThread();
-// wxPyInEvent = false;
-// #endif
-// return;
-// }
+bool wxPyCallbackHelper::findCallback(const wxString& name) {
+ m_lastFound = NULL;
+ if (m_self && PyObject_HasAttrString(m_self, (char*)name.c_str()))
+ m_lastFound = PyObject_GetAttrString(m_self, (char*)name.c_str());
+
+ return m_lastFound != NULL;
+}
+
+
+int wxPyCallbackHelper::callCallback(PyObject* argTuple) {
+ PyObject* result;
+ int retval = FALSE;
+
+ result = callCallbackObj(argTuple);
+ if (result) { // Assumes an integer return type...
+ retval = PyInt_AsLong(result);
+ Py_DECREF(result);
+ PyErr_Clear(); // forget about it if it's not...
+ }
+ return retval;
+}
+
+// Invoke the Python callable object, returning the raw PyObject return
+// value. Caller should DECREF the return value and also call PyEval_SaveThread.
+PyObject* wxPyCallbackHelper::callCallbackObj(PyObject* argTuple) {
+ PyObject* result;
+
+ result = PyEval_CallObject(m_lastFound, argTuple);
+ Py_DECREF(argTuple);
+ if (!result) {
+ PyErr_Print();
+ }
+ return result;
+}
+