OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
python_interpreter.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 // Copyright (C) 2003-2010 by the IPLT authors
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the Free
9 // Software Foundation; either version 3.0 of the License, or (at your option)
10 // any later version.
11 // This library is distributed in the hope that it will be useful, but WITHOUT
12 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14 // details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this library; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //------------------------------------------------------------------------------
20 
21 /*
22  python interpreter
23 
24  Authors: Andreas Schenk, Ansgar Philippsen, Marco Biasini
25 */
26 
27 #ifndef PYTHON_INTERPRETER_HH
28 #define PYTHON_INTERPRETER_HH
29 
30 
32 #include "output_redirector.hh"
33 #include "main_thread_runner.hh"
34 #include <ost/gui/module_config.hh>
35 
36 #include <QQueue>
37 #include <QMetaType>
38 
39 namespace ost { namespace gui {
40 namespace bp = boost::python;
41 
45 };
46 
47 
48 typedef enum {
53 
54 class DLLEXPORT_OST_GUI PythonInterpreter: public QObject
55 {
56  Q_OBJECT
57 public:
58  static PythonInterpreter& Instance();
59 
61  bool IsRunning();
62  void AppendModulePath(const QString& entry);
63 
64  void AppendCommandlineArgument(const QString& arg);
65 
66  bp::dict GetMainNamespace() const;
67  bp::object GetMainModule() const;
72  CodeBlockStatus GetCodeBlockStatus(const QString& command);
73 
74 
77  void Stop();
81  void Start();
83  void StopScript();
84 
85 
86 
87 public slots:
89  unsigned int RunScript(const QString& script);
90  unsigned int RunCommand(const QString& command);
91 signals:
92  void Output(unsigned int id,const QString& output);
93  void ErrorOutput(unsigned int id,const QString& output);
94  void Finished(unsigned int id, bool error_state);
95  void Exit();
96  void WakeWorker();
97 protected:
99  bp::object main_module_;
100  bp::dict main_namespace_;
101  bool running_;
102  bp::object compile_command_;
104 };
105 
106 }} // ns
107 
108 #endif
#define DLLEXPORT_OST_GUI
PythonInterpreterWorker worker_