X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fpython%2Fsigrok%2Fcore%2Fclasses.i;h=8bccae1d5271aa98ebadf15baab4f07bcb3fa55d;hb=c1f9428a6c95e639e3d613738b6a2b08c8496ee0;hp=a00efff2536d78911cd7a8b41f2744ad418c8479;hpb=62bd644f55b674730957be4e3dcd3d3362148cfc;p=libsigrok.git diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index a00efff2..8bccae1d 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -112,6 +112,9 @@ typedef guint pyg_flags_type; g_free(value); } +/* Use the same typemap above for Glib::VariantContainerBase */ +%apply Glib::VariantBase { Glib::VariantContainerBase } + /* Map from callable PyObject to LogCallbackFunction */ %typecheck(SWIG_TYPECHECK_POINTER) sigrok::LogCallbackFunction { $1 = PyCallable_Check($input); @@ -337,8 +340,17 @@ 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_UINT32 && PyInt_Check(input)) + return Glib::Variant::create(PyInt_AsLong(input)); + 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))) { + const std::vector v = {(guint64)PyInt_AsLong(numObj), (guint64)PyInt_AsLong(denomObj)}; + return Glib::Variant< std::vector >::create(v); + } + } + throw sigrok::Error(SR_ERR_ARG); } /* Convert from a Python type to Glib::Variant, according to Option data type. */ @@ -359,6 +371,8 @@ Glib::VariantBase python_to_variant_by_option(PyObject *input, return Glib::Variant::create(PyFloat_AsDouble(input)); else if (type == G_VARIANT_TYPE_INT32 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); + else if (type == G_VARIANT_TYPE_UINT32 && PyInt_Check(input)) + return Glib::Variant::create(PyInt_AsLong(input)); else throw sigrok::Error(SR_ERR_ARG); }