00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2014 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 00020 00021 #ifndef PYTHON_INTERPRETER_WORKER_HH 00022 #define PYTHON_INTERPRETER_WORKER_HH 00023 00024 // workaround for QTBUG-22829: https://bugreports.qt-project.org/browse/QTBUG-22829 00025 #ifndef Q_MOC_RUN 00026 #include <boost/python.hpp> 00027 #include <boost/shared_ptr.hpp> 00028 #endif 00029 #include "output_redirector.hh" 00030 #include <csignal> 00031 #include <utility> 00032 #include <QObject> 00033 #include <QQueue> 00034 00035 namespace ost { namespace gui { 00036 namespace bp = boost::python; 00037 00038 class PythonInterpreterWorker: public QObject 00039 { 00040 Q_OBJECT 00041 public: 00042 PythonInterpreterWorker(); 00043 ~PythonInterpreterWorker(); 00044 unsigned int AddCommand(const QString& command); 00045 00046 signals: 00047 void Finished(unsigned int id, bool error_state); 00048 void Output(unsigned int id,const QString& output); 00049 void ErrorOutput(unsigned int id,const QString& output); 00050 00051 public slots: 00052 void Wake(); 00053 00054 protected slots: 00055 void handle_redirector_output(const QString& output); 00056 void handle_redirector_error(const QString& output); 00057 00058 protected: 00059 bool is_simple_expression(const QString& expr); 00060 void run_command_(std::pair<unsigned int,QString> pair); 00061 bool is_simple_expression_(const QString& expr); 00062 QQueue<std::pair<unsigned int,QString> > exec_queue_; 00063 unsigned int command_id_; 00064 boost::shared_ptr<OutputRedirector> output_redirector_; 00065 boost::shared_ptr<OutputRedirector> error_redirector_; 00066 #ifndef _MSC_VER 00067 struct sigaction sig_act_; 00068 #endif 00069 bp::object parse_expr_cmd_; 00070 bp::object repr_; 00071 bp::dict main_namespace_; 00072 unsigned int current_id_; 00073 bool awake_; 00074 }; 00075 00076 }} //ns 00077 00078 #endif // PYTHON_INTERPRETER_WORKER_HH