OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
python_interpreter_worker.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-2014 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 
21 #ifndef PYTHON_INTERPRETER_WORKER_HH
22 #define PYTHON_INTERPRETER_WORKER_HH
23 
24 // workaround for QTBUG-22829: https://bugreports.qt-project.org/browse/QTBUG-22829
25 #ifndef Q_MOC_RUN
26  #include <boost/python.hpp>
27  #include <boost/shared_ptr.hpp>
28 #endif
29 #include "output_redirector.hh"
30 #include <csignal>
31 #include <utility>
32 #include <QObject>
33 #include <QQueue>
34 
35 namespace ost { namespace gui {
36 namespace bp = boost::python;
37 
38 class PythonInterpreterWorker: public QObject
39 {
40 Q_OBJECT
41 public:
44  unsigned int AddCommand(const QString& command);
45 
46 signals:
47  void Finished(unsigned int id, bool error_state);
48  void Output(unsigned int id,const QString& output);
49  void ErrorOutput(unsigned int id,const QString& output);
50 
51 public slots:
52  void Wake();
53 
54 protected slots:
55  void handle_redirector_output(const QString& output);
56  void handle_redirector_error(const QString& output);
57 
58 protected:
59  bool is_simple_expression(const QString& expr);
60  void run_command_(std::pair<unsigned int,QString> pair);
61  bool is_simple_expression_(const QString& expr);
62  QQueue<std::pair<unsigned int,QString> > exec_queue_;
63  unsigned int command_id_;
64  boost::shared_ptr<OutputRedirector> output_redirector_;
65  boost::shared_ptr<OutputRedirector> error_redirector_;
66 #ifndef _MSC_VER
67  struct sigaction sig_act_;
68 #endif
69  bp::object parse_expr_cmd_;
70  bp::object repr_;
71  bp::dict main_namespace_;
72  unsigned int current_id_;
73  bool awake_;
74 };
75 
76 }} //ns
77 
78 #endif // PYTHON_INTERPRETER_WORKER_HH
QQueue< std::pair< unsigned int, QString > > exec_queue_
bool is_simple_expression(const QString &expr)
void ErrorOutput(unsigned int id, const QString &output)
boost::shared_ptr< OutputRedirector > error_redirector_
boost::shared_ptr< OutputRedirector > output_redirector_
void Finished(unsigned int id, bool error_state)
void Output(unsigned int id, const QString &output)
void run_command_(std::pair< unsigned int, QString > pair)
void handle_redirector_output(const QString &output)
bool is_simple_expression_(const QString &expr)
unsigned int AddCommand(const QString &command)
void handle_redirector_error(const QString &output)