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 #if !defined(SIMPLE_THREADS) && defined(WITH_THREAD)
47 #if PY_VERSION_HEX >= 0x03020000
51 #if PY_VERSION_HEX < 0x03090000
61 PythonCallbackObject::
62 ~PythonCallbackObject() {
70 void PythonCallbackObject::
71 set_function(PyObject *
function) {
75 if (_function != Py_None && !PyCallable_Check(_function)) {
76 nassert_raise(
"Invalid function passed to PythonCallbackObject");
83 PyObject *PythonCallbackObject::
94 void PythonCallbackObject::
96 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
98 PyGILState_STATE gstate;
99 gstate = PyGILState_Ensure();
102 do_python_callback(cbdata);
104 #if defined(HAVE_THREADS) && !defined(SIMPLE_THREADS)
105 PyGILState_Release(gstate);
113 void PythonCallbackObject::
115 nassertv(cbdata !=
nullptr);
120 DTool_CreatePyInstanceTyped(cbdata, Dtool_TypedObject,
122 PyObject *args = Py_BuildValue(
"(O)", pycbdata);
125 PyObject *result = PythonThread::call_python_func(_function, args);
128 if (result ==
nullptr) {
129 if (PyErr_Occurred() != PyExc_SystemExit) {
131 <<
"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.