[PATCH evemu 08/16] python: add wrappers to get input prop names/values
Peter Hutterer
peter.hutterer at who-t.net
Mon Aug 11 18:34:42 PDT 2014
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
python/evemu/__init__.py | 25 ++++++++++++++++++++++++-
python/evemu/make-event-names.py | 16 ++++++++++++++++
python/evemu/tests/test_device.py | 7 +++++++
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 928ef8d..8d7163f 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -29,7 +29,12 @@ import evemu.base
import evemu.const
import evemu.event_names
-__all__ = ["Device", "InputEvent", "event_get_value", "event_get_name"]
+__all__ = ["Device",
+ "InputEvent",
+ "event_get_value",
+ "event_get_name",
+ "input_prop_get_value",
+ "input_prop_get_name"]
def event_get_value(event_type, event_code = None):
"""
@@ -59,6 +64,24 @@ def event_get_name(event_type, event_code = None):
except KeyError:
return None
+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:
+ return None
+
+def input_prop_get_value(prop):
+ """
+ Return the name of the input property, or None if undefined.
+ """
+ try:
+ return evemu.event_names._input_prop_get_value(prop)
+ except KeyError:
+ return None
+
class InputEvent(object):
__slots__ = 'sec', 'usec', 'type', 'code', 'value'
diff --git a/python/evemu/make-event-names.py b/python/evemu/make-event-names.py
index 7a100d5..0e28ba9 100755
--- a/python/evemu/make-event-names.py
+++ b/python/evemu/make-event-names.py
@@ -130,6 +130,22 @@ def print_python_mapping_table(bits):
raise TypeError("expected a string")
return _type_map[event_type][event_code]
+
+ def _input_prop_get_name(prop):
+ '''
+ Returns the name of the input property.
+ '''
+ if type(prop) != int:
+ raise TypeError("expected an int")
+ return _input_prop_map[prop]
+
+ def _input_prop_get_value(prop):
+ '''
+ Returns the value of the input property.
+ '''
+ if type(prop) != str:
+ raise TypeError("expected a string")
+ return _input_prop_map[prop]
""")
def parse_define(bits, line):
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index 78fc7c1..3c16871 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -297,5 +297,12 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
self.assertEqual(evemu.event_get_name("EV_ABS", 0x00), "ABS_X")
self.assertEqual(evemu.event_get_name("EV_ABS", 0xFFFF), None)
+ def test_prop_names(self):
+ self.assertEqual(evemu.input_prop_get_value("INPUT_PROP_POINTER"), 0x00)
+ self.assertEqual(evemu.input_prop_get_value("INPUT_PROP_DIRECT"), 0x01)
+
+ self.assertEqual(evemu.input_prop_get_name(0x00), "INPUT_PROP_POINTER")
+ self.assertEqual(evemu.input_prop_get_name(0x01), "INPUT_PROP_DIRECT")
+
if __name__ == "__main__":
unittest.main()
--
1.9.3
More information about the Input-tools
mailing list