%module(docstring=DOCSTRING) classes
%{
+#include "config.h"
+
#include <stdio.h>
#include <pygobject.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
PyObject *PyGObject_lib;
PyObject *GLib;
-#include "config.h"
-
#if PYGOBJECT_FLAGS_SIGNED
typedef gint pyg_flags_type;
#else
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);
/* Ignore these methods, we will override them below. */
%ignore sigrok::Analog::data;
+%ignore sigrok::Logic::data;
%ignore sigrok::Driver::scan;
%ignore sigrok::InputFormat::create_input;
%ignore sigrok::OutputFormat::create_output;
return (long) $self;
}
+ std::string __str__()
+ {
+ return $self->name();
+ }
+
+ std::string __repr__()
+ {
+ return "Class." + $self->name();
+ }
+
%pythoncode
{
def __eq__(self, other):
}
}
+/* Return NumPy array from Logic::data(). */
+%extend sigrok::Logic
+{
+ PyObject * _data()
+ {
+ npy_intp dims[2];
+ dims[0] = $self->data_length() / $self->unit_size();
+ dims[1] = $self->unit_size();
+ int typenum = NPY_UINT8;
+ void *data = $self->data_pointer();
+ return PyArray_SimpleNewFromData(2, dims, typenum, data);
+ }
+
+%pythoncode
+{
+ data = property(_data)
+}
+}
+
+/* Create logic packet from Python buffer. */
+%extend sigrok::Context
+{
+ std::shared_ptr<Packet> _create_logic_packet_buf(PyObject *buf, unsigned int unit_size)
+ {
+ Py_buffer view;
+ PyObject_GetBuffer(buf, &view, PyBUF_SIMPLE);
+ return $self->create_logic_packet(view.buf, view.len, unit_size);
+ }
+}
+
+%pythoncode
+{
+ def _Context_create_logic_packet(self, buf, unit_size):
+ return self._create_logic_packet_buf(buf, unit_size)
+
+ Context.create_logic_packet = _Context_create_logic_packet
+}
+
%include "doc_end.i"