Panda3D
|
00001 // Filename: pythonCallbackObject.h 00002 // Created by: drose (13Mar09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef PYTHONCALLBACKOBJECT_H 00016 #define PYTHONCALLBACKOBJECT_H 00017 00018 #include "pandabase.h" 00019 00020 #ifdef HAVE_PYTHON 00021 00022 #include "callbackObject.h" 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Class : PythonCallbackObject 00026 // Description : This is a specialization on CallbackObject to allow 00027 // a callback to directly call an arbitarary Python 00028 // function. Powerful! But use with caution. 00029 //////////////////////////////////////////////////////////////////// 00030 class EXPCL_PANDA_PUTIL PythonCallbackObject : public CallbackObject { 00031 PUBLISHED: 00032 PythonCallbackObject(PyObject *function = Py_None); 00033 virtual ~PythonCallbackObject(); 00034 ALLOC_DELETED_CHAIN(PythonCallbackObject); 00035 00036 void set_function(PyObject *function); 00037 PyObject *get_function(); 00038 00039 public: 00040 virtual void do_callback(CallbackData *cbdata); 00041 00042 private: 00043 void do_python_callback(CallbackData *cbdata); 00044 00045 PyObject *_function; 00046 00047 public: 00048 static TypeHandle get_class_type() { 00049 return _type_handle; 00050 } 00051 static void init_type() { 00052 CallbackObject::init_type(); 00053 register_type(_type_handle, "PythonCallbackObject", 00054 CallbackObject::get_class_type()); 00055 } 00056 virtual TypeHandle get_type() const { 00057 return get_class_type(); 00058 } 00059 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00060 00061 private: 00062 static TypeHandle _type_handle; 00063 }; 00064 00065 #include "pythonCallbackObject.I" 00066 00067 #endif // HAVE_PYTHON 00068 00069 #endif