/* Convert from a Python type to Glib::Variant, according to config key data type. */
Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::ConfigKey *key)
{
- enum sr_datatype type = key->data_type()->id();
+ enum sr_datatype type = (enum sr_datatype) key->data_type()->id();
if (type == SR_T_UINT64 && PyInt_Check(input))
return Glib::Variant<guint64>::create(PyInt_AsLong(input));
%include "doc.i"
+%define %attributevector(Class, Type, Name, Get)
+%rename(_ ## Get) sigrok::Class::Get;
+%extend sigrok::Class
+{
+%pythoncode
+{
+ Name = property(_ ## Get)
+}
+}
+%enddef
+
+%define %attributemap(Class, Type, Name, Get)
+%rename(_ ## Get) sigrok::Class::Get;
+%extend sigrok::Class
+{
+%pythoncode
+{
+ Name = property(fget = lambda x: x._ ## Get().asdict(), doc=_ ## Get.__doc__)
+}
+}
+%enddef
+
+%define %enumextras(Class)
+%extend sigrok::Class
+{
+ long __hash__()
+ {
+ return (long) $self;
+ }
+
+%pythoncode
+{
+ def __eq__(self, other):
+ return (type(self) is type(other) and hash(self) == hash(other))
+
+ def __ne__(self, other):
+ return (type(self) is not type(other) or hash(self) != hash(other))
+}
+}
+%enddef
+
%include "../../../swig/classes.i"
/* Support Driver.scan() with keyword arguments. */
{
if (!PyString_Check(py_key))
throw sigrok::Error(SR_ERR_ARG);
- auto key = sigrok::ConfigKey::get(PyString_AsString(py_key));
+ auto key = sigrok::ConfigKey::get_by_identifier(PyString_AsString(py_key));
auto value = python_to_variant_by_key(py_value, key);
options[key] = value;
}