[PATCH evemu 10/10] python: allow strings as event codes/types in evemu.Device
Peter Hutterer
peter.hutterer at who-t.net
Mon Aug 4 21:01:52 PDT 2014
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
python/evemu/__init__.py | 16 ++++++++++++++++
python/evemu/tests/test_device.py | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 656b744..ebb4443 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -272,26 +272,38 @@ class Device(object):
return self._libevemu.evemu_get_id_version(self._evemu_device)
def get_abs_minimum(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
return self._libevemu.evemu_get_abs_minimum(self._evemu_device,
event_code)
def get_abs_maximum(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
return self._libevemu.evemu_get_abs_maximum(self._evemu_device,
event_code)
def get_abs_fuzz(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
return self._libevemu.evemu_get_abs_fuzz(self._evemu_device,
event_code)
def get_abs_flat(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
return self._libevemu.evemu_get_abs_flat(self._evemu_device,
event_code)
def get_abs_resolution(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
return self._libevemu.evemu_get_abs_resolution(self._evemu_device,
event_code)
def has_prop(self, event_code):
+ if type(event_code) == str:
+ event_code = evemu.event_get_value("EV_ABS", event_code)
result = self._libevemu.evemu_has_prop(self._evemu_device, event_code)
return bool(result)
@@ -307,6 +319,10 @@ class Device(object):
used to simulate gestures for a higher number of touches than are
possible with just 2-touch hardware.
"""
+ if type(event_type) == str:
+ event_type = evemu.event_get_value(event_type)
+ if type(event_code) == str:
+ event_code = evemu.event_get_value(event_type, event_code)
result = self._libevemu.evemu_has_event(self._evemu_device,
event_type,
event_code)
diff --git a/python/evemu/tests/test_device.py b/python/evemu/tests/test_device.py
index c7b6162..4c555a4 100644
--- a/python/evemu/tests/test_device.py
+++ b/python/evemu/tests/test_device.py
@@ -183,36 +183,67 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
self.assertEqual(results, self.get_expected_abs("min"))
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_minimum(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_abs("min"))
+
def test_get_abs_maximum(self):
keys = evemu.const.absolute_axes.values()
results = dict((x, self._device.get_abs_maximum(x)) for x in keys)
self.assertEqual(results, self.get_expected_abs("max"))
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_maximum(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_abs("max"))
+
def test_get_abs_fuzz(self):
keys = evemu.const.absolute_axes.values()
results = dict((x, self._device.get_abs_fuzz(x)) for x in keys)
self.assertEqual(results, self.get_expected_abs("fuzz"))
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_fuzz(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_abs("fuzz"))
+
def test_get_abs_flat(self):
keys = evemu.const.absolute_axes.values()
results = dict((x, self._device.get_abs_flat(x)) for x in keys)
self.assertEqual(results, self.get_expected_abs("flat"))
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_flat(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_abs("flat"))
+
def test_get_abs_resolution(self):
keys = evemu.const.absolute_axes.values()
results = dict((x, self._device.get_abs_resolution(x)) for x in keys)
self.assertEqual(results, self.get_expected_abs("res"))
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.get_abs_resolution(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_abs("res"))
+
+
def test_has_prop(self):
keys = evemu.const.absolute_axes.values()
results = dict((x, self._device.has_prop(x)) for x in keys)
self.assertEqual(results, self.get_expected_propbits())
+ keys = evemu.const.absolute_axes.keys()
+ results = dict((evemu.event_get_value("EV_ABS", x), self._device.has_prop(x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_propbits())
+
def test_has_event_ev_abs(self):
ev_abs = evemu.const.event_types["EV_ABS"]
keys = evemu.const.absolute_axes.values()
@@ -227,6 +258,10 @@ class DevicePropertiesTestCase(evemu.testing.testcase.BaseTestCase):
self.assertEqual(results, self.get_expected_keybits())
+ keys = evemu.const.buttons.keys()
+ results = dict((evemu.event_get_value("EV_KEY", x), self._device.has_event("EV_KEY", x)) for x in keys)
+
+ self.assertEqual(results, self.get_expected_keybits())
if __name__ == "__main__":
unittest.main()
--
1.9.3
More information about the Input-tools
mailing list