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 "Script.h"
00034 #include "PythonScript.h"
00035
00036 #include <qobject.h>
00037 #include <qstring.h>
00038
00039 typedef struct _object PyObject;
00040
00041 class PythonScripting: public ScriptingEnv
00042 {
00043 Q_OBJECT
00044
00045 public:
00046 static const char *langName;
00047 PythonScripting(ApplicationWindow *parent);
00048 ~PythonScripting();
00049 static ScriptingEnv *constructor(ApplicationWindow *parent) { return new PythonScripting(parent); }
00050 bool initialize();
00051
00052 void write(const QString &text) { emit print(text); }
00053
00055
00059 QString toString(PyObject *object, bool decref=false);
00061
00067 PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
00069
00075 bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
00076 QString errorMsg();
00077
00078 bool isRunning() const;
00079 Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
00080 {
00081 return new PythonScript(this, code, context, name);
00082 }
00083
00084 bool setQObject(QObject*, const char*, PyObject *dict);
00085 bool setQObject(QObject *val, const char *name) { return setQObject(val,name,NULL); }
00086 bool setInt(int, const char*, PyObject *dict=NULL);
00087 bool setDouble(double, const char*, PyObject *dict=NULL);
00088
00089 const QStringList mathFunctions() const;
00090 const QString mathFunctionDoc (const QString &name) const;
00091 const QStringList fileExtensions() const;
00092
00093 PyObject *globalDict() { return globals; }
00094 PyObject *sysDict() { return sys; }
00095
00096 private:
00097 bool loadInitFile(const QString &path);
00098
00099 PyObject *globals;
00100 PyObject *math;
00101 PyObject *sys;
00102 };
00103
00104 #endif