PythonScripting.h
Go to the documentation of this file.
/***************************************************************************
File : PythonScripting.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_SCRIPTING_H
#define PYTHON_SCRIPTING_H
#include "ScriptingEnv.h"
#include "PythonScript.h"
class QObject;
class QString;
typedef struct _object PyObject;
class PythonScripting: public ScriptingEnv
{
Q_OBJECT
public:
static const char *langName;
PythonScripting(ApplicationWindow *parent);
~PythonScripting();
static ScriptingEnv *constructor(ApplicationWindow *parent) { return new PythonScripting(parent); }
bool initialize();
void write(const QString &text) { emit print(text); }
QString toString(PyObject *object, bool decref=false);
PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>");
QString errorMsg();
bool isRunning() const;
Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
{
return new PythonScript(this, code, context, name);
}
bool setQObject(QObject*, const char*, PyObject *dict);
bool setQObject(QObject *val, const char *name) { return setQObject(val,name,NULL); }
bool setInt(int, const char*, PyObject *dict=NULL);
bool setDouble(double, const char*, PyObject *dict=NULL);
const QStringList mathFunctions() const;
const QString mathFunctionDoc (const QString &name) const;
const QStringList fileExtensions() const;
PyObject *globalDict() { return globals; }
PyObject *sysDict() { return sys; }
private:
bool loadInitFile(const QString &path);
PyObject *globals; // PyDict of global environment
PyObject *math; // PyDict of math functions
PyObject *sys; // PyDict of sys module
};
#endif
PythonScript.h
PythonScripting::eval
PyObject * eval(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>")
evaluate a Python expression
Definition: PythonScripting.cpp:84
PythonScripting::langName
static const char * langName
Definition: PythonScripting.h:45
PythonScripting::exec
bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<qtiplot>")
execute a sequence of Python statements
Definition: PythonScripting.cpp:103
PythonScripting::~PythonScripting
~PythonScripting()
Definition: PythonScripting.cpp:287
PythonScripting::setQObject
bool setQObject(QObject *, const char *, PyObject *dict)
Definition: PythonScripting.cpp:357
PythonScripting::initialize
bool initialize()
Part of the initialization is deferred from the constructor until after the signals have been connect...
Definition: PythonScripting.cpp:265
PythonScripting::constructor
static ScriptingEnv * constructor(ApplicationWindow *parent)
Definition: PythonScripting.h:48
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:50
ScriptingEnv.h
PythonScripting::math
PyObject * math
Definition: PythonScripting.h:99
PythonScript
Definition: PythonScript.h:41
PythonScripting::sysDict
PyObject * sysDict()
Definition: PythonScripting.h:93
PythonScripting::isRunning
bool isRunning() const
whether asynchronuous execution is enabled (if supported by the implementation)
Definition: PythonScripting.cpp:349
Script
A chunk of scripting code. Abstract.
Definition: Script.h:50
PythonScripting::sys
PyObject * sys
Definition: PythonScripting.h:100
PythonScripting::errorMsg
QString errorMsg()
Definition: PythonScripting.cpp:124
ApplicationWindow
QtiPlot&#39;s main window.
Definition: ApplicationWindow.h:133
PythonScripting::fileExtensions
const QStringList fileExtensions() const
Return a list of file extensions commonly used for this language.
Definition: PythonScripting.cpp:442
PyObject
struct _object PyObject
Definition: PythonScript.h:37
PythonScripting::setInt
bool setInt(int, const char *, PyObject *dict=NULL)
Definition: PythonScripting.cpp:380
PythonScripting::loadInitFile
bool loadInitFile(const QString &path)
Definition: PythonScripting.cpp:296
ScriptingEnv::decref
void decref()
Decrease the reference count. This should only be called by scripted and Script to avoid segfaults...
Definition: ScriptingEnv.cpp:64
PythonScripting::setQObject
bool setQObject(QObject *val, const char *name)
Definition: PythonScripting.h:84
ScriptingEnv::print
void print(const QString &output)
output that is not handled by a Script
PythonScripting::PythonScripting
PythonScripting(ApplicationWindow *parent)
Definition: PythonScripting.cpp:183
PythonScripting::mathFunctions
const QStringList mathFunctions() const
Return a list of supported mathematical functions. These should be imported into the global namespace...
Definition: PythonScripting.cpp:410
PythonScripting::write
void write(const QString &text)
Definition: PythonScripting.h:51
PythonScripting::globalDict
PyObject * globalDict()
Definition: PythonScripting.h:92
PythonScripting::toString
QString toString(PyObject *object, bool decref=false)
like str(object) in Python
Definition: PythonScripting.cpp:66
PythonScripting
Definition: PythonScripting.h:40
PythonScripting::newScript
Script * newScript(const QString &code, QObject *context, const QString &name="<input>")
Instantiate the Script subclass matching the ScriptEnv subclass.
Definition: PythonScripting.h:78
PythonScripting::globals
PyObject * globals
Definition: PythonScripting.h:98
PythonScripting::setDouble
bool setDouble(double, const char *, PyObject *dict=NULL)
Definition: PythonScripting.cpp:395
PythonScripting::mathFunctionDoc
const QString mathFunctionDoc(const QString &name) const
Return a documentation string for the given mathematical function.
Definition: PythonScripting.cpp:428