Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions PythonScript/src/PythonConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void PythonConsole::initPython(PythonHandler *pythonHandler)
void PythonConsole::pythonShowDialog()
{
assert(mp_consoleDlg);
GILRelease release;
if (mp_consoleDlg)
{
// Post the message to ourselves (on the right thread) to create the window
Expand All @@ -144,6 +145,7 @@ void PythonConsole::showDialog()
assert(mp_consoleDlg);
if (mp_consoleDlg)
{
GILRelease release;
mp_consoleDlg->doDialog();
}
}
Expand All @@ -153,6 +155,7 @@ void PythonConsole::hideDialog()
assert(mp_consoleDlg);
if (mp_consoleDlg)
{
GILRelease release;
mp_consoleDlg->hide();
}
}
Expand All @@ -162,6 +165,7 @@ void PythonConsole::message(const char *msg)
assert(mp_consoleDlg);
if (mp_consoleDlg)
{
GILRelease release;
mp_consoleDlg->writeText(strlen(msg), msg);
}
}
Expand All @@ -171,6 +175,7 @@ void PythonConsole::clear()
assert(mp_consoleDlg);
if (mp_consoleDlg)
{
GILRelease release;
mp_consoleDlg->clearText();
}
}
Expand Down Expand Up @@ -272,23 +277,26 @@ void PythonConsole::queueComplete()

void PythonConsole::consume(std::shared_ptr<std::string> statement)
{
GILLock gilLock;

bool continuePrompt = false;
try
{
boost::python::object oldStdout = m_sys.attr("stdout");
m_sys.attr("stdout") = boost::python::ptr(this);
PyObject* unicodeCommand = PyUnicode_FromEncodedObject(boost::python::str(statement->c_str()).ptr(), "utf-8", NULL);
boost::python::object result = m_pushFunc(boost::python::handle<PyObject>(unicodeCommand));
//Py_DECREF(unicodeCommand);
m_sys.attr("stdout") = oldStdout;

continuePrompt = boost::python::extract<bool>(result);
}
catch(...)
{
PyErr_Print();
GILLock gilLock;

try
{
boost::python::object oldStdout = m_sys.attr("stdout");
m_sys.attr("stdout") = boost::python::ptr(this);
PyObject* unicodeCommand = PyUnicode_FromEncodedObject(boost::python::str(statement->c_str()).ptr(), "utf-8", NULL);
boost::python::object result = m_pushFunc(boost::python::handle<PyObject>(unicodeCommand));
//Py_DECREF(unicodeCommand);
m_sys.attr("stdout") = oldStdout;

continuePrompt = boost::python::extract<bool>(result);
}
catch(...)
{
PyErr_Print();
}

}

assert(mp_consoleDlg);
Expand Down