use () instead of [] where possible
This commit is contained in:
parent
15cb97c56e
commit
5d4d0c07ad
|
@ -288,7 +288,7 @@ def make_notification(devnumber, data):
|
||||||
return _HIDPP_Notification(devnumber, sub_id, address, data[2:])
|
return _HIDPP_Notification(devnumber, sub_id, address, data[2:])
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
_HIDPP_Notification = namedtuple('_HIDPP_Notification', ['devnumber', 'sub_id', 'address', 'data'])
|
_HIDPP_Notification = namedtuple('_HIDPP_Notification', ('devnumber', 'sub_id', 'address', 'data'))
|
||||||
_HIDPP_Notification.__str__ = lambda self: 'Notification(%d,%02X,%02X,%s)' % (self.devnumber, self.sub_id, self.address, _strhex(self.data))
|
_HIDPP_Notification.__str__ = lambda self: 'Notification(%d,%02X,%02X,%s)' % (self.devnumber, self.sub_id, self.address, _strhex(self.data))
|
||||||
_HIDPP_Notification.__unicode__ = _HIDPP_Notification.__str__
|
_HIDPP_Notification.__unicode__ = _HIDPP_Notification.__str__
|
||||||
del namedtuple
|
del namedtuple
|
||||||
|
|
|
@ -99,7 +99,7 @@ class NamedInts(object):
|
||||||
if the value already exists in the set (int or string), ValueError will be
|
if the value already exists in the set (int or string), ValueError will be
|
||||||
raised.
|
raised.
|
||||||
"""
|
"""
|
||||||
__slots__ = ['__dict__', '_values', '_indexed', '_fallback']
|
__slots__ = ('__dict__', '_values', '_indexed', '_fallback')
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
def _readable_name(n):
|
def _readable_name(n):
|
||||||
|
|
|
@ -32,7 +32,7 @@ _R = _hidpp10.REGISTERS
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
_DeviceDescriptor = namedtuple('_DeviceDescriptor',
|
_DeviceDescriptor = namedtuple('_DeviceDescriptor',
|
||||||
['name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings'])
|
('name', 'kind', 'wpid', 'codename', 'protocol', 'registers', 'settings'))
|
||||||
del namedtuple
|
del namedtuple
|
||||||
|
|
||||||
DEVICES = {}
|
DEVICES = {}
|
||||||
|
|
|
@ -136,14 +136,14 @@ REGISTERS = _NamedInts(
|
||||||
#
|
#
|
||||||
|
|
||||||
def read_register(device, register_number, *params):
|
def read_register(device, register_number, *params):
|
||||||
assert device
|
assert device, 'tried to read register %02X from invalid device %s' % (register_number, device)
|
||||||
# support long registers by adding a 2 in front of the register number
|
# support long registers by adding a 2 in front of the register number
|
||||||
request_id = 0x8100 | (int(register_number) & 0x2FF)
|
request_id = 0x8100 | (int(register_number) & 0x2FF)
|
||||||
return device.request(request_id, *params)
|
return device.request(request_id, *params)
|
||||||
|
|
||||||
|
|
||||||
def write_register(device, register_number, *value):
|
def write_register(device, register_number, *value):
|
||||||
assert device
|
assert device, 'tried to write register %02X to invalid device %s' % (register_number, device)
|
||||||
# support long registers by adding a 2 in front of the register number
|
# support long registers by adding a 2 in front of the register number
|
||||||
request_id = 0x8000 | (int(register_number) & 0x2FF)
|
request_id = 0x8000 | (int(register_number) & 0x2FF)
|
||||||
return device.request(request_id, *value)
|
return device.request(request_id, *value)
|
||||||
|
|
|
@ -418,7 +418,7 @@ def get_mouse_pointer_info(device):
|
||||||
pointer_info = feature_request(device, FEATURE.MOUSE_POINTER)
|
pointer_info = feature_request(device, FEATURE.MOUSE_POINTER)
|
||||||
if pointer_info:
|
if pointer_info:
|
||||||
dpi, flags = _unpack('!HB', pointer_info[:3])
|
dpi, flags = _unpack('!HB', pointer_info[:3])
|
||||||
acceleration = ['none', 'low', 'med', 'high' ][flags & 0x3]
|
acceleration = ('none', 'low', 'med', 'high')[flags & 0x3]
|
||||||
suggest_os_ballistics = (flags & 0x04) != 0
|
suggest_os_ballistics = (flags & 0x04) != 0
|
||||||
suggest_vertical_orientation = (flags & 0x08) != 0
|
suggest_vertical_orientation = (flags & 0x08) != 0
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -45,7 +45,7 @@ class _ThreadedHandle(object):
|
||||||
Closing a ThreadedHandle will close all handles.
|
Closing a ThreadedHandle will close all handles.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = ['path', '_local', '_handles', '_listener']
|
__slots__ = ('path', '_local', '_handles', '_listener')
|
||||||
|
|
||||||
def __init__(self, listener, path, handle):
|
def __init__(self, listener, path, handle):
|
||||||
assert listener is not None
|
assert listener is not None
|
||||||
|
|
|
@ -41,8 +41,8 @@ KIND = _NamedInts(toggle=0x01, choice=0x02, range=0x12)
|
||||||
class Setting(object):
|
class Setting(object):
|
||||||
"""A setting descriptor.
|
"""A setting descriptor.
|
||||||
Needs to be instantiated for each specific device."""
|
Needs to be instantiated for each specific device."""
|
||||||
__slots__ = ['name', 'label', 'description', 'kind', 'persister', 'device_kind',
|
__slots__ = ('name', 'label', 'description', 'kind', 'persister', 'device_kind',
|
||||||
'_rw', '_validator', '_device', '_value']
|
'_rw', '_validator', '_device', '_value')
|
||||||
|
|
||||||
def __init__(self, name, rw, validator, kind=None, label=None, description=None, device_kind=None):
|
def __init__(self, name, rw, validator, kind=None, label=None, description=None, device_kind=None):
|
||||||
assert name
|
assert name
|
||||||
|
@ -163,7 +163,7 @@ class Setting(object):
|
||||||
#
|
#
|
||||||
|
|
||||||
class RegisterRW(object):
|
class RegisterRW(object):
|
||||||
__slots__ = ['register']
|
__slots__ = ('register', )
|
||||||
|
|
||||||
kind = _NamedInt(0x01, 'register')
|
kind = _NamedInt(0x01, 'register')
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ class RegisterRW(object):
|
||||||
|
|
||||||
|
|
||||||
class FeatureRW(object):
|
class FeatureRW(object):
|
||||||
__slots__ = ['feature', 'read_fnid', 'write_fnid']
|
__slots__ = ('feature', 'read_fnid', 'write_fnid')
|
||||||
|
|
||||||
kind = _NamedInt(0x02, 'feature')
|
kind = _NamedInt(0x02, 'feature')
|
||||||
default_read_fnid = 0x00
|
default_read_fnid = 0x00
|
||||||
|
@ -205,7 +205,7 @@ class FeatureRW(object):
|
||||||
#
|
#
|
||||||
|
|
||||||
class BooleanValidator(object):
|
class BooleanValidator(object):
|
||||||
__slots__ = ['true_value', 'false_value', 'mask', 'needs_current_value']
|
__slots__ = ('true_value', 'false_value', 'mask', 'needs_current_value')
|
||||||
|
|
||||||
kind = KIND.toggle
|
kind = KIND.toggle
|
||||||
default_true = 0x01
|
default_true = 0x01
|
||||||
|
@ -313,7 +313,7 @@ class BooleanValidator(object):
|
||||||
|
|
||||||
|
|
||||||
class ChoicesValidator(object):
|
class ChoicesValidator(object):
|
||||||
__slots__ = ['choices', 'flag', '_bytes_count', 'needs_current_value']
|
__slots__ = ('choices', 'flag', '_bytes_count', 'needs_current_value')
|
||||||
|
|
||||||
kind = KIND.choice
|
kind = KIND.choice
|
||||||
|
|
||||||
|
|
|
@ -323,9 +323,9 @@ def config_device(receiver, args):
|
||||||
try:
|
try:
|
||||||
value = bool(int(value))
|
value = bool(int(value))
|
||||||
except:
|
except:
|
||||||
if value.lower() in ['1', 'true', 'yes', 'on', 't', 'y']:
|
if value.lower() in ('1', 'true', 'yes', 'on', 't', 'y'):
|
||||||
value = True
|
value = True
|
||||||
elif value.lower() in ['0', 'false', 'no', 'off', 'f', 'n']:
|
elif value.lower() in ('0', 'false', 'no', 'off', 'f', 'n'):
|
||||||
value = False
|
value = False
|
||||||
else:
|
else:
|
||||||
_fail("don't know how to interpret '%s' as boolean" % value)
|
_fail("don't know how to interpret '%s' as boolean" % value)
|
||||||
|
@ -333,7 +333,7 @@ def config_device(receiver, args):
|
||||||
elif setting.choices:
|
elif setting.choices:
|
||||||
value = args.value.lower()
|
value = args.value.lower()
|
||||||
|
|
||||||
if value in ['higher', 'lower']:
|
if value in ('higher', 'lower'):
|
||||||
old_value = setting.read()
|
old_value = setting.read()
|
||||||
if old_value is None:
|
if old_value is None:
|
||||||
_fail("could not read current value of '%s'" % setting.name)
|
_fail("could not read current value of '%s'" % setting.name)
|
||||||
|
|
|
@ -38,7 +38,7 @@ from logitech_receiver import (
|
||||||
#
|
#
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
_GHOST_DEVICE = namedtuple('_GHOST_DEVICE', ['receiver', 'number', 'name', 'kind', 'status', 'online'])
|
_GHOST_DEVICE = namedtuple('_GHOST_DEVICE', ('receiver', 'number', 'name', 'kind', 'status', 'online'))
|
||||||
_GHOST_DEVICE.__bool__ = lambda self: False
|
_GHOST_DEVICE.__bool__ = lambda self: False
|
||||||
_GHOST_DEVICE.__nonzero__ = _GHOST_DEVICE.__bool__
|
_GHOST_DEVICE.__nonzero__ = _GHOST_DEVICE.__bool__
|
||||||
del namedtuple
|
del namedtuple
|
||||||
|
|
Loading…
Reference in New Issue