X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fpython%2Fsigrok%2Fcore%2Fclasses.i;h=3c327e4d4c50222b074961757d6cccb1d5659211;hb=062430a2fbd74a7ff153b77d92523daae9ec18a7;hp=91c4fe63538fa77b1377b90a7e49cd7b801cd6ca;hpb=6a8c1d68797cbb51cb94436b29ef451a1eab5293;p=libsigrok.git diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 91c4fe63..3c327e4d 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -51,7 +51,7 @@ PyObject *GLib; PyTypeObject *IOChannel; PyTypeObject *PollFD; -#include "../../../../config.h" +#include "config.h" #if PYGOBJECT_FLAGS_SIGNED typedef gint pyg_flags_type; @@ -287,14 +287,14 @@ std::map dict_to_map_string(PyObject *dict) /* 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->get_data_type()->get_id(); + enum sr_datatype type = (enum sr_datatype) key->data_type()->id(); if (type == SR_T_UINT64 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); if (type == SR_T_UINT64 && PyLong_Check(input)) return Glib::Variant::create(PyLong_AsLong(input)); else if (type == SR_T_STRING && PyString_Check(input)) - return Glib::Variant::create(PyString_AsString(input)); + return Glib::Variant::create(PyString_AsString(input)); else if (type == SR_T_BOOL && PyBool_Check(input)) return Glib::Variant::create(input == Py_True); else if (type == SR_T_FLOAT && PyFloat_Check(input)) @@ -309,14 +309,14 @@ Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::Config Glib::VariantBase python_to_variant_by_option(PyObject *input, std::shared_ptr option) { - GVariantType *type = option->get_default_value().get_type().gobj(); + GVariantType *type = option->default_value().get_type().gobj(); if (type == G_VARIANT_TYPE_UINT64 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); if (type == G_VARIANT_TYPE_UINT64 && PyLong_Check(input)) return Glib::Variant::create(PyLong_AsLong(input)); else if (type == G_VARIANT_TYPE_STRING && PyString_Check(input)) - return Glib::Variant::create(PyString_AsString(input)); + return Glib::Variant::create(PyString_AsString(input)); else if (type == G_VARIANT_TYPE_BOOLEAN && PyBool_Check(input)) return Glib::Variant::create(input == Py_True); else if (type == G_VARIANT_TYPE_DOUBLE && PyFloat_Check(input)) @@ -354,11 +354,19 @@ std::map dict_to_map_options(PyObject *dict, /* Ignore these methods, we will override them below. */ %ignore sigrok::Driver::scan; -%ignore sigrok::InputFormat::open_file; +%ignore sigrok::InputFormat::create_input; %ignore sigrok::OutputFormat::create_output; %include "doc.i" +%define %attributevector(Class, Type, Name, Get) +%attributeval(sigrok::Class, Type, Name, Get); +%enddef + +%define %attributemap(Class, Type, Name, Get) +%attributeval(sigrok::Class, Type, Name, Get); +%enddef + %include "../../../swig/classes.i" /* Support Driver.scan() with keyword arguments. */ @@ -377,7 +385,7 @@ std::map dict_to_map_options(PyObject *dict, { 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; } @@ -394,21 +402,22 @@ std::map dict_to_map_options(PyObject *dict, Driver.scan = _Driver_scan } -/* Support InputFormat.open_file() with keyword arguments. */ +/* Support InputFormat.create_input() with keyword arguments. */ %extend sigrok::InputFormat { - std::shared_ptr _open_file_kwargs(std::string filename, PyObject *dict) + std::shared_ptr _create_input_kwargs(PyObject *dict) { - return $self->open_file(filename, dict_to_map_string(dict)); + return $self->create_input( + dict_to_map_options(dict, $self->options())); } } %pythoncode { - def _InputFormat_open_file(self, filename, **kwargs): - return self._open_file_kwargs(filename, kwargs) + def _InputFormat_create_input(self, **kwargs): + return self._create_input(kwargs) - InputFormat.open_file = _InputFormat_open_file + InputFormat.create_input = _InputFormat_create_input } /* Support OutputFormat.create_output() with keyword arguments. */ @@ -418,7 +427,7 @@ std::map dict_to_map_options(PyObject *dict, std::shared_ptr device, PyObject *dict) { return $self->create_output(device, - dict_to_map_options(dict, $self->get_options())); + dict_to_map_options(dict, $self->options())); } }