@@ -136,8 +136,8 @@ static StreamCatcher* create_catcher(const bool is_stderr,
136136}
137137
138138// Redirect sys.stdout and sys.stderr
139- bool redirect_python_output (stdout_write_type stdout_write,
140- stdout_write_type stderr_write)
139+ static bool redirect_python_output (stdout_write_type stdout_write,
140+ stdout_write_type stderr_write)
141141{
142142 PyObject* sysmod = PyImport_ImportModule (" sys" );
143143 if (!sysmod) {
@@ -149,8 +149,8 @@ bool redirect_python_output(stdout_write_type stdout_write,
149149 original_stderr = PyObject_GetAttrString (sysmod, " stderr" );
150150
151151 // Create new catchers
152- stdout_catcher = create_catcher (false , stdout_write);
153- stderr_catcher = create_catcher (true , stderr_write);
152+ stdout_catcher = create_catcher (false , std::move ( stdout_write) );
153+ stderr_catcher = create_catcher (true , std::move ( stderr_write) );
154154
155155 if (!stdout_catcher || !stderr_catcher) {
156156 Py_DECREF (sysmod);
@@ -168,8 +168,10 @@ bool redirect_python_output(stdout_write_type stdout_write,
168168 return true ;
169169}
170170
171+ // TODO: Preserved for exiting the GUI back to text mode
172+ #if 0
171173// Restore original sys.stdout/stderr
172- void restore_python_output ()
174+ static void restore_python_output()
173175{
174176 PyObject* sysmod = PyImport_ImportModule("sys");
175177 if (!sysmod) {
@@ -195,6 +197,8 @@ void restore_python_output()
195197 Py_DECREF(sysmod);
196198}
197199
200+ #endif
201+
198202static PythonCmdInputWidget* widget = nullptr ;
199203
200204class PythonRef : public std ::unique_ptr<PyObject>
@@ -325,13 +329,13 @@ void PythonCmdInputWidget::init()
325329 }
326330
327331 stdout_write_type stdout_write
328- = [logger](std::string s) { logger->report (" {}" , s); };
329- stdout_write_type stderr_write = [this ](std::string s) {
332+ = [logger](const std::string& s) { logger->report (" {}" , s); };
333+ stdout_write_type stderr_write = [this ](const std::string& s) {
330334 emit addResultToOutput (QString::fromStdString (s), false );
331335 };
332336
333337 if (!redirect_python_output (stdout_write, stderr_write)) {
334- std::cerr << " Failed to redirect Python output" << std::endl ;
338+ std::cerr << " Failed to redirect Python output\n " ;
335339 Py_Finalize ();
336340 return ;
337341 }
0 commit comments