00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2010 by the OpenStructure authors 00005 // Copyright (C) 2003-2010 by the IPLT authors 00006 // 00007 // This library is free software; you can redistribute it and/or modify it under 00008 // the terms of the GNU Lesser General Public License as published by the Free 00009 // Software Foundation; either version 3.0 of the License, or (at your option) 00010 // any later version. 00011 // This library is distributed in the hope that it will be useful, but WITHOUT 00012 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00014 // details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with this library; if not, write to the Free Software Foundation, Inc., 00018 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 //------------------------------------------------------------------------------ 00020 00021 /* 00022 python interpreter 00023 00024 Authors: Andreas Schenk, Ansgar Philippsen, Marco Biasini 00025 */ 00026 00027 #ifndef PYTHON_INTERPRETER_HH 00028 #define PYTHON_INTERPRETER_HH 00029 00030 #include <vector> 00031 00032 #include <QQueue> 00033 #include <QMetaType> 00034 00035 00036 #include <ost/gui/module_config.hh> 00037 00038 #include <ost/gui/module_config.hh> 00039 #include "python_interpreter_worker.hh" 00040 #include "output_redirector.hh" 00041 #include "main_thread_runner.hh" 00042 00043 namespace ost { namespace gui { 00044 namespace bp = boost::python; 00045 00046 enum InterpreterStatus{ 00047 STATUS_OK, 00048 STATUS_ERROR 00049 }; 00050 00051 00052 typedef enum { 00053 CODE_BLOCK_COMPLETE=1, 00054 CODE_BLOCK_ERROR=2, 00055 CODE_BLOCK_INCOMPLETE=4 00056 } CodeBlockStatus; 00057 00058 class DLLEXPORT_OST_GUI PythonInterpreter: public QObject 00059 { 00060 Q_OBJECT 00061 public: 00062 static PythonInterpreter& Instance(); 00063 00064 ~PythonInterpreter(); 00065 bool IsRunning(); 00066 void AppendModulePath(const QString& entry); 00067 00068 void AppendCommandlineArgument(const QString& arg); 00069 00070 bp::dict GetMainNamespace() const; 00071 bp::object GetMainModule() const; 00076 CodeBlockStatus GetCodeBlockStatus(const QString& command); 00077 00078 00081 void Stop(); 00085 void Start(); 00086 00087 00088 public slots: 00090 unsigned int RunScript(const QString& script); 00091 unsigned int RunCommand(const QString& command); 00092 signals: 00093 void Output(unsigned int id,const QString& output); 00094 void ErrorOutput(unsigned int id,const QString& output); 00095 void Finished(unsigned int id, bool error_state); 00096 void Exit(); 00097 void WakeWorker(); 00098 protected: 00099 PythonInterpreter(); 00100 bp::object main_module_; 00101 bp::dict main_namespace_; 00102 bool running_; 00103 bp::object compile_command_; 00104 PythonInterpreterWorker worker_; 00105 }; 00106 00107 }} // ns 00108 00109 #endif
1.5.8