DataFilter Embed Python Scripts

.. allow the user to embed a python script into a datafilter.

.. this is primarily to enable the use of python when writing
   user metrics.

.. the syntax is basically "%%python script %%" and it is
   evaluated as an expresssion so the results can be assigned
   to a variable or returned as a value.

.. additionally GC.result(double) has been added to the python
   API to enable a return value to be set by the script.

.. since Python is really sensitive about white space its going
   to be best practice to embed python scripts without honoring
   any of the data filter spacing, for example:

{
   value {
      t <-

%%python
GC.result(100)
%%;

   }
}

  .. is likely to be a sensible way to use this.

  .. also notice how the ; is needed after the expression. This
     is because %%python ... %% is a numeric expression with the
     same semantics as "1 + 2"
This commit is contained in:
Mark Liversedge
2018-01-29 10:03:41 +00:00
parent a78ea56090
commit 8e3a170d94
13 changed files with 165 additions and 25 deletions

View File

@@ -110,7 +110,6 @@ PythonEmbed::PythonEmbed(const bool verbose, const bool interactive) : verbose(v
// prepare for threaded processing
PyEval_InitThreads();
mainThreadState = PyEval_SaveThread();
loaded = true;
}
@@ -152,6 +151,7 @@ void PythonEmbed::runline(Context *context, QString line)
// clear results
PyObject_CallFunction(static_cast<PyObject*>(clear), NULL);
}
PyGILState_Release(gstate);
threadid=-1;
}