PythonScript.h
Go to the documentation of this file.
/***************************************************************************
File : PythonScript.h
Project : QtiPlot
--------------------------------------------------------------------
Copyright : (C) 2006 by Knut Franke
Email (use @ for *) : knut.franke*gmx.de
Description : Execute Python code from within QtiPlot
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
***************************************************************************/
#ifndef PYTHON_SCRIPT_H
#define PYTHON_SCRIPT_H
#include "Script.h"
class QObject;
class QString;
typedef struct _object PyObject;
class PythonScripting;
class ScriptingEnv;
class PythonScript : public Script
{
Q_OBJECT
public:
PythonScript(PythonScripting *env, const QString &code, QObject *context=0, const QString &name="<input>");
~PythonScript();
void write(const QString &text) { emit print(text); }
public slots:
bool compile(bool for_eval=true);
QVariant eval();
bool exec();
bool setQObject(QObject *val, const char *name);
bool setInt(int val, const char* name);
bool setDouble(double val, const char* name);
void setContext(QObject *context);
private:
PythonScripting *env() { return (PythonScripting*)Env; }
void beginStdoutRedirect();
void endStdoutRedirect();
PyObject *PyCode, *modLocalDict, *modGlobalDict, *stdoutSave, *stderrSave;
bool isFunction, hasOldGlobals;
};
#endif
PythonScript::modLocalDict
PyObject * modLocalDict
Definition: PythonScript.h:65
PythonScript::setDouble
bool setDouble(double val, const char *name)
Definition: PythonScript.cpp:352
PythonScript::PythonScript
PythonScript(PythonScripting *env, const QString &code, QObject *context=0, const QString &name="<input>")
Definition: PythonScript.cpp:43
PythonScript::isFunction
bool isFunction
Definition: PythonScript.h:66
Script::Env
ScriptingEnv * Env
Definition: Script.h:102
PythonScript::PyCode
PyObject * PyCode
Definition: PythonScript.h:65
PythonScript::hasOldGlobals
bool hasOldGlobals
Definition: PythonScript.h:66
PythonScript::exec
bool exec()
Definition: PythonScript.cpp:278
PythonScript::~PythonScript
~PythonScript()
Definition: PythonScript.cpp:80
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
PythonScript::compile
bool compile(bool for_eval=true)
Definition: PythonScript.cpp:95
PythonScript::setInt
bool setInt(int val, const char *name)
Definition: PythonScript.cpp:343
PythonScript
Definition: PythonScript.h:41
PythonScript::setQObject
bool setQObject(QObject *val, const char *name)
Definition: PythonScript.cpp:334
Script.h
Script
A chunk of scripting code. Abstract.
Definition: Script.h:50
PythonScript::write
void write(const QString &text)
Definition: PythonScript.h:49
PythonScript::eval
QVariant eval()
Definition: PythonScript.cpp:190
PyObject
struct _object PyObject
Definition: PythonScript.h:37
PythonScript::env
PythonScripting * env()
Definition: PythonScript.h:61
PythonScript::stderrSave
PyObject * stderrSave
Definition: PythonScript.h:65
PythonScript::stdoutSave
PyObject * stdoutSave
Definition: PythonScript.h:65
PythonScript::modGlobalDict
PyObject * modGlobalDict
Definition: PythonScript.h:65
Script::context
QObject * context() const
Return the context in which the code is to be executed.
Definition: Script.h:63
Script::print
void print(const QString &output)
output generated by the code
Script::name
const QString name() const
Like QObject::name, but with unicode support.
Definition: Script.h:65
PythonScript::endStdoutRedirect
void endStdoutRedirect()
Definition: PythonScript.cpp:324
PythonScripting
Definition: PythonScripting.h:40
PythonScript::setContext
void setContext(QObject *context)
Definition: PythonScript.cpp:89
Script::code
const QString code() const
Return the code that will be executed when calling exec() or eval()
Definition: Script.h:61
PythonScript::beginStdoutRedirect
void beginStdoutRedirect()
Definition: PythonScript.cpp:312