PythonScript.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : PythonScript.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_SCRIPT_H
00030 #define PYTHON_SCRIPT_H
00031 
00032 #include "Script.h"
00033 
00034 class QObject;
00035 class QString;
00036 
00037 typedef struct _object PyObject;
00038 class PythonScripting;
00039 class ScriptingEnv;
00040 
00041 class PythonScript : public Script
00042 {
00043     Q_OBJECT
00044 
00045     public:
00046         PythonScript(PythonScripting *env, const QString &code, QObject *context=0, const QString &name="<input>");
00047         ~PythonScript();
00048 
00049         void write(const QString &text) { emit print(text); }
00050 
00051         public slots:
00052         bool compile(bool for_eval=true);
00053         QVariant eval();
00054         bool exec();
00055         bool setQObject(QObject *val, const char *name);
00056         bool setInt(int val, const char* name);
00057         bool setDouble(double val, const char* name);
00058         void setContext(QObject *context);
00059 
00060     private:
00061         PythonScripting *env() { return (PythonScripting*)Env; }
00062         void beginStdoutRedirect();
00063         void endStdoutRedirect();
00064 
00065         PyObject *PyCode, *localDict, *stdoutSave, *stderrSave;
00066         bool isFunction;
00067 };
00068 
00069 
00070 #endif

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