From 728a52c83c1e111d43ecb38d6abdc49e1cf31302 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 5 Jun 2018 11:50:10 +0200 Subject: Fix scriptableapplication after PEP384 Due to the PEP384 many casts related to SbkObjectTypes dropped the `const` because of a change on the signature of the methods like `pointerToPython`, `referenceToPython`, among others. Many examples of these changs can be found in the commit: 18dc31becdd994c53a9f894087cf1ef99fbd0232 file `sbkconverter.cpp`. Change-Id: Id7b9f8e14fd931c686608a89e0d989d9026e0c85 Reviewed-by: Friedemann Kleint --- examples/scriptableapplication/pythonutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/scriptableapplication/pythonutils.cpp') diff --git a/examples/scriptableapplication/pythonutils.cpp b/examples/scriptableapplication/pythonutils.cpp index 2f7d2c2ad..2d5be552c 100644 --- a/examples/scriptableapplication/pythonutils.cpp +++ b/examples/scriptableapplication/pythonutils.cpp @@ -122,7 +122,7 @@ bool bindAppObject(const QString &moduleName, const QString &name, return false; PyTypeObject *typeObject = SbkAppLibTypes[index]; - PyObject *po = Shiboken::Conversions::pointerToPython(reinterpret_cast(typeObject), o); + PyObject *po = Shiboken::Conversions::pointerToPython(reinterpret_cast(typeObject), o); if (!po) { qWarning() << __FUNCTION__ << "Failed to create wrapper for" << o; return false; -- cgit v1.2.3 From e58320653e3e455685636b58750088f806b98533 Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 5 Jun 2018 15:02:48 +0200 Subject: scriptableapplication: execution as one line The previous approach executed the entered script line-by-line, it was not possible to execute multi-line statements, for example: for i in range(0, 10): print(i) because PyRun_SimpleString was complaining about the colon. To avoid all these extra steps we can concatenate all the lines into one, and then execute it, instead of creating a temporary file. This will delegate error handling to Python. Change-Id: Idda572aa1b2e3daad2ba1ed9d70f0a8714b8c995 Reviewed-by: Alexandru Croitor --- examples/scriptableapplication/pythonutils.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'examples/scriptableapplication/pythonutils.cpp') diff --git a/examples/scriptableapplication/pythonutils.cpp b/examples/scriptableapplication/pythonutils.cpp index 2d5be552c..f546a5a6c 100644 --- a/examples/scriptableapplication/pythonutils.cpp +++ b/examples/scriptableapplication/pythonutils.cpp @@ -54,6 +54,8 @@ #include #include #include +#include +#include #include #include @@ -152,17 +154,22 @@ bool runScript(const QStringList &script) { if (init() == PythonUninitialized) return false; + + // Concatenating all the lines + QString content; + QTextStream ss(&content); + for (const QString &line: script) + ss << line << "\n"; + + // Executing the whole script as one line bool result = true; - for (const QString& lineS : script) { - const QByteArray line = lineS.toUtf8(); - if (PyRun_SimpleString(line.constData()) == -1) { - if (PyErr_Occurred()) - PyErr_Print(); - qWarning() << __FUNCTION__ << "Error at" << line; - result = false; - break; - } + const QByteArray line = content.toUtf8(); + if (PyRun_SimpleString(line.constData()) == -1) { + if (PyErr_Occurred()) + PyErr_Print(); + result = false; } + return result; } -- cgit v1.2.3