00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef FXPYTHON_H
00023
00024 #ifndef FXPYTHON_FROMBOOSTINVOKE
00025
00026 #ifndef BOOST_PYTHON_DYNAMIC_LIB
00027 #define BOOST_PYTHON_DYNAMIC_LIB
00028 #endif
00029 #ifndef BOOST_PYTHON_MAX_ARITY
00030 #define BOOST_PYTHON_MAX_ARITY 19
00031 #endif
00032 #include <boost/python.hpp>
00033 #else
00034 #define FXPYTHON_H
00035 #include "../include/FXString.h"
00036 #include "../include/FXGenericTools.h"
00037 #include "../include/FXObject.h"
00038 #include <boost/python/opaque_pointer_converter.hpp>
00039
00040 #ifdef WIN32
00041 #ifdef FOXPYTHONDLL_EXPORTS
00042 #define FXPYTHONAPI __declspec(dllexport)
00043 #else
00044 #define FXPYTHONAPI __declspec(dllimport)
00045 #endif
00046 #else
00047 #ifdef GCC_HASCLASSVISIBILITY
00048 #define FXPYTHONAPI __attribute__ ((visibility("default")))
00049 #else
00050 #define FXPYTHONAPI
00051 #endif
00052 #endif
00053 #ifndef FXPYTHONAPI
00054 #define FXPYTHONAPI
00055 #endif
00056
00057
00058 namespace FX {
00059
00064 class QThread;
00065 class FXComboBox;
00066 class FXFoldingList;
00067 class FXGLViewer;
00068 class FXIconList;
00069 class FXList;
00070 class FXListBox;
00071 class FXTreeList;
00072 class FXTreeListBox;
00073 class FXComposite;
00074
00079 class FXEXCEPTIONAPI(FXPYTHONAPI) FXPythonException : public FXException
00080 {
00081 friend class FXPython;
00082 FXPythonException() { }
00083 public:
00085 FXPythonException(const FXString &msg, FXuint flags)
00086 : FXException(0, 0, msg, FXEXCEPTION_PYTHONERROR, flags) { }
00087 };
00088 #define FXERRHPY(ret) { if((ret)<=0) FXPython::int_throwPythonException(); }
00089
00090
00108 class FXPYTHONAPI FXPython
00109 {
00110 public:
00112 static FXString interpreterPath();
00114 static FXString version();
00116 static FXString platform();
00118 static FXString programName();
00120 static void setProgramName(const FXString &name);
00125 static void setArgv(int argc, char **argv);
00127 static boost::python::handle<> globals();
00133 static boost::python::handle<> execute(const FXString &code, boost::python::handle<> context=globals());
00138 static boost::python::handle<> evaluate(const FXString &code, boost::python::handle<> context=globals());
00140 static void setFXComboBoxSortFunc(FXComboBox &list, boost::python::api::object *code);
00142 static void setFXFoldingListSortFunc(FXFoldingList &list, boost::python::api::object *code);
00144 static void setFXGLViewerSortFunc(FXGLViewer &list, boost::python::api::object *code);
00146 static void setFXIconListSortFunc(FXIconList &list, boost::python::api::object *code);
00148 static void setFXListSortFunc(FXList &list, boost::python::api::object *code);
00150 static void setFXListBoxSortFunc(FXListBox &list, boost::python::api::object *code);
00152 static void setFXTreeListSortFunc(FXTreeList &list, boost::python::api::object *code);
00154 static void setFXTreeListBoxSortFunc(FXTreeListBox &list, boost::python::api::object *code);
00155
00156 static void int_throwPythonException();
00157 static void int_initEmbeddedEnv();
00158 static void int_runPythonThread(PyObject *self, QThread *cthread);
00159 static void int_pythonObjectCreated(Generic::BoundFunctorV *detach);
00160 static void int_pythonObjectDeleted(Generic::BoundFunctorV *detach);
00161 #ifndef FX_DISABLEGUI
00162 static bool int_FXObjectHandle(long *ret, FXObject *self, FXObject *sender, FXSelector sel, void *ptr);
00163 #endif
00164 };
00165 inline PyObject *fxerrhpy(PyObject *ptr)
00166 {
00167 if(ptr<=0) FXPython::int_throwPythonException();
00168 return ptr;
00169 }
00171 inline boost::python::handle<> py(const FXString &code) { return FXPython::execute(code); }
00173 inline boost::python::handle<> pyeval(const FXString &code) { return FXPython::evaluate(code); }
00174
00286 struct FXPythonInterpPrivate;
00287 class FXPYTHONAPI FXPythonInterp
00288 {
00289 friend struct FXPythonInterpPrivate;
00290 friend class FXPython;
00291 FXPythonInterpPrivate *p;
00292 FXPythonInterp(const FXPythonInterp &);
00293 FXPythonInterp &operator=(const FXPythonInterp &);
00294 FXPythonInterp(void *ts);
00295 public:
00304 FXPythonInterp(int argc=0, char **argv=0, const char *name=0);
00305 ~FXPythonInterp();
00307 const char *name() const throw();
00309 static FXPythonInterp *current();
00311 void setContext();
00313 void unsetContext();
00314 static void int_enterCPP();
00315 static void int_exitCPP();
00316 };
00317
00326 class FXPython_CtxHold : public Generic::DoUndo<FXPythonInterp, void (FXPythonInterp::*)(), void (FXPythonInterp::*)()>
00327 {
00328 public:
00330 FXPython_CtxHold(FXPythonInterp *i=FXPythonInterp::current())
00331 : Generic::DoUndo<FXPythonInterp, void (FXPythonInterp::*)(), void (FXPythonInterp::*)()>(i, &FXPythonInterp::setContext, &FXPythonInterp::unsetContext)
00332 { }
00333 };
00334
00335 class FXPython_DoCPP : public Generic::DoUndo<void, void (*)(), void (*)()>
00336 {
00337 public:
00338 FXPython_DoCPP()
00339 : Generic::DoUndo<void, void (*)(), void (*)()>(&FXPythonInterp::int_enterCPP, &FXPythonInterp::int_exitCPP)
00340 { }
00341 };
00342
00343 class FXPython_DoPython : public Generic::DoUndo<void, void (*)(), void (*)()>
00344 {
00345 public:
00346 FXPython_DoPython()
00347 : Generic::DoUndo<void, void (*)(), void (*)()>(&FXPythonInterp::int_exitCPP, &FXPythonInterp::int_enterCPP)
00348 { }
00349 };
00350
00351
00352 }
00353
00354 #endif
00355 #endif