00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 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 00031 #include "python_interpreter_worker.hh" 00032 #include "output_redirector.hh" 00033 #include "main_thread_runner.hh" 00034 #include <ost/gui/module_config.hh> 00035 00036 #include <QQueue> 00037 #include <QMetaType> 00038 00039 namespace ost { namespace gui { 00040 namespace bp = boost::python; 00041 00042 enum InterpreterStatus{ 00043 STATUS_OK, 00044 STATUS_ERROR 00045 }; 00046 00047 00048 typedef enum { 00049 CODE_BLOCK_COMPLETE=1, 00050 CODE_BLOCK_ERROR=2, 00051 CODE_BLOCK_INCOMPLETE=4 00052 } CodeBlockStatus; 00053 00054 class DLLEXPORT_OST_GUI PythonInterpreter: public QObject 00055 { 00056 Q_OBJECT 00057 public: 00058 static PythonInterpreter& Instance(); 00059 00060 ~PythonInterpreter(); 00061 bool IsRunning(); 00062 void AppendModulePath(const QString& entry); 00063 00064 void AppendCommandlineArgument(const QString& arg); 00065 00066 bp::dict GetMainNamespace() const; 00067 bp::object GetMainModule() const; 00072 CodeBlockStatus GetCodeBlockStatus(const QString& command); 00073 00074 00077 void Stop(); 00081 void Start(); 00083 void StopScript(); 00084 00085 00086 00087 public slots: 00089 unsigned int RunScript(const QString& script); 00090 unsigned int RunCommand(const QString& command); 00091 signals: 00092 void Output(unsigned int id,const QString& output); 00093 void ErrorOutput(unsigned int id,const QString& output); 00094 void Finished(unsigned int id, bool error_state); 00095 void Exit(); 00096 void WakeWorker(); 00097 protected: 00098 PythonInterpreter(); 00099 bp::object main_module_; 00100 bp::dict main_namespace_; 00101 bool running_; 00102 bp::object compile_command_; 00103 PythonInterpreterWorker worker_; 00104 }; 00105 00106 }} // ns 00107 00108 #endif