[PATCH evemu 4/7] python: replace input_prop_get_value/get_name with the C implementation
Peter Hutterer
peter.hutterer at who-t.net
Thu Aug 28 16:44:06 PDT 2014
Relying on an external lib removes the pain to maintain our own input.h
implementation.
The functions accept both strings and integer values in both directions of
conversion.
Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
python/evemu/__init__.py | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index aac64c6..65e4673 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -101,20 +101,28 @@ def input_prop_get_name(prop):
"""
Return the name of the input property, or None if undefined.
"""
- try:
- return evemu.event_names._input_prop_get_name(prop)
- except KeyError:
+ if not isinstance(prop, int):
+ prop = input_prop_get_value(prop)
+
+ if prop == None:
return None
+ prop = _libevdev.libevdev_property_get_name(prop)
+ return None if prop == 0 else prop
+
def input_prop_get_value(prop):
"""
Return the value of the input property, or None if undefined.
"""
- try:
- return evemu.event_names._input_prop_get_value(prop)
- except KeyError:
+ if isinstance(prop, int):
+ prop = input_prop_get_name(prop)
+
+ if prop == None:
return None
+ prop = _libevdev.libevdev_property_from_name(str(prop))
+ return None if prop < 0 else prop
+
class InputEvent(object):
__slots__ = 'sec', 'usec', 'type', 'code', 'value'
--
1.9.3
More information about the Input-tools
mailing list