SciDAVis  1.D4
PythonScripting.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : PythonScripting.h
3  Project : SciDAVis
4 --------------------------------------------------------------------
5  Copyright : (C) 2006 by Knut Franke
6  Email (use @ for *) : knut.franke*gmx.de
7  Description : Execute Python code from within SciDAVis
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_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;
48  static ScriptingEnv *constructor(ApplicationWindow *parent) { return new PythonScripting(parent); }
49  bool initialize();
50 
51  void write(const QString &text) { emit print(text); }
52 
54 
58  QString toString(PyObject *object, bool decref=false);
60 
66  PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>");
68 
74  bool exec(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>");
75  QString errorMsg();
76 
77  bool isRunning() const;
78  Script *newScript(const QString &code, QObject *context, const QString &name="<input>")
79  {
80  return new PythonScript(this, code, context, name);
81  }
82 
83  bool setQObject(QObject*, const char*, PyObject *dict);
84  bool setQObject(QObject *val, const char *name) { return setQObject(val,name,NULL); }
85  bool setInt(int, const char*, PyObject *dict=NULL);
86  bool setDouble(double, const char*, PyObject *dict=NULL);
87 
88  const QStringList mathFunctions() const;
89  const QString mathFunctionDoc (const QString &name) const;
90  const QStringList fileExtensions() const;
91 
92  PyObject *globalDict() { return globals; }
93  PyObject *sysDict() { return sys; }
94 
95  private:
96  bool loadInitFile(const QString &path);
97 
98  PyObject *globals; // PyDict of global environment
99  PyObject *math; // PyDict of math functions
100  PyObject *sys; // PyDict of sys module
101 };
102 
103 #endif