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 "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;      // PyDict of global environment
00099         PyObject *math;     // PyDict of math functions
00100         PyObject *sys;      // PyDict of sys module
00101 };
00102 
00103 #endif

Generated on Sun Jun 15 21:32:19 2008 for QtiPlot by  doxygen 1.5.6