| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#ifndef GUI_PYTHONCONSOLE_PY_H |
| 25 |
#define GUI_PYTHONCONSOLE_PY_H |
| 26 |
|
| 27 |
#include <CXX/Extensions.hxx> |
| 28 |
|
| 29 |
class QTimer; |
| 30 |
|
| 31 |
namespace Gui |
| 32 |
{ |
| 33 |
class PythonConsole; |
| 34 |
|
| 35 |
/** |
| 36 |
* Python class for redirection of stdout to FreeCAD's Python |
| 37 |
* console window. This allows one to show all Python messages in |
| 38 |
* the same window where the commands are performed. |
| 39 |
* @see PythonStderr |
| 40 |
* @see PythonConsole |
| 41 |
* @author Werner Mayer |
| 42 |
*/ |
| 43 |
class PythonStdout: public Py::PythonExtension<PythonStdout> |
| 44 |
{ |
| 45 |
private: |
| 46 |
PythonConsole* pyConsole; |
| 47 |
|
| 48 |
public: |
| 49 |
static void init_type(); // announce properties and methods |
| 50 |
|
| 51 |
explicit PythonStdout(PythonConsole* pc); |
| 52 |
~PythonStdout() override; |
| 53 |
|
| 54 |
Py::Object getattr(const char* name) override; |
| 55 |
Py::Object repr() override; |
| 56 |
Py::Object write(const Py::Tuple&); |
| 57 |
Py::Object flush(const Py::Tuple&); |
| 58 |
Py::Object isatty(); |
| 59 |
}; |
| 60 |
|
| 61 |
/** |
| 62 |
* Python class for redirection of stderr to FreeCAD's Python |
| 63 |
* console window. This allows one to show all Python messages in |
| 64 |
* the same window where the commands are performed. |
| 65 |
* @see PythonStdout |
| 66 |
* @see PythonConsole |
| 67 |
* @author Werner Mayer |
| 68 |
*/ |
| 69 |
class PythonStderr: public Py::PythonExtension<PythonStderr> |
| 70 |
{ |
| 71 |
private: |
| 72 |
PythonConsole* pyConsole; |
| 73 |
|
| 74 |
public: |
| 75 |
static void init_type(); // announce properties and methods |
| 76 |
|
| 77 |
explicit PythonStderr(PythonConsole* pc); |
| 78 |
~PythonStderr() override; |
| 79 |
|
| 80 |
Py::Object getattr(const char* name) override; |
| 81 |
Py::Object repr() override; |
| 82 |
Py::Object write(const Py::Tuple&); |
| 83 |
Py::Object flush(const Py::Tuple&); |
| 84 |
Py::Object isatty(); |
| 85 |
}; |
| 86 |
|
| 87 |
/** |
| 88 |
* Python class for redirection of stdout to FreeCAD's output |
| 89 |
* console window. This allows one to report all Python output to |
| 90 |
* the report view which simplifies debugging scripts. |
| 91 |
* @see PythonStdout |
| 92 |
* @see PythonStderr |
| 93 |
* @author Werner Mayer |
| 94 |
*/ |
| 95 |
class OutputStdout: public Py::PythonExtension<OutputStdout> |
| 96 |
{ |
| 97 |
public: |
| 98 |
static void init_type(); // announce properties and methods |
| 99 |
|
| 100 |
OutputStdout(); |
| 101 |
~OutputStdout() override; |
| 102 |
|
| 103 |
Py::Object getattr(const char* name) override; |
| 104 |
Py::Object repr() override; |
| 105 |
Py::Object write(const Py::Tuple&); |
| 106 |
Py::Object flush(const Py::Tuple&); |
| 107 |
Py::Object isatty(); |
| 108 |
}; |
| 109 |
|
| 110 |
/** |
| 111 |
* Python class for redirection of stderr to FreeCAD's output |
| 112 |
* console window. This allows one to report all Python errors to |
| 113 |
* the report view which simplifies error tracking. |
| 114 |
* @see PythonStdout |
| 115 |
* @see PythonStderr |
| 116 |
* @author Werner Mayer |
| 117 |
*/ |
| 118 |
class OutputStderr: public Py::PythonExtension<OutputStderr> |
| 119 |
{ |
| 120 |
public: |
| 121 |
static void init_type(); // announce properties and methods |
| 122 |
|
| 123 |
OutputStderr(); |
| 124 |
~OutputStderr() override; |
| 125 |
|
| 126 |
Py::Object getattr(const char* name) override; |
| 127 |
Py::Object repr() override; |
| 128 |
Py::Object write(const Py::Tuple&); |
| 129 |
Py::Object flush(const Py::Tuple&); |
| 130 |
Py::Object isatty(); |
| 131 |
}; |
| 132 |
|
| 133 |
/** |
| 134 |
* Python class for redirection of stdin to an input dialog of Qt. |
| 135 |
* @author Werner Mayer |
| 136 |
*/ |
| 137 |
class PythonStdin: public Py::PythonExtension<PythonStdin> |
| 138 |
{ |
| 139 |
private: |
| 140 |
PythonConsole* pyConsole; |
| 141 |
|
| 142 |
public: |
| 143 |
static void init_type(); // announce properties and methods |
| 144 |
|
| 145 |
explicit PythonStdin(PythonConsole* pc); |
| 146 |
~PythonStdin() override; |
| 147 |
|
| 148 |
Py::Object repr() override; |
| 149 |
Py::Object getattr(const char* name) override; |
| 150 |
Py::Object readline(const Py::Tuple&); |
| 151 |
}; |
| 152 |
|
| 153 |
} // namespace Gui |
| 154 |
|
| 155 |
#endif // GUI_PYTHONCONSOLE_PY_H |