QtiPlot  0.9.8.2
PythonScript.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : PythonScript.h
3  Project : QtiPlot
4 --------------------------------------------------------------------
5  Copyright : (C) 2006 by Knut Franke
6  Email (use @ for *) : knut.franke*gmx.de
7  Description : Execute Python code from within QtiPlot
8 
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  * This program is distributed in the hope that it will be useful, *
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21  * GNU General Public License for more details. *
22  * *
23  * You should have received a copy of the GNU General Public License *
24  * along with this program; if not, write to the Free Software *
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
26  * Boston, MA 02110-1301 USA *
27  * *
28  ***************************************************************************/
29 #ifndef PYTHON_SCRIPT_H
30 #define PYTHON_SCRIPT_H
31 
32 #include "Script.h"
33 
34 class QObject;
35 class QString;
36 
37 typedef struct _object PyObject;
38 class PythonScripting;
39 class ScriptingEnv;
40 
41 class PythonScript : public Script
42 {
43  Q_OBJECT
44 
45  public:
46  PythonScript(PythonScripting *env, const QString &code, QObject *context=0, const QString &name="<input>");
47  ~PythonScript();
48 
49  void write(const QString &text) { emit print(text); }
50 
51  public slots:
52  bool compile(bool for_eval=true);
53  QVariant eval();
54  bool exec();
55  bool setQObject(QObject *val, const char *name);
56  bool setInt(int val, const char* name);
57  bool setDouble(double val, const char* name);
58  void setContext(QObject *context);
59 
60  private:
62  void beginStdoutRedirect();
63  void endStdoutRedirect();
64 
67 };
68 
69 
70 #endif
PyObject * modLocalDict
Definition: PythonScript.h:65
bool setDouble(double val, const char *name)
Definition: PythonScript.cpp:352
PythonScript(PythonScripting *env, const QString &code, QObject *context=0, const QString &name="<input>")
Definition: PythonScript.cpp:43
bool isFunction
Definition: PythonScript.h:66
ScriptingEnv * Env
Definition: Script.h:102
PyObject * PyCode
Definition: PythonScript.h:65
bool hasOldGlobals
Definition: PythonScript.h:66
bool exec()
Definition: PythonScript.cpp:278
~PythonScript()
Definition: PythonScript.cpp:80
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
const QString code() const
Return the code that will be executed when calling exec() or eval()
Definition: Script.h:61
bool compile(bool for_eval=true)
Definition: PythonScript.cpp:95
bool setInt(int val, const char *name)
Definition: PythonScript.cpp:343
Definition: PythonScript.h:41
bool setQObject(QObject *val, const char *name)
Definition: PythonScript.cpp:334
const QString name() const
Like QObject::name, but with unicode support.
Definition: Script.h:65
A chunk of scripting code. Abstract.
Definition: Script.h:50
QObject * context() const
Return the context in which the code is to be executed.
Definition: Script.h:63
void write(const QString &text)
Definition: PythonScript.h:49
QVariant eval()
Definition: PythonScript.cpp:190
struct _object PyObject
Definition: PythonScript.h:37
PythonScripting * env()
Definition: PythonScript.h:61
PyObject * stderrSave
Definition: PythonScript.h:65
PyObject * stdoutSave
Definition: PythonScript.h:65
PyObject * modGlobalDict
Definition: PythonScript.h:65
void print(const QString &output)
output generated by the code
void endStdoutRedirect()
Definition: PythonScript.cpp:324
Definition: PythonScripting.h:40
void setContext(QObject *context)
Definition: PythonScript.cpp:89
void beginStdoutRedirect()
Definition: PythonScript.cpp:312