scidavis  2.3.0
About: SciDAVis is a free application for Scientific Data Analysis and Visualization (a fork off of QtiPlot).
  Fossies Dox: scidavis-2.3.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

PythonScripting.h
Go to the documentation of this file.
1 
11 
29 #ifndef PYTHON_SCRIPTING_H
30 #define PYTHON_SCRIPTING_H
31 
32 #include "ScriptingEnv.h"
33 #include "PythonScript.h"
34 
35 class QObject;
36 class QString;
37 
38 typedef struct _object PyObject;
39 
41 {
42  Q_OBJECT
43 
44 public:
45  static const char *langName;
46  PythonScripting(ApplicationWindow *parent, bool batch=false);
48  static ScriptingEnv *constructor(ApplicationWindow *parent, bool batch=false) { return new PythonScripting(parent, batch); }
49  bool initialize() override;
50  void redirectStdIO() override;
51 
52  void write(const QString &text) { emit print(text); }
53 
55 
59  QString toString(PyObject *object, bool decref=false);
61 
67  PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>");
69 
75  bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>");
76  QString errorMsg();
77 
78  bool isRunning() const override;
79  Script *newScript(const QString &code, QObject *context, const QString &name="<input>") override
80  {
81  return new PythonScript(this, code, context, name);
82  }
83 
84  bool setQObject(QObject*, const char*, PyObject *dict);
85  bool setQObject(QObject *val, const char *name) override { return setQObject(val,name,NULL); }
86  bool setInt(int i, const char* s) override {return setInt(i,s,nullptr);}
87  bool setInt(int, const char*, PyObject *dict);
88  bool setDouble(double x, const char* s) override {return setDouble(x,s,nullptr);}
89  bool setDouble(double, const char*, PyObject *dict);
90 
91  const QStringList mathFunctions() const override;
92  const QString mathFunctionDoc (const QString &name) const override;
93  const QStringList fileExtensions() const override;
94 
95  PyObject *globalDict() { return globals; }
96  PyObject *sysDict() { return sys; }
97 
98 private:
99  bool loadInitFile(const QString &path);
100 
101  PyObject *globals; // PyDict of global environment
102  PyObject *math; // PyDict of math functions
103  PyObject *sys; // PyDict of sys module
104 };
105 
106 #endif
PythonScripting::math
PyObject * math
Definition: PythonScripting.h:102
PythonScripting::exec
bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>")
execute a sequence of Python statements
Definition: PythonScripting.cpp:117
ScriptingEnv.h
PythonScripting::setQObject
bool setQObject(QObject *, const char *, PyObject *dict)
Definition: PythonScripting.cpp:388
PythonScripting::eval
PyObject * eval(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>")
evaluate a Python expression
Definition: PythonScripting.cpp:100
PythonScripting::setQObject
bool setQObject(QObject *val, const char *name) override
Definition: PythonScripting.h:85
PythonScripting::setInt
bool setInt(int i, const char *s) override
Definition: PythonScripting.h:86
PythonScripting::toString
QString toString(PyObject *object, bool decref=false)
like str(object) in Python
Definition: PythonScripting.cpp:88
PythonScripting::fileExtensions
const QStringList fileExtensions() const override
Return a list of file extensions commonly used for this language.
Definition: PythonScripting.cpp:462
PythonScripting::globals
PyObject * globals
Definition: PythonScripting.h:101
ScriptingEnv::decref
void decref()
Decrease the reference count. This should only be called by scripted and Script to avoid segfaults.
Definition: ScriptingEnv.cpp:65
PythonScripting::initialize
bool initialize() override
Part of the initialization is deferred from the constructor until after the signals have been connect...
Definition: PythonScripting.cpp:292
PythonScripting::isRunning
bool isRunning() const override
whether asynchronuous execution is enabled (if supported by the implementation)
Definition: PythonScripting.cpp:383
PythonScripting::mathFunctions
const QStringList mathFunctions() const override
Return a list of supported mathematical functions. These should be imported into the global namespace...
Definition: PythonScripting.cpp:436
PythonScript
Definition: PythonScript.h:42
PythonScripting::globalDict
PyObject * globalDict()
Definition: PythonScripting.h:95
PythonScripting::write
void write(const QString &text)
Definition: PythonScripting.h:52
PythonScripting::langName
static const char * langName
Definition: PythonScripting.h:45
PythonScripting::errorMsg
QString errorMsg()
Definition: PythonScripting.cpp:136
PythonScripting::setDouble
bool setDouble(double x, const char *s) override
Definition: PythonScripting.h:88
PythonScripting::PythonScripting
PythonScripting(ApplicationWindow *parent, bool batch=false)
Definition: PythonScripting.cpp:190
PythonScripting::loadInitFile
bool loadInitFile(const QString &path)
Definition: PythonScripting.cpp:331
PythonScript.h
ScriptingEnv
An interpreter for evaluating scripting code. Abstract.
Definition: ScriptingEnv.h:53
PythonScripting::constructor
static ScriptingEnv * constructor(ApplicationWindow *parent, bool batch=false)
Definition: PythonScripting.h:48
ApplicationWindow
SciDAVis's main window.
Definition: ApplicationWindow.h:122
Script
A chunk of scripting code. Abstract.
Definition: Script.h:53
ScriptingEnv::print
void print(const QString &output)
output that is not handled by a Script
PythonScripting::newScript
Script * newScript(const QString &code, QObject *context, const QString &name="<input>") override
Instantiate the Script subclass matching the ScriptEnv subclass.
Definition: PythonScripting.h:79
name
char * name()
Definition: exp_saturation.c:45
PythonScripting::redirectStdIO
void redirectStdIO() override
Definition: PythonScripting.cpp:283
PythonScripting::~PythonScripting
~PythonScripting()
Definition: PythonScripting.cpp:320
PythonScripting::sys
PyObject * sys
Definition: PythonScripting.h:103
PythonScripting::mathFunctionDoc
const QString mathFunctionDoc(const QString &name) const override
Return a documentation string for the given mathematical function.
Definition: PythonScripting.cpp:452
PythonScripting
Definition: PythonScripting.h:41
PythonScripting::sysDict
PyObject * sysDict()
Definition: PythonScripting.h:96
PyObject
struct _object PyObject
Definition: PythonScript.h:37