[v4,3/3] py: Add bindings for ControlId enum name
diff mbox series

Message ID 20240915232420.2106705-4-paul.elder@ideasonboard.com
State Accepted
Commit 505e49b76ed4f3040182f66a1c3884ea1648a612
Headers show
Series
  • libcamera: controls: Add enum information to ControlId
Related show

Commit Message

Paul Elder Sept. 15, 2024, 11:24 p.m. UTC
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@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@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(-)

Comments

Stefan Klug Sept. 16, 2024, 1:32 p.m. UTC | #1
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@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Stefan Klug <stefan.klug@ideasonboard.com> 

Cheers,
Stefam
> 
> ---
> 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) {
> -- 
> 2.39.2
>
Laurent Pinchart Sept. 25, 2024, 8:55 p.m. UTC | #2
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@ideasonboard.com>
> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@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) {

Patch
diff mbox series

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) {