mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-16 01:19:57 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user