00001
00002
00008 #ifndef __CPython_h__
00009 #define __CPython_h__
00010
00011 #include <vector>
00012 using std::vector;
00013 #include <map>
00014 using std::map;
00015 #include <string>
00016 using std::string;
00017
00018 #include <Python.h>
00019
00020 #include <QWidget>
00021
00022
00023 struct module_data
00024 {
00025 PyObject * modPtr;
00026 PyObject * dict;
00027 };
00028
00029
00039 class VPythonThreadLocker
00040 {
00041 public:
00042 VPythonThreadLocker()
00043 : _state(PyGILState_Ensure())
00044 {}
00045
00046 ~VPythonThreadLocker() {
00047 PyGILState_Release(_state);
00048 }
00049
00050 private:
00051 PyGILState_STATE _state;
00052 };
00053
00054
00060 class CPython
00061 {
00062 public:
00063 CPython(vector<string> & pathvec);
00064 ~CPython();
00065
00066 static void addPath(const string & path);
00067 static void checkPyObj(const PyObject * const obj);
00068
00069 static PyObject * getModule(const string & module);
00070 static PyObject * loadModule(const string & module);
00071 static void printModules(void);
00072 static PyObject * getCurrentDict(void);
00073 static PyObject * getDict(const string & module);
00074 static void setDict(PyObject * dict);
00075 static void setDict(const string & module);
00076 static void printDict(PyObject * dict = NULL);
00077
00078 static PyObject * callFunction(PyObject *callable, PyObject *args);
00079
00080 static QWidget * createPyWidget(QWidget * parentWidget = NULL, PyObject * data = NULL);
00081
00082 private:
00083 static PyThreadState * _mainThreadState;
00085 static PyObject * pyMainDict_;
00086 static PyObject * pyDict_;
00088 static map<string, struct module_data> modules_;
00090 static void initHelperFunctions(void);
00091 };
00092
00093 #endif // __CPython_h__