X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fpython%2Fsigrok%2Fcore%2Fclasses.i;h=7d4304fca13e9644a2117d74571576fd24cd2495;hb=ed6b4c4747ed98374feb59ac5758a24bd4d9a63f;hp=7a6eb22ba3789ecb54f8c8d6b745831571f4a497;hpb=ea22dc108b1da4c1f43c5cb2b8433a44fad726bf;p=libsigrok.git diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 7a6eb22b..7d4304fc 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -46,6 +46,7 @@ which provides access to the error code and description." %{ #include +#include PyObject *GLib; PyTypeObject *IOChannel; @@ -66,6 +67,7 @@ typedef guint pyg_flags_type; GLib = PyImport_ImportModule("gi.repository.GLib"); IOChannel = (PyTypeObject *) PyObject_GetAttrString(GLib, "IOChannel"); PollFD = (PyTypeObject *) PyObject_GetAttrString(GLib, "PollFD"); + import_array(); %} /* Map file objects to file descriptors. */ @@ -446,6 +448,7 @@ std::map dict_to_map_options(PyObject *dict, %} /* Ignore these methods, we will override them below. */ +%ignore sigrok::Analog::data; %ignore sigrok::Driver::scan; %ignore sigrok::InputFormat::create_input; %ignore sigrok::OutputFormat::create_output; @@ -573,3 +576,23 @@ std::map dict_to_map_options(PyObject *dict, $self->config_set(key, python_to_variant_by_key(input, key)); } } + +/* Return NumPy array from Analog::data(). */ +%extend sigrok::Analog +{ + PyObject * _data() + { + int nd = 2; + npy_intp dims[2]; + dims[0] = $self->channels().size(); + dims[1] = $self->num_samples(); + int typenum = NPY_FLOAT; + void *data = $self->data_pointer(); + return PyArray_SimpleNewFromData(nd, dims, typenum, data); + } + +%pythoncode +{ + data = property(_data) +} +}