25 Configure(config_pythonCallbackObject);
26 ConfigureFn(config_pythonCallbackObject) {
27 PythonCallbackObject::init_type();
31 extern struct Dtool_PyTypedObject Dtool_TypedObject;
37 PythonCallbackObject::
38 PythonCallbackObject(PyObject *
function) {
42 set_function(
function);
44 #ifndef SIMPLE_THREADS 46 #ifdef WITH_THREAD // This symbol defined within Python.h 48 #if PY_VERSION_HEX >= 0x03020000 60 PythonCallbackObject::
61 ~PythonCallbackObject() {
69 void PythonCallbackObject::
70 set_function(PyObject *
function) {
74 if (_function != Py_None && !PyCallable_Check(_function)) {
75 nassert_raise(
"Invalid function passed to PythonCallbackObject");
82 PyObject *PythonCallbackObject::
93 void PythonCallbackObject::
95 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) 97 PyGILState_STATE gstate;
98 gstate = PyGILState_Ensure();
101 do_python_callback(cbdata);
103 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS) 104 PyGILState_Release(gstate);
112 void PythonCallbackObject::
114 nassertv(cbdata !=
nullptr);
119 DTool_CreatePyInstanceTyped(cbdata, Dtool_TypedObject,
121 PyObject *args = Py_BuildValue(
"(O)", pycbdata);
124 PyObject *result = PythonThread::call_python_func(_function, args);
127 if (result ==
nullptr) {
128 if (PyErr_Occurred() != PyExc_SystemExit) {
130 <<
"Exception occurred in " << *
this <<
"\n";
137 #endif // HAVE_PYTHON This is a generic data block that is passed along to a CallbackObject when a callback is made.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
int get_type_index() const
Returns the internal index number associated with this object's TypeHandle, a unique number for each ...