From: Martin Ling Date: Tue, 11 Nov 2014 15:29:35 +0000 (+0000) Subject: python: Fix mapping of vector & map attributes to Python types. X-Git-Tag: libsigrok-0.4.0~795 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=444d6a3975787583494fa91cbb20c26d0ac858b5;p=libsigrok.git python: Fix mapping of vector & map attributes to Python types. Fixes bug #382. --- diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index 3c327e4d..7cfdc29d 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -360,11 +360,25 @@ std::map dict_to_map_options(PyObject *dict, %include "doc.i" %define %attributevector(Class, Type, Name, Get) -%attributeval(sigrok::Class, Type, Name, Get); +%rename(_ ## Get) sigrok::Class::Get; +%extend sigrok::Class +{ +%pythoncode +{ + Name = property(_ ## Get) +} +} %enddef %define %attributemap(Class, Type, Name, Get) -%attributeval(sigrok::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 %include "../../../swig/classes.i"