Panda3D
pythonCallbackObject.h
1 // Filename: pythonCallbackObject.h
2 // Created by: drose (13Mar09)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PYTHONCALLBACKOBJECT_H
16 #define PYTHONCALLBACKOBJECT_H
17 
18 #include "pandabase.h"
19 
20 #ifdef HAVE_PYTHON
21 
22 #include "py_panda.h"
23 #include "callbackObject.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : PythonCallbackObject
27 // Description : This is a specialization on CallbackObject to allow
28 // a callback to directly call an arbitarary Python
29 // function. Powerful! But use with caution.
30 ////////////////////////////////////////////////////////////////////
31 class PythonCallbackObject : public CallbackObject {
32 PUBLISHED:
33  PythonCallbackObject(PyObject *function = Py_None);
34  virtual ~PythonCallbackObject();
35  ALLOC_DELETED_CHAIN(PythonCallbackObject);
36 
37  void set_function(PyObject *function);
38  PyObject *get_function();
39 
40 public:
41  virtual void do_callback(CallbackData *cbdata);
42 
43 private:
44  void do_python_callback(CallbackData *cbdata);
45 
46  PyObject *_function;
47 
48 public:
49  static TypeHandle get_class_type() {
50  return _type_handle;
51  }
52  static void init_type() {
53  CallbackObject::init_type();
54  register_type(_type_handle, "PythonCallbackObject",
55  CallbackObject::get_class_type());
56  }
57  virtual TypeHandle get_type() const {
58  return get_class_type();
59  }
60  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
61 
62 private:
63  static TypeHandle _type_handle;
64 };
65 
66 #include "pythonCallbackObject.I"
67 
68 #endif // HAVE_PYTHON
69 
70 #endif
This is a generic data block that is passed along to a CallbackObject when a callback is made...
Definition: callbackData.h:32
virtual void do_callback(CallbackData *cbdata)
This method called when the callback is triggered; it replaces* the original function.
This is a generic object that can be assigned to a callback at various points in the rendering proces...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85