From dac56ff0dcf35c4bf8ecb1e127465f6f726de737 Mon Sep 17 00:00:00 2001 From: Aaron Rossetto Date: Thu, 4 Jun 2020 09:04:24 -0500 Subject: python: Add __repr__, property bindings to NocBlockBase This commit adds a __repr__ function to the noc_block_base bindings, which helpfully displays the block's unique ID, e.g.: >>> block = g.get_block('0/VectorIIR#0') >>> block Also added are get_property_ids and set_properties functions, so Python clients can set block properties by string if desired, e.g.: >>> block.get_property_ids() ['alpha', 'beta', 'delay', 'max_delay'] >>> block.set_properties('alpha=0.45,beta=0.77,delay=41') >>> viir = uhd.rfnoc.VectorIirBlockControl(block) >>> viir.get_alpha(0) 0.45 >>> viir.get_beta(0) 0.77 --- host/lib/rfnoc/rfnoc_python.hpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'host/lib/rfnoc') diff --git a/host/lib/rfnoc/rfnoc_python.hpp b/host/lib/rfnoc/rfnoc_python.hpp index 061fb8a9a..b0809a8b6 100644 --- a/host/lib/rfnoc/rfnoc_python.hpp +++ b/host/lib/rfnoc/rfnoc_python.hpp @@ -266,11 +266,23 @@ void export_rfnoc(py::module& m) .def("get_tick_rate", &noc_block_base::get_tick_rate) .def("get_mtu", &noc_block_base::get_mtu) .def("get_block_args", &noc_block_base::get_block_args) - .def("get_tree", [](noc_block_base::sptr& self) { - // Force the non-const `get_tree` - uhd::property_tree::sptr tree = self->get_tree(); - return tree; - }); + .def("get_tree", + [](noc_block_base::sptr& self) { + // Force the non-const `get_tree` + uhd::property_tree::sptr tree = self->get_tree(); + return tree; + }) + .def("__repr__", + [](noc_block_base::sptr& self) { + return "get_unique_id() + "'>"; + }) + // node_t superclass methods--not worth having a separate Py class + // for them + .def("get_property_ids", &node_t::get_property_ids) + .def("set_properties", + &node_t::set_properties, + py::arg("props"), + py::arg("instance") = 0); } #endif /* INCLUDED_UHD_RFNOC_PYTHON_HPP */ -- cgit v1.2.3