add App.Units.setSchema() python method

This commit is contained in:
Yorik van Havre
2018-12-05 22:25:13 -02:00
parent 2557f07cbe
commit 91bb88fe18
2 changed files with 20 additions and 0 deletions

View File

@@ -105,6 +105,7 @@ protected: // the python API wrapper methods
static PyObject *sParseQuantity (PyObject *self,PyObject *args);
static PyObject *sListSchemas (PyObject *self,PyObject *args);
static PyObject *sGetSchema (PyObject *self,PyObject *args);
static PyObject *sSetSchema (PyObject *self,PyObject *args);
static PyObject *sSchemaTranslate (PyObject *self,PyObject *args);
};

View File

@@ -84,6 +84,10 @@ PyMethodDef UnitsApi::Methods[] = {
"getSchema() -> int\n\n"
"The int is the position of the tuple returned by listSchemas"
},
{"setSchema", (PyCFunction) UnitsApi::sSetSchema, METH_VARARGS,
"setSchema(int) -> None\n\n"
"Sets the current schema to the given number, if possible"
},
{"schemaTranslate", (PyCFunction) UnitsApi::sSchemaTranslate, METH_VARARGS,
"schemaTranslate(Quantity, int) -> tuple\n\n"
"Translate a quantity to a given schema"
@@ -198,6 +202,21 @@ PyObject* UnitsApi::sGetSchema(PyObject * /*self*/, PyObject *args)
return Py_BuildValue("i", static_cast<int>(actSystem));
}
PyObject* UnitsApi::sSetSchema(PyObject * /*self*/, PyObject *args)
{
PyErr_Clear();
int index;
if (PyArg_ParseTuple(args, "i", &index)) {
int num = NumUnitSystemTypes;
if (index < 0 || index >= num) {
PyErr_SetString(PyExc_ValueError, "invalid schema value");
return 0;
}
setSchema((UnitSystem)index);
}
Py_Return;
}
PyObject* UnitsApi::sSchemaTranslate(PyObject * /*self*/, PyObject *args)
{
PyObject* q;