OpenStructure
Loading...
Searching...
No Matches
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-2020 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 // https://stackoverflow.com/questions/23068700/embedding-python3-in-qt-5
27 #pragma push_macro("slots")
28 #undef slots
29 #include <boost/python.hpp>
30 #include <boost/shared_ptr.hpp>
31 #pragma pop_macro("slots")
32#endif
33#include "output_redirector.hh"
34#include <csignal>
35#include <utility>
36#include <QObject>
37#include <QQueue>
38
39namespace ost { namespace gui {
40namespace bp = boost::python;
41
42class PythonInterpreterWorker: public QObject
43{
44Q_OBJECT
45public:
48 unsigned int AddCommand(const QString& command);
49
50signals:
51 void Finished(unsigned int id, bool error_state);
52 void Output(unsigned int id,const QString& output);
53 void ErrorOutput(unsigned int id,const QString& output);
54
55public slots:
56 void Wake();
57
58protected slots:
59 void handle_redirector_output(const QString& output);
60 void handle_redirector_error(const QString& output);
61
62protected:
63 bool is_simple_expression(const QString& expr);
64 void run_command_(std::pair<unsigned int,QString> pair);
65 QQueue<std::pair<unsigned int,QString> > exec_queue_;
66 unsigned int command_id_;
67 boost::shared_ptr<OutputRedirector> output_redirector_;
68 boost::shared_ptr<OutputRedirector> error_redirector_;
69#ifndef _MSC_VER
70 struct sigaction sig_act_;
71#endif
72 bp::object parse_expr_cmd_;
73 bp::object repr_;
75 unsigned int current_id_;
76 bool awake_;
77};
78
79}} //ns
80
81#endif // PYTHON_INTERPRETER_WORKER_HH
void Output(unsigned int id, const QString &output)
unsigned int AddCommand(const QString &command)
bool is_simple_expression(const QString &expr)
void Finished(unsigned int id, bool error_state)
boost::shared_ptr< OutputRedirector > output_redirector_
boost::shared_ptr< OutputRedirector > error_redirector_
void run_command_(std::pair< unsigned int, QString > pair)
void handle_redirector_output(const QString &output)
void handle_redirector_error(const QString &output)
void ErrorOutput(unsigned int id, const QString &output)
QQueue< std::pair< unsigned int, QString > > exec_queue_
Definition base.dox:1