00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef PYTHON_SCRIPTING_H
00030 #define PYTHON_SCRIPTING_H
00031
00032 #include "ScriptingEnv.h"
00033 #include "PythonScript.h"
00034
00035 class QObject;
00036 class QString;
00037
00038 typedef struct _object PyObject;
00039
00040 class PythonScripting: public ScriptingEnv
00041 {
00042 Q_OBJECT
00043
00044 public:
00045 static const char *langName;
00046 PythonScripting(ApplicationWindow *parent);
00047 ~PythonScripting();
00048 static ScriptingEnv *constructor(ApplicationWindow *parent) { return new PythonScripting(parent); }
00049 bool initialize();
00050
00051 void write(const QString &text) { emit print(text); }
00052
00054
00058 QString toString(PyObject *object, bool decref=false);
00060
00066 PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
00068
00074 bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
00075 QString errorMsg();
00076
00077 bool isRunning() const;
00078 Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
00079 {
00080 return new PythonScript(this, code, context, name);
00081 }
00082
00083 bool setQObject(QObject*, const char*, PyObject *dict);
00084 bool setQObject(QObject *val, const char *name) { return setQObject(val,name,NULL); }
00085 bool setInt(int, const char*, PyObject *dict=NULL);
00086 bool setDouble(double, const char*, PyObject *dict=NULL);
00087
00088 const QStringList mathFunctions() const;
00089 const QString mathFunctionDoc (const QString &name) const;
00090 const QStringList fileExtensions() const;
00091
00092 PyObject *globalDict() { return globals; }
00093 PyObject *sysDict() { return sys; }
00094
00095 private:
00096 bool loadInitFile(const QString &path);
00097
00098 PyObject *globals;
00099 PyObject *math;
00100 PyObject *sys;
00101 };
00102
00103 #endif