[PATCH evemu 5/7] python: emulate input_prop_get_value without event_names.py

Benjamin Tissoires benjamin.tissoires at gmail.com
Thu Aug 14 11:00:43 PDT 2014


libevdev does not provide currently a simple way to retrieve the max
for the property bit, and the value given a property name.

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