~valavanisalex/ubuntu/maverick/scidavis/fix-604811

« back to all changes in this revision

Viewing changes to scidavis/src/PythonScripting.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
40
class PythonScripting: public ScriptingEnv
 
41
{
 
42
        Q_OBJECT
 
43
 
 
44
        public:
 
45
                static const char *langName;
 
46
                PythonScripting(ApplicationWindow *parent);
 
47
                ~PythonScripting();
 
48
                static ScriptingEnv *constructor(ApplicationWindow *parent) { return new PythonScripting(parent); }
 
49
                bool initialize();
 
50
 
 
51
                void write(const QString &text) { emit print(text); }
 
52
 
 
53
                //! like str(object) in Python
 
54
                /**
 
55
                 * Convert object to a string.
 
56
                 * Steals a reference to object if decref is true; borrows otherwise.
 
57
                 */
 
58
                QString toString(PyObject *object, bool decref=false);
 
59
                //! evaluate a Python expression
 
60
                /**
 
61
                 * Evaluates code, using argDict (borrowed reference) as local dictionary
 
62
                 * or an empty one if argDict==NULL. name is the filename Python uses when
 
63
                 * reporting errors. Returns a new reference; NULL means caller has to do
 
64
                 * exception handling.
 
65
                 */
 
66
                PyObject* eval(const QString &code, PyObject *argDict=NULL, const char *name="<scidavis>");
 
67
                //! execute a sequence of Python statements
 
68
                /**
 
69
                 * Executes code, using argDict (borrowed reference) as local dictionary
 
70
                 * or an empty one if argDict==NULL. name is the filename Python uses when
 
71
                 * reporting errors. A false return value means caller has to do exception
 
72
                 * handling.
 
73
                 */
 
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