From: Richard Allen Date: Tue, 26 Jan 2021 06:27:09 +0000 (-0600) Subject: python bindings: Support passing in rational voltages for config_set X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a2916ad01779e1cf8a5e220eb6288dab9734b146;p=libsigrok.git python bindings: Support passing in rational voltages for config_set --- diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 5c5cb3b3..94913d0f 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -340,8 +340,15 @@ Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::Config return Glib::Variant::create(PyFloat_AsDouble(input)); else if (type == SR_T_INT32 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); - else - throw sigrok::Error(SR_ERR_ARG); + else if ((type == SR_T_RATIONAL_VOLT) && PyTuple_Check(input) && (PyTuple_Size(input) == 2)) { + PyObject *numObj = PyTuple_GetItem(input, 0); + PyObject *denomObj = PyTuple_GetItem(input, 1); + if ((PyInt_Check(numObj) || PyLong_Check(numObj)) && (PyInt_Check(denomObj) || PyLong_Check(denomObj))) { + std::tuple tpl = {PyInt_AsLong(numObj), PyInt_AsLong(denomObj)}; + return Glib::Variant< std::tuple >::Variant::create(tpl); + } + } + throw sigrok::Error(SR_ERR_ARG); } /* Convert from a Python type to Glib::Variant, according to Option data type. */