diff --git a/libevdev/const.py b/libevdev/const.py index b68c517869c95231f35cb462bf0576cdc77dbe8c..90610e9a6eca4226dba90f7aa67b61040b7bb944 100644 --- a/libevdev/const.py +++ b/libevdev/const.py @@ -65,6 +65,9 @@ class EvdevBit: def __lt__(self, other): return self.value < other.value + def __int__(self): + return self.value + class EventCode(EvdevBit): """ @@ -81,13 +84,16 @@ class EventCode(EvdevBit): ABS_X:0 >>> print(libevdev.EV_ABS.ABS_Y) ABS_X:1 - >>> code = libevdev.EV_REL.REL_X + >>> code = libevdev.EV_REL.REL_Y >>> print(code.type) EV_REL:2 + >>> int(code) + 1 .. attribute:: value - The numeric value of the event code + The numeric value of the event code. This value is also returned when + the object is converted to ``int``. .. attribute:: name @@ -140,6 +146,8 @@ class EventType(EvdevBit): EV_ABS:3 >>> print(libevdev.EV_ABS.ABS_X) ABS_X:0 + >>> print(int(libevdev.EV_ABS.ABS_Y)) + 1 >>> print(libevdev.EV_ABS.max) 63 >>> print(libevdev.EV_ABS.ABS_MAX) @@ -153,7 +161,8 @@ class EventType(EvdevBit): .. attribute:: value - The numeric value of the event type + The numeric value of the event type. This value is also returned when + the object is converted to ``int``. .. attribute:: name @@ -173,6 +182,9 @@ class EventType(EvdevBit): assert isinstance(other, EventType) return self.value == other.value + def __int__(self): + return self.value + class InputProperty(EvdevBit): """ @@ -186,11 +198,13 @@ class InputProperty(EvdevBit): >>> print(libevdev.INPUT_PROP_DIRECT) INPUT_PROP_DIRECT:1 - + >> int(libevdev.INPUT_PROP_DIRECT) + 1 .. attribute:: value - The numeric value of the property + The numeric value of the property. This value is also returned when + the object is converted to ``int``. .. attribute:: name diff --git a/test/test_const.py b/test/test_const.py index 44c0390f4af65332210d5f03b5d2708e058791f0..cd77748ab6fcac321598166f76b6303e646bee1d 100644 --- a/test/test_const.py +++ b/test/test_const.py @@ -55,6 +55,12 @@ class TestEventBits(unittest.TestCase): self.assertNotEqual(libevdev.EV_REL.REL_X, libevdev.EV_REL) self.assertNotEqual(libevdev.EV_ABS.ABS_X, libevdev.EV_ABS) + def test_int_conversion(self): + self.assertEqual(int(libevdev.EV_REL.REL_X), 0) + self.assertEqual(int(libevdev.EV_KEY.KEY_ESC), 1) + self.assertEqual(int(libevdev.EV_KEY), 0x1) + self.assertEqual(int(libevdev.INPUT_PROP_SEMI_MT), 3) + def test_evbit(self): self.assertEqual(evbit(0, 0), libevdev.EV_SYN.SYN_REPORT) self.assertEqual(evbit(1, 30), libevdev.EV_KEY.KEY_A)