[PATCH evemu 5/7] python: emulate input_prop_get_value without event_names.py
Peter Hutterer
peter.hutterer at who-t.net
Thu Aug 14 20:29:02 PDT 2014
On Thu, Aug 14, 2014 at 02:00:43PM -0400, Benjamin Tissoires wrote:
> libevdev does not provide currently a simple way to retrieve the max
> for the property bit, and the value given a property name.
patch is on the list
> Emulate this by creating a map dynamically when the function is first
> called.
>
> Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
> ---
> python/evemu/__init__.py | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
> index 882d91d..dea2be8 100644
> --- a/python/evemu/__init__.py
> +++ b/python/evemu/__init__.py
> @@ -107,12 +107,22 @@ def input_prop_get_name(prop):
> raise TypeError("expected an int")
> return _libevemu.evemu_property_get_name(prop)
>
> +__prop_dict = None
> +
> def input_prop_get_value(prop):
> """
> Return the value of the input property, or None if undefined.
> """
> + global __prop_dict
> + if not __prop_dict:
> + # libevdev does not give us this functionality, build a mapping table
> + __prop_dict = dict((input_prop_get_name(i), i) for i in xrange(0, 32) if input_prop_get_name(i))
I'd really prefer this with a named value
INPUT_PROP_MAX = 32
__prop_dict = ... xrange(0, INPUT_PROP_MAX) ...
btw, looks like the double underscore here doesn't do anything over a single
underscore, it seems to only mangle the name for class members.
Cheers,
Peter
> +
> + if type(prop) != str:
> + raise TypeError("expected a string")
> +
> try:
> - return evemu.event_names._input_prop_get_value(prop)
> + return __prop_dict[prop]
> except KeyError:
> return None
>
> --
> 2.0.4
More information about the Input-tools
mailing list