From 444d6a3975787583494fa91cbb20c26d0ac858b5 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Tue, 11 Nov 2014 15:29:35 +0000 Subject: [PATCH] python: Fix mapping of vector & map attributes to Python types. Fixes bug #382. --- bindings/python/sigrok/core/classes.i | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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"