From e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 14 Dec 2018 17:20:25 +0100 Subject: Add GUI for executing python file --- 3rdparty/python-console/modified/pyinterpreter.cc | 22 ++++++++++++++++++++++ 3rdparty/python-console/modified/pyinterpreter.h | 1 + 2 files changed, 23 insertions(+) (limited to '3rdparty/python-console') diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index f53207ad..89c9b88c 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -153,3 +153,25 @@ void pyinterpreter_release() { PyEval_ReleaseThread(m_threadState); } + +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode) +{ + PyEval_AcquireThread(m_threadState); + *errorCode = 0; + std::string res; + FILE *fp = fopen(python_file, "r"); + if (fp == NULL) { + *errorCode = 1; + res = "Fatal error: file not found " + std::string(python_file) + "\n"; + return res; + } + + if (PyRun_SimpleFile(fp, python_file)==-1) { + *errorCode = 1; + PyErr_Print(); + } + res = redirector_take_output(m_threadState); + + PyEval_ReleaseThread(m_threadState); + return res; +} diff --git a/3rdparty/python-console/modified/pyinterpreter.h b/3rdparty/python-console/modified/pyinterpreter.h index 1a85c1fb..48512507 100644 --- a/3rdparty/python-console/modified/pyinterpreter.h +++ b/3rdparty/python-console/modified/pyinterpreter.h @@ -33,4 +33,5 @@ void pyinterpreter_initialize(); void pyinterpreter_finalize(); void pyinterpreter_aquire(); void pyinterpreter_release(); +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode); #endif // PYINTERPRETER_H -- cgit v1.2.3