25Configure(config_pythonCallbackObject);
26ConfigureFn(config_pythonCallbackObject) {
27 PythonCallbackObject::init_type();
31extern struct Dtool_PyTypedObject Dtool_TypedObject;
38PythonCallbackObject(PyObject *function) {
42 set_function(function);
44#if !defined(SIMPLE_THREADS) && defined(WITH_THREAD)
47#if PY_VERSION_HEX >= 0x03020000
51#if PY_VERSION_HEX < 0x03090000
62~PythonCallbackObject() {
65#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
66 PyGILState_STATE gstate;
67 gstate = PyGILState_Ensure();
72#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
73 PyGILState_Release(gstate);
81void PythonCallbackObject::
82set_function(PyObject *function) {
86 if (_function != Py_None && !PyCallable_Check(_function)) {
87 nassert_raise(
"Invalid function passed to PythonCallbackObject");
94PyObject *PythonCallbackObject::
105void PythonCallbackObject::
107#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
109 PyGILState_STATE gstate;
110 gstate = PyGILState_Ensure();
113 do_python_callback(cbdata);
115#if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
116 PyGILState_Release(gstate);
124void PythonCallbackObject::
126 nassertv(cbdata !=
nullptr);
131 DTool_CreatePyInstanceTyped(cbdata, Dtool_TypedObject,
133 PyObject *args = Py_BuildValue(
"(O)", pycbdata);
136 PyObject *result = PythonThread::call_python_func(_function, args);
139 if (result ==
nullptr) {
140 if (PyErr_Occurred() != PyExc_SystemExit) {
142 <<
"Exception occurred in " << *
this <<
"\n";
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a generic data block that is passed along to a CallbackObject when a callback is made.
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 ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.