[v2,3/3] py: Add bindings for ControlId vendor information
diff mbox series

Message ID 20241016111943.1411372-4-paul.elder@ideasonboard.com
State Accepted
Commit 79893cc00fc6b58d42c411164947b8876bc628c3
Headers show
Series
  • libcamera: controls: Add namespace to ControlId
Related show

Commit Message

Paul Elder Oct. 16, 2024, 11:19 a.m. UTC
Add python bindings for quering vendor information from a ControlId.
While at it, update __repr__ so that it also prints the vendor.

Example usage:
>>> cid
libcamera.ControlId(20, libcamera.Saturation, ControlType.Float)
>>> cid.vendor
'libcamera'

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
---
Changes in v2:
- reorder code so vendor comes immediately after name
- update repr
---
 src/py/libcamera/py_main.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Kieran Bingham Oct. 19, 2024, 10:08 p.m. UTC | #1
Quoting Paul Elder (2024-10-16 12:19:43)
> Add python bindings for quering vendor information from a ControlId.
> While at it, update __repr__ so that it also prints the vendor.
> 
> Example usage:
> >>> cid
> libcamera.ControlId(20, libcamera.Saturation, ControlType.Float)

Thanks!

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> >>> cid.vendor
> 'libcamera'
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
> ---
> Changes in v2:
> - reorder code so vendor comes immediately after name
> - update repr
> ---
>  src/py/libcamera/py_main.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
> index 983b76f6e998..09b6f9db0650 100644
> --- a/src/py/libcamera/py_main.cpp
> +++ b/src/py/libcamera/py_main.cpp
> @@ -399,11 +399,12 @@ PYBIND11_MODULE(_libcamera, m)
>         pyControlId
>                 .def_property_readonly("id", &ControlId::id)
>                 .def_property_readonly("name", &ControlId::name)
> +               .def_property_readonly("vendor", &ControlId::vendor)
>                 .def_property_readonly("type", &ControlId::type)
>                 .def("__str__", [](const ControlId &self) { return self.name(); })
>                 .def("__repr__", [](const ControlId &self) {
> -                       return py::str("libcamera.ControlId({}, {}, {})")
> -                               .format(self.id(), self.name(), self.type());
> +                       return py::str("libcamera.ControlId({}, {}.{}, {})")
> +                               .format(self.id(), self.vendor(), self.name(), self.type());
>                 })
>                 .def("enumerators", &ControlId::enumerators);
>  
> -- 
> 2.39.2
>
Laurent Pinchart Oct. 20, 2024, 9:19 p.m. UTC | #2
Hi Paul,

Thank you for the patch.

On Wed, Oct 16, 2024 at 08:19:43PM +0900, Paul Elder wrote:
> Add python bindings for quering vendor information from a ControlId.
> While at it, update __repr__ so that it also prints the vendor.
> 
> Example usage:
> >>> cid
> libcamera.ControlId(20, libcamera.Saturation, ControlType.Float)
> >>> cid.vendor
> 'libcamera'
> 
> Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
> Changes in v2:
> - reorder code so vendor comes immediately after name
> - update repr
> ---
>  src/py/libcamera/py_main.cpp | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
> index 983b76f6e998..09b6f9db0650 100644
> --- a/src/py/libcamera/py_main.cpp
> +++ b/src/py/libcamera/py_main.cpp
> @@ -399,11 +399,12 @@ PYBIND11_MODULE(_libcamera, m)
>  	pyControlId
>  		.def_property_readonly("id", &ControlId::id)
>  		.def_property_readonly("name", &ControlId::name)
> +		.def_property_readonly("vendor", &ControlId::vendor)
>  		.def_property_readonly("type", &ControlId::type)
>  		.def("__str__", [](const ControlId &self) { return self.name(); })
>  		.def("__repr__", [](const ControlId &self) {
> -			return py::str("libcamera.ControlId({}, {}, {})")
> -				.format(self.id(), self.name(), self.type());
> +			return py::str("libcamera.ControlId({}, {}.{}, {})")
> +				.format(self.id(), self.vendor(), self.name(), self.type());
>  		})
>  		.def("enumerators", &ControlId::enumerators);
>

Patch
diff mbox series

diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
index 983b76f6e998..09b6f9db0650 100644
--- a/src/py/libcamera/py_main.cpp
+++ b/src/py/libcamera/py_main.cpp
@@ -399,11 +399,12 @@  PYBIND11_MODULE(_libcamera, m)
 	pyControlId
 		.def_property_readonly("id", &ControlId::id)
 		.def_property_readonly("name", &ControlId::name)
+		.def_property_readonly("vendor", &ControlId::vendor)
 		.def_property_readonly("type", &ControlId::type)
 		.def("__str__", [](const ControlId &self) { return self.name(); })
 		.def("__repr__", [](const ControlId &self) {
-			return py::str("libcamera.ControlId({}, {}, {})")
-				.format(self.id(), self.name(), self.type());
+			return py::str("libcamera.ControlId({}, {}.{}, {})")
+				.format(self.id(), self.vendor(), self.name(), self.type());
 		})
 		.def("enumerators", &ControlId::enumerators);