[PATCH v4 3/3] py: Add bindings for ControlId enum name

Laurent Pinchart laurent.pinchart at ideasonboard.com
Wed Sep 25 22:55:54 CEST 2024


Hi Paul,

Thank you for the patch.

On Mon, Sep 16, 2024 at 01:24:20AM +0200, Paul Elder wrote:
> Add python bindings for querying enum value names from a ControlId.
> 
> Example usage:
> >>> cid
> libcamera.ControlId(16, AwbMode, ControlType.Integer32)
> >>> cid.enumerators()
> {0: 'AwbAuto', 1: 'AwbIncandescent', 2: 'AwbTungsten', 3: 'AwbFluorescent', 4: 'AwbIndoor', 5: 'AwbDaylight', 6: 'AwbCloudy', 7: 'AwbCustom'}
> >>> cinfo
> libcamera.ControlInfo([2..5])
> >>> cinfo.values
> [2, 3, 5]
> >>> [cid.enumerators()[v] for v in cinfo.values]
> ['AwbTungsten', 'AwbFluorescent', 'AwbDaylight']
> 
> Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>

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

> ---
> Changes in v4:
> - s/enum_str/enumerators/
> - s/enumToString/enumerators/
> - add example usage to commit message
> 
> Changes in v3:
> - s/enumName/enumToString/
> - s/enum_name/enum_str/
> 
> New in v2
> ---
>  src/py/libcamera/py_main.cpp | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/py/libcamera/py_main.cpp b/src/py/libcamera/py_main.cpp
> index ab33f38a8..983b76f6e 100644
> --- a/src/py/libcamera/py_main.cpp
> +++ b/src/py/libcamera/py_main.cpp
> @@ -404,7 +404,8 @@ PYBIND11_MODULE(_libcamera, m)
>  		.def("__repr__", [](const ControlId &self) {
>  			return py::str("libcamera.ControlId({}, {}, {})")
>  				.format(self.id(), self.name(), self.type());
> -		});
> +		})
> +		.def("enumerators", &ControlId::enumerators);
>  
>  	pyControlInfo
>  		.def_property_readonly("min", [](const ControlInfo &self) {

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list