PythonScripting.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : PythonScripting.h
00003     Project              : QtiPlot
00004 --------------------------------------------------------------------
00005     Copyright            : (C) 2006 by Knut Franke
00006     Email (use @ for *)  : knut.franke*gmx.de
00007     Description          : Execute Python code from within QtiPlot
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
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;      // PyDict of global environment
00100         PyObject *math;     // PyDict of math functions
00101         PyObject *sys;      // PyDict of sys module
00102 };
00103 
00104 #endif

Generated on Mon Oct 15 06:11:42 2007 for QtiPlot by  doxygen 1.5.3