Skip to content

Commit 43c6aaf

Browse files
committed
rename AbsInfo to AbsData
1 parent 0ab0698 commit 43c6aaf

5 files changed

Lines changed: 38 additions & 27 deletions

File tree

evdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Gather everything into a convenient namespace
44

5-
from evdev.device import DeviceInfo, InputDevice, AbsInfo
5+
from evdev.device import DeviceInfo, InputDevice, AbsData
66
from evdev.events import InputEvent, KeyEvent, RelEvent, SynEvent, AbsEvent, event_factory
77
from evdev.uinput import UInput, UInputError
88
from evdev.util import list_devices, categorize, resolve_ecodes

evdev/device.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,18 @@ def __eq__(self, o):
3232

3333

3434

35-
_AbsInfo = namedtuple('AbsInfo',
35+
_AbsData = namedtuple('AbsData',
3636
['min', 'max', 'fuzz', 'flat'])
3737

38-
class AbsInfo(_AbsInfo):
38+
class AbsData(_AbsData):
39+
'''
40+
A ``namedtuple`` for storing absolut axis information:
41+
42+
- min - minimal value for an absolute axis
43+
- max - maximum value for an absolute axis
44+
- fuzz - noise tolerance (+- value)
45+
- flat - size of the center flat position
46+
'''
3947
pass
4048

4149

@@ -70,17 +78,20 @@ def __init__(self, dev, nophys=False):
7078

7179
#: The physical topology of the device
7280
self.phys = info_res[5] if not nophys else ''
81+
self.phys = info_res[5]
82+
83+
#: The raw dictionary of device capabilities - see `:func:capabilities()`
7384
self._rawcapabilities = info_res[6]
7485

75-
def _capabilities(self, absinfo=True):
86+
def _capabilities(self, absdata=True):
7687
res = {}
7788
for etype, ecodes in self._rawcapabilities.items():
7889
for code in ecodes:
7990
l = res.setdefault(etype, [])
8091
if isinstance(code, tuple):
81-
if absinfo:
92+
if absdata:
8293
a = code[1] # (0, 0, 255, 0)
83-
i = AbsInfo(min=a[1], max=a[2], fuzz=a[3], flat=a[4])
94+
i = AbsData(min=a[1], max=a[2], fuzz=a[3], flat=a[4])
8495
l.append((code[0], i))
8596
else:
8697
l.append(code[0])
@@ -89,7 +100,7 @@ def _capabilities(self, absinfo=True):
89100

90101
return res
91102

92-
def capabilities(self, verbose=False, absinfo=True):
103+
def capabilities(self, verbose=False, absdata=True):
93104
'''
94105
Returns the event types that this device supports as a a mapping of
95106
supported event types to lists of handled event codes. Example::
@@ -105,24 +116,24 @@ def capabilities(self, verbose=False, absinfo=True):
105116
106117
Unknown codes or types will be resolved to '?'.
107118
108-
If ``absinfo`` is ``True``, the list of capabilities will also
119+
If ``absdata`` is ``True``, the list of capabilities will also
109120
include absolute axis information (``absmin``, ``absmax``,
110121
``absfuzz``, ``absflat``) in the following form::
111122
112-
{ 3 : [ (0, AbsInfo(min=0, max=255, fuzz=0, flat=0)),
113-
(1, AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}
123+
{ 3 : [ (0, AbsData(min=0, max=255, fuzz=0, flat=0)),
124+
(1, AbsData(min=0, max=255, fuzz=0, flat=0)) ]}
114125
115126
Combined with ``verbose`` the above becomes::
116127
117-
{ ('EV_ABS', 3) : [ (('ABS_X', 0), AbsInfo(min=0, max=255, fuzz=0, flat=0)),
118-
(('ABS_Y', 1), AbsInfo(min=0, max=255, fuzz=0, flat=0)) ]}
128+
{ ('EV_ABS', 3) : [ (('ABS_X', 0), AbsData(min=0, max=255, fuzz=0, flat=0)),
129+
(('ABS_Y', 1), AbsData(min=0, max=255, fuzz=0, flat=0)) ]}
119130
120131
'''
121132

122133
if verbose:
123-
return dict(util.resolve_ecodes(self._capabilities(absinfo)))
134+
return dict(util.resolve_ecodes(self._capabilities(absdata)))
124135
else:
125-
return self._capabilities(absinfo)
136+
return self._capabilities(absdata)
126137

127138
def __eq__(self, o):
128139
''' Two devices are considered equal if their :data:`info` attributes are equal. '''

evdev/uinput.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__(self,
7272
for etype, codes in events.items():
7373
for code in codes:
7474
# handle max,min,fuzz,flat
75-
if isinstance(code, (tuple, list, device.AbsInfo)):
75+
if isinstance(code, (tuple, list, device.AbsData)):
7676
# flatten (ABS_Y, (0,255,0,0)) to (ABS_Y,0,255,0,0)
7777
f = [code[0]] ; f += code[1]
7878
absdata.append(f)
@@ -164,9 +164,9 @@ def syn(self):
164164

165165
_uinput.write(self.fd, ecodes.EV_SYN, ecodes.SYN_REPORT, 0)
166166

167-
def capabilities(self, verbose=False, absinfo=True):
167+
def capabilities(self, verbose=False, absdata=True):
168168
'''See :func:`capabilities <evdev.device.InputDevice.capabilities>`.'''
169-
return self.device.capabilities(verbose, absinfo)
169+
return self.device.capabilities(verbose, absdata)
170170

171171
def _verify(self):
172172
''' Verify that an uinput device exists and is readable and writable

evdev/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def resolve_ecodes(typecodemap, unknown='?'):
6161
{ ('EV_KEY', 1) : [('BTN_MOUSE', 272), ('BTN_RIGHT', 273), ('BTN_MIDDLE', 274)] }
6262
6363
If the typecodemap contains absolute axis info (wrapped in
64-
instances of `AbsInfo <evdev.device.AbsInfo>`) the result would
64+
instances of `AbsData <evdev.device.AbsData>`) the result would
6565
look like::
6666
67-
resove_ecodes({ 3 : [(0, AbsInfo(...))] })
68-
{ ('EV_ABS', 3L): [(('ABS_X', 0L), AbsInfo(...))] }
67+
resove_ecodes({ 3 : [(0, AbsData(...))] })
68+
{ ('EV_ABS', 3L): [(('ABS_X', 0L), AbsData(...))] }
6969
'''
7070

7171
for etype, codes in typecodemap.items():
@@ -79,7 +79,7 @@ def resolve_ecodes(typecodemap, unknown='?'):
7979

8080
res = []
8181
for i in codes:
82-
# elements with AbsInfo(), eg { 3 : [(0, AbsInfo(...)), (1, AbsInfo(...))] }
82+
# elements with AbsData(), eg { 3 : [(0, AbsData(...)), (1, AbsData(...))] }
8383
if isinstance(i, tuple):
8484
l = ((code_names[i[0]], i[0]), i[1]) if i[0] in code_names \
8585
else ((unknown, i[0]), i[1])

tests/test_uinput.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ def test_abs_values(c):
6161
c['events'] = {
6262
e.EV_KEY : [e.KEY_A, e.KEY_B],
6363
e.EV_ABS : [(e.ABS_X, (0, 255, 0, 0)),
64-
(e.ABS_Y, device.AbsInfo(0, 255, 5, 10))],
64+
(e.ABS_Y, device.AbsData(0, 255, 5, 10))],
6565
}
6666

6767
with uinput.UInput(**c) as ui:
6868
c = ui.capabilities()
69-
assert c[e.EV_ABS][0] == (0L, device.AbsInfo(min=0, max=255, fuzz=0, flat=0))
70-
assert c[e.EV_ABS][1] == (1L, device.AbsInfo(min=0, max=255, fuzz=5, flat=10))
69+
assert c[e.EV_ABS][0] == (0L, device.AbsData(min=0, max=255, fuzz=0, flat=0))
70+
assert c[e.EV_ABS][1] == (1L, device.AbsData(min=0, max=255, fuzz=5, flat=10))
7171

7272
c = ui.capabilities(verbose=True)
73-
assert c[('EV_ABS', 3)][0] == (('ABS_X', 0L), device.AbsInfo(min=0, max=255, fuzz=0, flat=0))
73+
assert c[('EV_ABS', 3)][0] == (('ABS_X', 0L), device.AbsData(min=0, max=255, fuzz=0, flat=0))
7474

75-
c = ui.capabilities(verbose=False, absinfo=False)
76-
assert c[e.EV_ABS][0] == (0, 1)
75+
c = ui.capabilities(verbose=False, absdata=False)
76+
assert c[e.EV_ABS] == list((0, 1))
7777

7878
def test_write(c):
7979
with uinput.UInput(**c) as ui:

0 commit comments

Comments
 (0)