Skip to content

Commit

Permalink
fixes #2632: Improvements to Prefs for Python
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 25, 2017
1 parent 5022b41 commit 0ad9436
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/App/Application.h
Expand Up @@ -292,6 +292,7 @@ class AppExport Application

// static python wrapper of the exported functions
static PyObject* sGetParam (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sSaveParameter (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetVersion (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sGetConfig (PyObject *self,PyObject *args,PyObject *kwd);
static PyObject* sSetConfig (PyObject *self,PyObject *args,PyObject *kwd);
Expand Down
30 changes: 30 additions & 0 deletions src/App/ApplicationPy.cpp
Expand Up @@ -58,6 +58,9 @@ using namespace App;
PyMethodDef Application::Methods[] = {
{"ParamGet", (PyCFunction) Application::sGetParam, 1,
"Get parameters by path"},
{"saveParameter", (PyCFunction) Application::sSaveParameter, 1,
"saveParameter(config='User parameter') -> None\n"
"Save parameter set to file. The default set is 'User parameter'"},
{"Version", (PyCFunction) Application::sGetVersion, 1,
"Print the version to the output."},
{"ConfigGet", (PyCFunction) Application::sGetConfig, 1,
Expand Down Expand Up @@ -342,6 +345,33 @@ PyObject* Application::sGetParam(PyObject * /*self*/, PyObject *args,PyObject *
}PY_CATCH;
}

PyObject* Application::sSaveParameter(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char *pstr = "User parameter";
if (!PyArg_ParseTuple(args, "|s", &pstr))
return NULL;

PY_TRY {
ParameterManager* param = App::GetApplication().GetParameterSet(pstr);
if (!param) {
std::stringstream str;
str << "No parameter set found with name: " << pstr;
PyErr_SetString(PyExc_ValueError, str.str().c_str());
return NULL;
}
else if (!param->HasSerializer()) {
std::stringstream str;
str << "Parameter set cannot be serialized: " << pstr;
PyErr_SetString(PyExc_RuntimeError, str.str().c_str());
return NULL;
}

param->SaveDocument();
Py_INCREF(Py_None);
return Py_None;
}PY_CATCH;
}


PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
Expand Down

0 comments on commit 0ad9436

Please sign in to comment.