[PATCH evemu 2/7] python: replace event_get_value with the C implementation

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


No functional change, but relying on an external lib removes the
pain to maintain our own input.h implementation.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---
 python/evemu/__init__.py | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 02ff3a4..0797d73 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -35,6 +35,8 @@ __all__ = ["Device",
            "input_prop_get_value",
            "input_prop_get_name"]
 
+_libevemu = evemu.base.LibEvemu()
+
 def event_get_value(event_type, event_code = None):
     """
     Return the integer-value for the given event type and/or code string
@@ -44,10 +46,29 @@ def event_get_value(event_type, event_code = None):
     If an event code is passed, the event type may be given as integer or
     string.
     """
-    try:
-        return evemu.event_names._event_get_value(event_type, event_code)
-    except KeyError:
+    t = -1
+    c = -1
+
+    if type(event_type) == str:
+        t = _libevemu.evemu_event_type_from_name(event_type)
+    else:
+        t = event_type
+
+    if event_code == None:
+        if type(event_type) != str:
+            raise TypeError("expected a string")
+        if t < 0:
+            return None
+        return t
+
+    if type(event_code) != str:
+        raise TypeError("expected a string")
+
+    c = _libevemu.evemu_event_code_from_name(t, event_code)
+
+    if c < 0:
         return None
+    return c
 
 def event_get_name(event_type, event_code = None):
     """
-- 
2.0.4



More information about the Input-tools mailing list