pre-commit: initial fix

Signed-off-by: Filipe Laíns <lains@archlinux.org>
This commit is contained in:
Filipe Laíns 2020-07-02 14:24:08 +01:00 committed by Filipe Laíns
parent 63fa581d13
commit 33521558ed
71 changed files with 804 additions and 816 deletions

View File

@ -111,4 +111,3 @@ Unifying Receiver
23: unknown:0034 , default: Do Nothing One => unknown:0034 23: unknown:0034 , default: Do Nothing One => unknown:0034
nonstandard, pos:0, group:0, gmask:0 nonstandard, pos:0, group:0, gmask:0
Battery: 0%, full. Battery: 0%, full.

View File

@ -40,4 +40,3 @@ Unifying Receiver
6: SLEEP => Sleep nonstandard, reprogrammable 6: SLEEP => Sleep nonstandard, reprogrammable
7: Calculator => Calculator nonstandard, reprogrammable 7: Calculator => Calculator nonstandard, reprogrammable
Battery: 90%, discharging. Battery: 90%, discharging.

View File

@ -46,4 +46,3 @@ Device path : /dev/hidraw3
2: MIDDLE BUTTON , default: MiddleMouseButton => MIDDLE BUTTON 2: MIDDLE BUTTON , default: MiddleMouseButton => MIDDLE BUTTON
divertable, mse, reprogrammable, pos:0, group:2, gmask:3 divertable, mse, reprogrammable, pos:0, group:2, gmask:3
Battery status unavailable. Battery status unavailable.

View File

@ -48,4 +48,3 @@ Unifying Receiver
2: MIDDLE BUTTON , default: MiddleMouseButton => MIDDLE BUTTON 2: MIDDLE BUTTON , default: MiddleMouseButton => MIDDLE BUTTON
divertable, mse, reprogrammable, pos:0, group:2, gmask:3 divertable, mse, reprogrammable, pos:0, group:2, gmask:3
Battery: 5%, discharging. Battery: 5%, discharging.

View File

@ -22,4 +22,3 @@ Unifying Receiver
The power switch is located on the base. The power switch is located on the base.
Notifications: battery status (0x100000). Notifications: battery status (0x100000).
Battery: 100%, discharging. Battery: 100%, discharging.

View File

@ -80,4 +80,3 @@ Unifying Receiver
7: unknown:00D7 , default: unknown:00B4 => unknown:00D7 7: unknown:00D7 , default: unknown:00B4 => unknown:00D7
divertable, virtual, pos:0, group:3, gmask:0 divertable, virtual, pos:0, group:3, gmask:0
Battery: 50%, discharging. Battery: 50%, discharging.

View File

@ -79,4 +79,3 @@ Unifying Receiver
1: RIGHT CLICK => RightClick mse, reprogrammable 1: RIGHT CLICK => RightClick mse, reprogrammable
2: MIDDLE BUTTON => MiddleMouseButton mse, reprogrammable 2: MIDDLE BUTTON => MiddleMouseButton mse, reprogrammable
Battery: 30%, discharging. Battery: 30%, discharging.

View File

@ -75,4 +75,3 @@ Unifying Receiver
10: Volume Down => Volume Down is FN 10: Volume Down => Volume Down is FN
11: Volume Up => Volume Up is FN 11: Volume Up => Volume Up is FN
Battery: 90%, discharging. Battery: 90%, discharging.

View File

@ -83,4 +83,3 @@ Unifying Receiver
1: RIGHT CLICK => RightClick mse, reprogrammable 1: RIGHT CLICK => RightClick mse, reprogrammable
2: MIDDLE BUTTON => MiddleMouseButton mse, reprogrammable 2: MIDDLE BUTTON => MiddleMouseButton mse, reprogrammable
Battery: 70%, discharging. Battery: 70%, discharging.

View File

@ -58,4 +58,3 @@ Unifying Receiver
The power switch is located on the top case. The power switch is located on the top case.
Notifications: (none). Notifications: (none).
Battery: full, discharging. Battery: full, discharging.

View File

@ -80,4 +80,3 @@ Unifying Receiver
7: unknown:00D7 , default: unknown:00B4 => unknown:00D7 7: unknown:00D7 , default: unknown:00B4 => unknown:00D7
divertable, virtual, pos:0, group:4, gmask:0 divertable, virtual, pos:0, group:4, gmask:0
Battery: 100%, discharging. Battery: 100%, discharging.

View File

@ -275,4 +275,3 @@ Index (same as command)
zz zz
(don't care, recommended to return 0) (don't care, recommended to return 0)

View File

@ -113,4 +113,3 @@ Solaar also has a command line interface that can do most of what can be
done using the Solaar main window. For more information on the Solaar done using the Solaar main window. For more information on the Solaar
command line interface, run `solaar --help` to see the Solaar commands and command line interface, run `solaar --help` to see the Solaar commands and
then `solaar <command> --help` to see the arguments to any of the commands. then `solaar <command> --help` to see the arguments to any of the commands.

View File

@ -108,7 +108,7 @@ def _continuous_read(handle, timeout=2000):
try: try:
reply = _hid.read(handle, 128, timeout) reply = _hid.read(handle, 128, timeout)
except OSError as e: except OSError as e:
_error("Read failed, aborting: " + str(e), True) _error('Read failed, aborting: ' + str(e), True)
break break
assert reply is not None assert reply is not None
if reply: if reply:
@ -119,25 +119,25 @@ def _validate_input(line, hidpp=False):
try: try:
data = unhexlify(line.encode('ascii')) data = unhexlify(line.encode('ascii'))
except Exception as e: except Exception as e:
_error("Invalid input: " + str(e)) _error('Invalid input: ' + str(e))
return None return None
if hidpp: if hidpp:
if len(data) < 4: if len(data) < 4:
_error("Invalid HID++ request: need at least 4 bytes") _error('Invalid HID++ request: need at least 4 bytes')
return None return None
if data[:1] not in b'\x10\x11': if data[:1] not in b'\x10\x11':
_error("Invalid HID++ request: first byte must be 0x10 or 0x11") _error('Invalid HID++ request: first byte must be 0x10 or 0x11')
return None return None
if data[1:2] not in b'\xFF\x01\x02\x03\x04\x05\x06': if data[1:2] not in b'\xFF\x01\x02\x03\x04\x05\x06':
_error( _error(
"Invalid HID++ request: second byte must be 0xFF or one of 0x01..0x06" 'Invalid HID++ request: second byte must be 0xFF or one of 0x01..0x06'
) )
return None return None
if data[:1] == b'\x10': if data[:1] == b'\x10':
if len(data) > 7: if len(data) > 7:
_error( _error(
"Invalid HID++ request: maximum length of a 0x10 request is 7 bytes" 'Invalid HID++ request: maximum length of a 0x10 request is 7 bytes'
) )
return None return None
while len(data) < 7: while len(data) < 7:
@ -145,7 +145,7 @@ def _validate_input(line, hidpp=False):
elif data[:1] == b'\x11': elif data[:1] == b'\x11':
if len(data) > 20: if len(data) > 20:
_error( _error(
"Invalid HID++ request: maximum length of a 0x11 request is 20 bytes" 'Invalid HID++ request: maximum length of a 0x11 request is 20 bytes'
) )
return None return None
while len(data) < 20: while len(data) < 20:
@ -162,27 +162,27 @@ def _open(args):
device = d.path device = d.path
break break
if not device: if not device:
sys.exit("!! No HID++ receiver found.") sys.exit('!! No HID++ receiver found.')
if not device: if not device:
sys.exit("!! Device path required.") sys.exit('!! Device path required.')
print(".. Opening device", device) print('.. Opening device', device)
handle = _hid.open_path(device) handle = _hid.open_path(device)
if not handle: if not handle:
sys.exit("!! Failed to open %s, aborting." % device) sys.exit('!! Failed to open %s, aborting.' % device)
print(".. Opened handle %r, vendor %r product %r serial %r." % print('.. Opened handle %r, vendor %r product %r serial %r.' %
(handle, _hid.get_manufacturer(handle), _hid.get_product(handle), (handle, _hid.get_manufacturer(handle), _hid.get_product(handle),
_hid.get_serial(handle))) _hid.get_serial(handle)))
if args.hidpp: if args.hidpp:
if _hid.get_manufacturer(handle) != b'Logitech': if _hid.get_manufacturer(handle) != b'Logitech':
sys.exit("!! Only Logitech devices support the HID++ protocol.") sys.exit('!! Only Logitech devices support the HID++ protocol.')
print(".. HID++ validation enabled.") print('.. HID++ validation enabled.')
else: else:
if (_hid.get_manufacturer(handle) == b'Logitech' if (_hid.get_manufacturer(handle) == b'Logitech'
and b'Receiver' in _hid.get_product(handle)): and b'Receiver' in _hid.get_product(handle)):
args.hidpp = True args.hidpp = True
print(".. Logitech receiver detected, HID++ validation enabled.") print('.. Logitech receiver detected, HID++ validation enabled.')
return handle return handle
@ -196,15 +196,15 @@ def _parse_arguments():
import argparse import argparse
arg_parser = argparse.ArgumentParser() arg_parser = argparse.ArgumentParser()
arg_parser.add_argument( arg_parser.add_argument(
'--history', help="history file (default ~/.hidconsole-history)") '--history', help='history file (default ~/.hidconsole-history)')
arg_parser.add_argument('--hidpp', arg_parser.add_argument('--hidpp',
action='store_true', action='store_true',
help="ensure input data is a valid HID++ request") help='ensure input data is a valid HID++ request')
arg_parser.add_argument( arg_parser.add_argument(
'device', 'device',
nargs='?', nargs='?',
help="linux device to connect to (/dev/hidrawX); " help='linux device to connect to (/dev/hidrawX); '
"may be omitted if --hidpp is given, in which case it looks for the first Logitech receiver" 'may be omitted if --hidpp is given, in which case it looks for the first Logitech receiver'
) )
return arg_parser.parse_args() return arg_parser.parse_args()
@ -215,7 +215,7 @@ def main():
if interactive: if interactive:
print( print(
".. Press ^C/^D to exit, or type hex bytes to write to the device." '.. Press ^C/^D to exit, or type hex bytes to write to the device.'
) )
import readline import readline
@ -264,12 +264,12 @@ def main():
time.sleep(0.700) time.sleep(0.700)
except EOFError: except EOFError:
if interactive: if interactive:
print("") print('')
else: else:
time.sleep(1) time.sleep(1)
finally: finally:
print(".. Closing handle %r" % handle) print('.. Closing handle %r' % handle)
_hid.close(handle) _hid.close(handle)
if interactive: if interactive:
readline.write_history_file(args.history) readline.write_history_file(args.history)

View File

@ -176,13 +176,13 @@ def write(handle, devnumber, data):
else: else:
wdata = _pack('!BB5s', 0x10, devnumber, data) wdata = _pack('!BB5s', 0x10, devnumber, data)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("(%s) <= w[%02X %02X %s %s]", handle, ord(wdata[:1]), _log.debug('(%s) <= w[%02X %02X %s %s]', handle, ord(wdata[:1]),
devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:])) devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:]))
try: try:
_hid.write(int(handle), wdata) _hid.write(int(handle), wdata)
except Exception as reason: except Exception as reason:
_log.error("write failed, assuming handle %r no longer available", _log.error('write failed, assuming handle %r no longer available',
handle) handle)
close(handle) close(handle)
raise NoReceiver(reason=reason) raise NoReceiver(reason=reason)
@ -214,7 +214,7 @@ def check_message(data):
if report_lengths.get(report_id) == len(data): if report_lengths.get(report_id) == len(data):
return True return True
else: else:
_log.warn("unexpected message size: report_id %02X message %s" % _log.warn('unexpected message size: report_id %02X message %s' %
(report_id, _strhex(data))) (report_id, _strhex(data)))
return False return False
@ -233,7 +233,7 @@ def _read(handle, timeout):
timeout = int(timeout * 1000) timeout = int(timeout * 1000)
data = _hid.read(int(handle), _MAX_READ_SIZE, timeout) data = _hid.read(int(handle), _MAX_READ_SIZE, timeout)
except Exception as reason: except Exception as reason:
_log.error("read failed, assuming handle %r no longer available", _log.error('read failed, assuming handle %r no longer available',
handle) handle)
close(handle) close(handle)
raise NoReceiver(reason=reason) raise NoReceiver(reason=reason)
@ -243,7 +243,7 @@ def _read(handle, timeout):
devnumber = ord(data[1:2]) devnumber = ord(data[1:2])
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("(%s) => r[%02X %02X %s %s]", handle, report_id, _log.debug('(%s) => r[%02X %02X %s %s]', handle, report_id,
devnumber, _strhex(data[2:4]), _strhex(data[4:])) devnumber, _strhex(data[2:4]), _strhex(data[4:]))
return report_id, devnumber, data[2:] return report_id, devnumber, data[2:]
@ -265,7 +265,7 @@ def _skip_incoming(handle, ihandle, notifications_hook):
# read whatever is already in the buffer, if any # read whatever is already in the buffer, if any
data = _hid.read(ihandle, _MAX_READ_SIZE, 0) data = _hid.read(ihandle, _MAX_READ_SIZE, 0)
except Exception as reason: except Exception as reason:
_log.error("read failed, assuming receiver %s no longer available", _log.error('read failed, assuming receiver %s no longer available',
handle) handle)
close(handle) close(handle)
raise NoReceiver(reason=reason) raise NoReceiver(reason=reason)
@ -389,7 +389,7 @@ def request(handle, devnumber, request_id, *params):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"(%s) device 0x%02X error on request {%04X}: %d = %s", '(%s) device 0x%02X error on request {%04X}: %d = %s',
handle, devnumber, request_id, error, handle, devnumber, request_id, error,
_hidpp10.ERROR[error]) _hidpp10.ERROR[error])
return return
@ -399,7 +399,7 @@ def request(handle, devnumber, request_id, *params):
# a HID++ 2.0 feature call returned with an error # a HID++ 2.0 feature call returned with an error
error = ord(reply_data[3:4]) error = ord(reply_data[3:4])
_log.error( _log.error(
"(%s) device %d error on feature request {%04X}: %d = %s", '(%s) device %d error on feature request {%04X}: %d = %s',
handle, devnumber, request_id, error, handle, devnumber, request_id, error,
_hidpp20.ERROR[error]) _hidpp20.ERROR[error])
raise _hidpp20.FeatureCallError(number=devnumber, raise _hidpp20.FeatureCallError(number=devnumber,
@ -445,7 +445,7 @@ def request(handle, devnumber, request_id, *params):
# if _log.isEnabledFor(_DEBUG): # if _log.isEnabledFor(_DEBUG):
# _log.debug("(%s) still waiting for reply, delta %f", handle, delta) # _log.debug("(%s) still waiting for reply, delta %f", handle, delta)
_log.warn("timeout (%0.2f/%0.2f) on device %d request {%04X} params [%s]", _log.warn('timeout (%0.2f/%0.2f) on device %d request {%04X} params [%s]',
delta, timeout, devnumber, request_id, _strhex(params)) delta, timeout, devnumber, request_id, _strhex(params))
# raise DeviceUnreachable(number=devnumber, request=request_id) # raise DeviceUnreachable(number=devnumber, request=request_id)
@ -456,7 +456,7 @@ def ping(handle, devnumber):
:returns: The HID protocol supported by the device, as a floating point number, if the device is active. :returns: The HID protocol supported by the device, as a floating point number, if the device is active.
""" """
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("(%s) pinging device %d", handle, devnumber) _log.debug('(%s) pinging device %d', handle, devnumber)
# import inspect as _inspect # import inspect as _inspect
# print ('\n '.join(str(s) for s in _inspect.stack())) # print ('\n '.join(str(s) for s in _inspect.stack()))
@ -504,7 +504,7 @@ def ping(handle, devnumber):
if error == _hidpp10.ERROR.unknown_device: # no paired device with that number if error == _hidpp10.ERROR.unknown_device: # no paired device with that number
_log.error( _log.error(
"(%s) device %d error on ping request: unknown device", '(%s) device %d error on ping request: unknown device',
handle, devnumber) handle, devnumber)
raise NoSuchDevice(number=devnumber, raise NoSuchDevice(number=devnumber,
request=request_id) request=request_id)
@ -518,6 +518,6 @@ def ping(handle, devnumber):
delta = _timestamp() - request_started delta = _timestamp() - request_started
_log.warn("(%s) timeout (%0.2f/%0.2f) on device %d ping", handle, delta, _log.warn('(%s) timeout (%0.2f/%0.2f) on device %d ping', handle, delta,
_PING_TIMEOUT, devnumber) _PING_TIMEOUT, devnumber)
# raise DeviceUnreachable(number=devnumber, request=request_id) # raise DeviceUnreachable(number=devnumber, request=request_id)

View File

@ -107,7 +107,7 @@ class NamedInts(object):
def __init__(self, **kwargs): def __init__(self, **kwargs):
def _readable_name(n): def _readable_name(n):
if not is_string(n): if not is_string(n):
raise TypeError("expected (unicode) string, got " + raise TypeError('expected (unicode) string, got ' +
str(type(n))) str(type(n)))
return n.replace('__', '/').replace('_', ' ') return n.replace('__', '/').replace('_', ' ')

View File

@ -202,7 +202,7 @@ def parse_battery_status(register, reply):
elif charging_byte & 0x22 == 0x22: elif charging_byte & 0x22 == 0x22:
status_text = BATTERY_STATUS.full status_text = BATTERY_STATUS.full
else: else:
_log.warn("could not parse 0x07 battery status: %02X (level %02X)", _log.warn('could not parse 0x07 battery status: %02X (level %02X)',
charging_byte, status_byte) charging_byte, status_byte)
status_text = None status_text = None

View File

@ -268,7 +268,7 @@ class FeaturesArray(object):
count = self.device.request(fs_index << 8) count = self.device.request(fs_index << 8)
if count is None: if count is None:
_log.warn( _log.warn(
"FEATURE_SET found, but failed to read features count" 'FEATURE_SET found, but failed to read features count'
) )
# most likely the device is unavailable # most likely the device is unavailable
return False return False
@ -348,7 +348,7 @@ class FeaturesArray(object):
self.features[index] = FEATURE[ivalue] self.features[index] = FEATURE[ivalue]
return index return index
raise ValueError("%r not in list" % featureId) raise ValueError('%r not in list' % featureId)
def __iter__(self): def __iter__(self):
if self._check(): if self._check():
@ -530,7 +530,7 @@ def get_name(device):
name += fragment[:name_length - len(name)] name += fragment[:name_length - len(name)]
else: else:
_log.error( _log.error(
"failed to read whole name of %s (expected %d chars)", 'failed to read whole name of %s (expected %d chars)',
device, name_length) device, name_length)
return None return None
@ -545,7 +545,7 @@ def get_battery(device):
discharge = None if discharge == 0 else discharge discharge = None if discharge == 0 else discharge
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"device %d battery %d%% charged, next level %d%% charge, status %d = %s", 'device %d battery %d%% charged, next level %d%% charge, status %d = %s',
device.number, discharge, dischargeNext, status, device.number, discharge, dischargeNext, status,
BATTERY_STATUS[status]) BATTERY_STATUS[status])
return discharge, BATTERY_STATUS[status], dischargeNext return discharge, BATTERY_STATUS[status], dischargeNext
@ -583,7 +583,7 @@ def decipher_voltage(voltage_report):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"device %d, battery voltage %d mV, charging = %s, charge status %d = %s, charge level %s, charge type %s", 'device %d, battery voltage %d mV, charging = %s, charge status %d = %s, charge level %s, charge type %s',
device.number, voltage, status, (flags & 0x03), charge_sts, device.number, voltage, status, (flags & 0x03), charge_sts,
charge_lvl, charge_type) charge_lvl, charge_type)

View File

@ -35,30 +35,30 @@ except:
_DUMMY = ( _DUMMY = (
# approximative battery levels # approximative battery levels
_("empty"), _('empty'),
_("critical"), _('critical'),
_("low"), _('low'),
_("good"), _('good'),
_("full"), _('full'),
# battery charging statuses # battery charging statuses
_("discharging"), _('discharging'),
_("recharging"), _('recharging'),
_("almost full"), _('almost full'),
_("charged"), _('charged'),
_("slow recharge"), _('slow recharge'),
_("invalid battery"), _('invalid battery'),
_("thermal error"), _('thermal error'),
# pairing errors # pairing errors
_("device timeout"), _('device timeout'),
_("device not supported"), _('device not supported'),
_("too many devices"), _('too many devices'),
_("sequence timeout"), _('sequence timeout'),
# firmware kinds # firmware kinds
_("Firmware"), _('Firmware'),
_("Bootloader"), _('Bootloader'),
_("Hardware"), _('Hardware'),
_("Other"), _('Other'),
) )

View File

@ -67,7 +67,7 @@ class _ThreadedHandle(object):
def _open(self): def _open(self):
handle = _base.open_path(self.path) handle = _base.open_path(self.path)
if handle is None: if handle is None:
_log.error("%r failed to open new handle", self) _log.error('%r failed to open new handle', self)
else: else:
# if _log.isEnabledFor(_DEBUG): # if _log.isEnabledFor(_DEBUG):
# _log.debug("%r opened new handle %d", self, handle) # _log.debug("%r opened new handle %d", self, handle)
@ -80,7 +80,7 @@ class _ThreadedHandle(object):
self._local = None self._local = None
handles, self._handles = self._handles, [] handles, self._handles = self._handles, []
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%r closing %s", self, handles) _log.debug('%r closing %s', self, handles)
for h in handles: for h in handles:
_base.close(h) _base.close(h)
@ -163,7 +163,7 @@ class EventsListener(_threading.Thread):
# get the right low-level handle for this thread # get the right low-level handle for this thread
ihandle = int(self.receiver.handle) ihandle = int(self.receiver.handle)
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("started with %s (%d)", self.receiver, ihandle) _log.info('started with %s (%d)', self.receiver, ihandle)
self.has_started() self.has_started()
@ -178,7 +178,7 @@ class EventsListener(_threading.Thread):
# _log.debug("read next notification") # _log.debug("read next notification")
n = _base.read(ihandle, _EVENT_READ_TIMEOUT) n = _base.read(ihandle, _EVENT_READ_TIMEOUT)
except _base.NoReceiver: except _base.NoReceiver:
_log.warning("receiver disconnected") _log.warning('receiver disconnected')
self.receiver.close() self.receiver.close()
break break
@ -194,7 +194,7 @@ class EventsListener(_threading.Thread):
try: try:
self._notifications_callback(n) self._notifications_callback(n)
except: except:
_log.exception("processing %s", n) _log.exception('processing %s', n)
# elif self.tick_period: # elif self.tick_period:
# idle_reads -= 1 # idle_reads -= 1

View File

@ -72,10 +72,10 @@ def _process_receiver_notification(receiver, status, n):
# pairing lock notification # pairing lock notification
if n.sub_id == 0x4A: if n.sub_id == 0x4A:
status.lock_open = bool(n.address & 0x01) status.lock_open = bool(n.address & 0x01)
reason = (_("pairing lock is open") reason = (_('pairing lock is open')
if status.lock_open else _("pairing lock is closed")) if status.lock_open else _('pairing lock is closed'))
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: %s", receiver, reason) _log.info('%s: %s', receiver, reason)
status[_K.ERROR] = None status[_K.ERROR] = None
if status.lock_open: if status.lock_open:
@ -86,12 +86,12 @@ def _process_receiver_notification(receiver, status, n):
status[ status[
_K.ERROR] = error_string = _hidpp10.PAIRING_ERRORS[pair_error] _K.ERROR] = error_string = _hidpp10.PAIRING_ERRORS[pair_error]
status.new_device = None status.new_device = None
_log.warn("pairing error %d: %s", pair_error, error_string) _log.warn('pairing error %d: %s', pair_error, error_string)
status.changed(reason=reason) status.changed(reason=reason)
return True return True
_log.warn("%s: unhandled notification %s", receiver, n) _log.warn('%s: unhandled notification %s', receiver, n)
# #
@ -124,7 +124,7 @@ def _process_device_notification(device, status, n):
try: try:
feature = device.features[n.sub_id] feature = device.features[n.sub_id]
except IndexError: except IndexError:
_log.warn("%s: notification from invalid feature index %02X: %s", _log.warn('%s: notification from invalid feature index %02X: %s',
device, n.sub_id, n) device, n.sub_id, n)
return False return False
@ -133,31 +133,31 @@ def _process_device_notification(device, status, n):
def _process_dj_notification(device, status, n): def _process_dj_notification(device, status, n):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s (%s) DJ notification %s", device, device.protocol, n) _log.debug('%s (%s) DJ notification %s', device, device.protocol, n)
if n.sub_id == 0x40: if n.sub_id == 0x40:
# do all DJ paired notifications also show up as HID++ 1.0 notifications? # do all DJ paired notifications also show up as HID++ 1.0 notifications?
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: ignoring DJ unpaired: %s", device, n) _log.info('%s: ignoring DJ unpaired: %s', device, n)
return True return True
if n.sub_id == 0x41: if n.sub_id == 0x41:
# do all DJ paired notifications also show up as HID++ 1.0 notifications? # do all DJ paired notifications also show up as HID++ 1.0 notifications?
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: ignoring DJ paired: %s", device, n) _log.info('%s: ignoring DJ paired: %s', device, n)
return True return True
if n.sub_id == 0x42: if n.sub_id == 0x42:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: ignoring DJ connection: %s", device, n) _log.info('%s: ignoring DJ connection: %s', device, n)
return True return True
_log.warn("%s: unrecognized DJ %s", device, n) _log.warn('%s: unrecognized DJ %s', device, n)
def _process_hidpp10_custom_notification(device, status, n): def _process_hidpp10_custom_notification(device, status, n):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s (%s) custom notification %s", device, device.protocol, _log.debug('%s (%s) custom notification %s', device, device.protocol,
n) n)
if n.sub_id in (_R.battery_status, _R.battery_charge): if n.sub_id in (_R.battery_status, _R.battery_charge):
@ -172,10 +172,10 @@ def _process_hidpp10_custom_notification(device, status, n):
# message layout: 10 ix 17("address") <??> <?> <??> <light level 1=off..5=max> # message layout: 10 ix 17("address") <??> <?> <??> <light level 1=off..5=max>
# TODO anything we can do with this? # TODO anything we can do with this?
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("illumination event: %s", n) _log.info('illumination event: %s', n)
return True return True
_log.warn("%s: unrecognized %s", device, n) _log.warn('%s: unrecognized %s', device, n)
def _process_hidpp10_notification(device, status, n): def _process_hidpp10_notification(device, status, n):
@ -190,9 +190,9 @@ def _process_hidpp10_notification(device, status, n):
del device.receiver[device.number] del device.receiver[device.number]
status.changed(active=False, status.changed(active=False,
alert=_ALERT.ALL, alert=_ALERT.ALL,
reason=_("unpaired")) reason=_('unpaired'))
else: else:
_log.warn("%s: disconnection with unknown type %02X: %s", device, _log.warn('%s: disconnection with unknown type %02X: %s', device,
n.address, n) n.address, n)
return True return True
@ -211,7 +211,7 @@ def _process_hidpp10_notification(device, status, n):
if protocol_name: if protocol_name:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
wpid = _strhex(n.data[2:3] + n.data[1:2]) wpid = _strhex(n.data[2:3] + n.data[1:2])
assert wpid == device.wpid, "%s wpid mismatch, got %s" % ( assert wpid == device.wpid, '%s wpid mismatch, got %s' % (
device, wpid) device, wpid)
flags = ord(n.data[:1]) & 0xF0 flags = ord(n.data[:1]) & 0xF0
@ -221,14 +221,14 @@ def _process_hidpp10_notification(device, status, n):
sw_present = bool(flags & 0x10) sw_present = bool(flags & 0x10)
has_payload = bool(flags & 0x80) has_payload = bool(flags & 0x80)
_log.debug( _log.debug(
"%s: %s connection notification: software=%s, encrypted=%s, link=%s, payload=%s", '%s: %s connection notification: software=%s, encrypted=%s, link=%s, payload=%s',
device, protocol_name, sw_present, link_encrypted, device, protocol_name, sw_present, link_encrypted,
link_established, has_payload) link_established, has_payload)
status[_K.LINK_ENCRYPTED] = link_encrypted status[_K.LINK_ENCRYPTED] = link_encrypted
status.changed(active=link_established) status.changed(active=link_established)
else: else:
_log.warn( _log.warn(
"%s: connection notification with unknown protocol %02X: %s", '%s: connection notification with unknown protocol %02X: %s',
device.number, n.address, n) device.number, n.address, n)
return True return True
@ -244,16 +244,16 @@ def _process_hidpp10_notification(device, status, n):
if n.sub_id == 0x4B: if n.sub_id == 0x4B:
if n.address == 0x01: if n.address == 0x01:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: device powered on", device) _log.debug('%s: device powered on', device)
reason = status.to_string() or _("powered on") reason = status.to_string() or _('powered on')
status.changed(active=True, status.changed(active=True,
alert=_ALERT.NOTIFICATION, alert=_ALERT.NOTIFICATION,
reason=reason) reason=reason)
else: else:
_log.warn("%s: unknown %s", device, n) _log.warn('%s: unknown %s', device, n)
return True return True
_log.warn("%s: unrecognized %s", device, n) _log.warn('%s: unrecognized %s', device, n)
def _process_feature_notification(device, status, n, feature): def _process_feature_notification(device, status, n, feature):
@ -267,7 +267,7 @@ def _process_feature_notification(device, status, n, feature):
_hidpp20.BATTERY_STATUS[battery_status], _hidpp20.BATTERY_STATUS[battery_status],
discharge_next_level) discharge_next_level)
else: else:
_log.warn("%s: unknown BATTERY %s", device, n) _log.warn('%s: unknown BATTERY %s', device, n)
return True return True
if feature == _F.BATTERY_VOLTAGE: if feature == _F.BATTERY_VOLTAGE:
@ -276,30 +276,30 @@ def _process_feature_notification(device, status, n, feature):
n.data) n.data)
status.set_battery_info(level, status, None, voltage) status.set_battery_info(level, status, None, voltage)
else: else:
_log.warn("%s: unknown VOLTAGE %s", device, n) _log.warn('%s: unknown VOLTAGE %s', device, n)
return True return True
# TODO: what are REPROG_CONTROLS_V{2,3}? # TODO: what are REPROG_CONTROLS_V{2,3}?
if feature == _F.REPROG_CONTROLS: if feature == _F.REPROG_CONTROLS:
if n.address == 0x00: if n.address == 0x00:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: reprogrammable key: %s", device, n) _log.info('%s: reprogrammable key: %s', device, n)
else: else:
_log.warn("%s: unknown REPROGRAMMABLE KEYS %s", device, n) _log.warn('%s: unknown REPROGRAMMABLE KEYS %s', device, n)
return True return True
if feature == _F.WIRELESS_DEVICE_STATUS: if feature == _F.WIRELESS_DEVICE_STATUS:
if n.address == 0x00: if n.address == 0x00:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("wireless status: %s", n) _log.debug('wireless status: %s', n)
if n.data[0:3] == b'\x01\x01\x01': if n.data[0:3] == b'\x01\x01\x01':
status.changed(active=True, status.changed(active=True,
alert=_ALERT.NOTIFICATION, alert=_ALERT.NOTIFICATION,
reason='powered on') reason='powered on')
else: else:
_log.warn("%s: unknown WIRELESS %s", device, n) _log.warn('%s: unknown WIRELESS %s', device, n)
else: else:
_log.warn("%s: unknown WIRELESS %s", device, n) _log.warn('%s: unknown WIRELESS %s', device, n)
return True return True
if feature == _F.SOLAR_DASHBOARD: if feature == _F.SOLAR_DASHBOARD:
@ -319,7 +319,7 @@ def _process_feature_notification(device, status, n, feature):
status.set_battery_info(charge, status_text, None) status.set_battery_info(charge, status_text, None)
elif n.address == 0x20: elif n.address == 0x20:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: Light Check button pressed", device) _log.debug('%s: Light Check button pressed', device)
status.changed(alert=_ALERT.SHOW_WINDOW) status.changed(alert=_ALERT.SHOW_WINDOW)
# first cancel any reporting # first cancel any reporting
# device.feature_request(_F.SOLAR_DASHBOARD) # device.feature_request(_F.SOLAR_DASHBOARD)
@ -329,25 +329,25 @@ def _process_feature_notification(device, status, n, feature):
device.feature_request(_F.SOLAR_DASHBOARD, 0x00, reports_count, device.feature_request(_F.SOLAR_DASHBOARD, 0x00, reports_count,
reports_period) reports_period)
else: else:
_log.warn("%s: unknown SOLAR CHARGE %s", device, n) _log.warn('%s: unknown SOLAR CHARGE %s', device, n)
else: else:
_log.warn("%s: SOLAR CHARGE not GOOD? %s", device, n) _log.warn('%s: SOLAR CHARGE not GOOD? %s', device, n)
return True return True
if feature == _F.TOUCHMOUSE_RAW_POINTS: if feature == _F.TOUCHMOUSE_RAW_POINTS:
if n.address == 0x00: if n.address == 0x00:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: TOUCH MOUSE points %s", device, n) _log.info('%s: TOUCH MOUSE points %s', device, n)
elif n.address == 0x10: elif n.address == 0x10:
touch = ord(n.data[:1]) touch = ord(n.data[:1])
button_down = bool(touch & 0x02) button_down = bool(touch & 0x02)
mouse_lifted = bool(touch & 0x01) mouse_lifted = bool(touch & 0x01)
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info( _log.info(
"%s: TOUCH MOUSE status: button_down=%s mouse_lifted=%s", '%s: TOUCH MOUSE status: button_down=%s mouse_lifted=%s',
device, button_down, mouse_lifted) device, button_down, mouse_lifted)
else: else:
_log.warn("%s: unknown TOUCH MOUSE %s", device, n) _log.warn('%s: unknown TOUCH MOUSE %s', device, n)
return True return True
if feature == _F.HIRES_WHEEL: if feature == _F.HIRES_WHEEL:
@ -356,18 +356,18 @@ def _process_feature_notification(device, status, n, feature):
flags, delta_v = _unpack('>bh', n.data[:3]) flags, delta_v = _unpack('>bh', n.data[:3])
high_res = (flags & 0x10) != 0 high_res = (flags & 0x10) != 0
periods = flags & 0x0f periods = flags & 0x0f
_log.info("%s: WHEEL: res: %d periods: %d delta V:%-3d", _log.info('%s: WHEEL: res: %d periods: %d delta V:%-3d',
device, high_res, periods, delta_v) device, high_res, periods, delta_v)
return True return True
elif (n.address == 0x10): elif (n.address == 0x10):
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
flags = ord(n.data[:1]) flags = ord(n.data[:1])
ratchet = flags & 0x01 ratchet = flags & 0x01
_log.info("%s: WHEEL: ratchet: %d", device, ratchet) _log.info('%s: WHEEL: ratchet: %d', device, ratchet)
return True return True
else: else:
_log.warn("%s: unknown WHEEL %s", device, n) _log.warn('%s: unknown WHEEL %s', device, n)
return True return True
_log.warn("%s: unrecognized %s for feature %s (index %02X)", device, n, _log.warn('%s: unrecognized %s for feature %s (index %02X)', device, n,
feature, n.sub_id) feature, n.sub_id)

View File

@ -106,19 +106,19 @@ class PairedDevice(object):
device_info = self.receiver.read_register( device_info = self.receiver.read_register(
_R.receiver_info, 0x04) _R.receiver_info, 0x04)
if device_info is None: if device_info is None:
_log.error("failed to read Nano wpid for device %d of %s", _log.error('failed to read Nano wpid for device %d of %s',
number, receiver) number, receiver)
raise _base.NoSuchDevice(number=number, raise _base.NoSuchDevice(number=number,
receiver=receiver, receiver=receiver,
error="read Nano wpid") error='read Nano wpid')
self.wpid = _strhex(device_info[3:5]) self.wpid = _strhex(device_info[3:5])
self._polling_rate = 0 self._polling_rate = 0
self._power_switch = '(' + _("unknown") + ')' self._power_switch = '(' + _('unknown') + ')'
# the wpid is necessary to properly identify wireless link on/off notifications # the wpid is necessary to properly identify wireless link on/off notifications
# also it gets set to None on this object when the device is unpaired # also it gets set to None on this object when the device is unpaired
assert self.wpid is not None, "failed to read wpid: device %d of %s" % ( assert self.wpid is not None, 'failed to read wpid: device %d of %s' % (
number, receiver) number, receiver)
self.descriptor = _DESCRIPTORS.get(self.wpid) self.descriptor = _DESCRIPTORS.get(self.wpid)
@ -289,14 +289,14 @@ class PairedDevice(object):
set_flag_bits = 0 set_flag_bits = 0
ok = _hidpp10.set_notification_flags(self, set_flag_bits) ok = _hidpp10.set_notification_flags(self, set_flag_bits)
if ok is None: if ok is None:
_log.warn("%s: failed to %s device notifications", self, _log.warn('%s: failed to %s device notifications', self,
'enable' if enable else 'disable') 'enable' if enable else 'disable')
flag_bits = _hidpp10.get_notification_flags(self) flag_bits = _hidpp10.get_notification_flags(self)
flag_names = None if flag_bits is None else tuple( flag_names = None if flag_bits is None else tuple(
_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)) _hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: device notifications %s %s", self, _log.info('%s: device notifications %s %s', self,
'enabled' if enable else 'disabled', flag_names) 'enabled' if enable else 'disabled', flag_names)
return flag_bits if ok else None return flag_bits if ok else None
@ -364,7 +364,7 @@ class Receiver(object):
self.product_id = device_info.product_id self.product_id = device_info.product_id
product_info = _product_information(self.product_id) product_info = _product_information(self.product_id)
if not product_info: if not product_info:
raise Exception("Unknown receiver type", self.product_id) raise Exception('Unknown receiver type', self.product_id)
# read the serial immediately, so we can find out max_devices # read the serial immediately, so we can find out max_devices
serial_reply = self.read_register(_R.receiver_info, 0x03) serial_reply = self.read_register(_R.receiver_info, 0x03)
@ -426,7 +426,7 @@ class Receiver(object):
set_flag_bits = 0 set_flag_bits = 0
ok = _hidpp10.set_notification_flags(self, set_flag_bits) ok = _hidpp10.set_notification_flags(self, set_flag_bits)
if ok is None: if ok is None:
_log.warn("%s: failed to %s receiver notifications", self, _log.warn('%s: failed to %s receiver notifications', self,
'enable' if enable else 'disable') 'enable' if enable else 'disable')
return None return None
@ -434,7 +434,7 @@ class Receiver(object):
flag_names = None if flag_bits is None else tuple( flag_names = None if flag_bits is None else tuple(
_hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits)) _hidpp10.NOTIFICATION_FLAG.flag_names(flag_bits))
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: receiver notifications %s => %s", self, _log.info('%s: receiver notifications %s => %s', self,
'enabled' if enable else 'disabled', flag_names) 'enabled' if enable else 'disabled', flag_names)
return flag_bits return flag_bits
@ -442,12 +442,12 @@ class Receiver(object):
"""Scan all devices.""" """Scan all devices."""
if self.handle: if self.handle:
if not self.write_register(_R.receiver_connection, 0x02): if not self.write_register(_R.receiver_connection, 0x02):
_log.warn("%s: failed to trigger device link notifications", _log.warn('%s: failed to trigger device link notifications',
self) self)
def register_new_device(self, number, notification=None): def register_new_device(self, number, notification=None):
if self._devices.get(number) is not None: if self._devices.get(number) is not None:
raise IndexError("%s: device number %d already registered" % raise IndexError('%s: device number %d already registered' %
(self, number)) (self, number))
assert notification is None or notification.devnumber == number assert notification is None or notification.devnumber == number
@ -457,14 +457,14 @@ class Receiver(object):
dev = PairedDevice(self, number, notification) dev = PairedDevice(self, number, notification)
assert dev.wpid assert dev.wpid
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: found new device %d (%s)", self, number, _log.info('%s: found new device %d (%s)', self, number,
dev.wpid) dev.wpid)
self._devices[number] = dev self._devices[number] = dev
return dev return dev
except _base.NoSuchDevice: except _base.NoSuchDevice:
_log.exception("register_new_device") _log.exception('register_new_device')
_log.warning("%s: looked for device %d, not found", self, number) _log.warning('%s: looked for device %d, not found', self, number)
self._devices[number] = None self._devices[number] = None
def set_lock(self, lock_closed=True, device=0, timeout=0): def set_lock(self, lock_closed=True, device=0, timeout=0):
@ -474,7 +474,7 @@ class Receiver(object):
timeout) timeout)
if reply: if reply:
return True return True
_log.warn("%s: failed to %s the receiver lock", self, _log.warn('%s: failed to %s the receiver lock', self,
'close' if lock_closed else 'open') 'close' if lock_closed else 'open')
def count(self): def count(self):
@ -536,7 +536,7 @@ class Receiver(object):
dev.wpid = None dev.wpid = None
if key in self._devices: if key in self._devices:
del self._devices[key] del self._devices[key]
_log.warn("%s removed device %s", self, dev) _log.warn('%s removed device %s', self, dev)
else: else:
reply = self.write_register(_R.receiver_pairing, 0x03, key) reply = self.write_register(_R.receiver_pairing, 0x03, key)
if reply: if reply:
@ -545,9 +545,9 @@ class Receiver(object):
dev.wpid = None dev.wpid = None
if key in self._devices: if key in self._devices:
del self._devices[key] del self._devices[key]
_log.warn("%s unpaired device %s", self, dev) _log.warn('%s unpaired device %s', self, dev)
else: else:
_log.error("%s failed to unpair device %s", self, dev) _log.error('%s failed to unpair device %s', self, dev)
raise IndexError(key) raise IndexError(key)
def __len__(self): def __len__(self):
@ -586,8 +586,8 @@ class Receiver(object):
if handle: if handle:
return Receiver(handle, device_info) return Receiver(handle, device_info)
except OSError as e: except OSError as e:
_log.exception("open %s", device_info) _log.exception('open %s', device_info)
if e.errno == _errno.EACCES: if e.errno == _errno.EACCES:
raise raise
except: except:
_log.exception("open %s", device_info) _log.exception('open %s', device_info)

View File

@ -110,7 +110,7 @@ class Setting(object):
assert hasattr(self, '_device') assert hasattr(self, '_device')
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings read %r from %s", self.name, self._value, _log.debug('%s: settings read %r from %s', self.name, self._value,
self._device) self._device)
if self._value is None and self._device.persister: if self._value is None and self._device.persister:
@ -141,7 +141,7 @@ class Setting(object):
assert value is not None assert value is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings write %r to %s", self.name, value, _log.debug('%s: settings write %r to %s', self.name, value,
self._device) self._device)
if self._device.online: if self._device.online:
@ -160,7 +160,7 @@ class Setting(object):
data_bytes = self._validator.prepare_write(value, current_value) data_bytes = self._validator.prepare_write(value, current_value)
if data_bytes is not None: if data_bytes is not None:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings prepare write(%s) => %r", _log.debug('%s: settings prepare write(%s) => %r',
self.name, value, data_bytes) self.name, value, data_bytes)
reply = self._rw.write(self._device, data_bytes) reply = self._rw.write(self._device, data_bytes)
@ -175,7 +175,7 @@ class Setting(object):
assert hasattr(self, '_device') assert hasattr(self, '_device')
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: apply %s (%s)", self.name, self._value, _log.debug('%s: apply %s (%s)', self.name, self._value,
self._device) self._device)
value = self.read() value = self.read()
@ -202,7 +202,7 @@ class Settings(Setting):
assert hasattr(self, '_device') assert hasattr(self, '_device')
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings read %r from %s", self.name, self._value, _log.debug('%s: settings read %r from %s', self.name, self._value,
self._device) self._device)
if self._value is None and getattr(self._device, 'persister', None): if self._value is None and getattr(self._device, 'persister', None):
@ -219,7 +219,7 @@ class Settings(Setting):
return self._value return self._value
if self._device.online: if self._device.online:
reply_map = dict() reply_map = {}
for key, value in self._validator.choices.items(): for key, value in self._validator.choices.items():
reply = self._rw.read(self._device, key) reply = self._rw.read(self._device, key)
if reply: if reply:
@ -241,7 +241,7 @@ class Settings(Setting):
assert key is not None assert key is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings read %r key %r from %s", self.name, _log.debug('%s: settings read %r key %r from %s', self.name,
self._value, key, self._device) self._value, key, self._device)
if self._value is None and getattr(self._device, 'persister', None): if self._value is None and getattr(self._device, 'persister', None):
@ -269,7 +269,7 @@ class Settings(Setting):
assert map is not None assert map is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings write %r to %s", self.name, map, _log.debug('%s: settings write %r to %s', self.name, map,
self._device) self._device)
if self._device.online: if self._device.online:
@ -285,7 +285,7 @@ class Settings(Setting):
if data_bytes is not None: if data_bytes is not None:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"%s: settings prepare map write(%s,%s) => %r", '%s: settings prepare map write(%s,%s) => %r',
self.name, key, value, data_bytes) self.name, key, value, data_bytes)
reply = self._rw.write(self._device, int(key), data_bytes) reply = self._rw.write(self._device, int(key), data_bytes)
if not reply: if not reply:
@ -300,7 +300,7 @@ class Settings(Setting):
assert value is not None assert value is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings write key %r value %r to %s", self.name, _log.debug('%s: settings write key %r value %r to %s', self.name,
key, value, self._device) key, value, self._device)
if self._device.online: if self._device.online:
@ -315,7 +315,7 @@ class Settings(Setting):
if data_bytes is not None: if data_bytes is not None:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"%s: settings prepare key value write(%s,%s) => %r", '%s: settings prepare key value write(%s,%s) => %r',
self.name, key, value, data_bytes) self.name, key, value, data_bytes)
reply = self._rw.write(self._device, int(key), data_bytes) reply = self._rw.write(self._device, int(key), data_bytes)
if not reply: if not reply:
@ -333,7 +333,7 @@ class BitFieldSetting(Setting):
assert hasattr(self, '_device') assert hasattr(self, '_device')
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings read %r from %s", self.name, self._value, _log.debug('%s: settings read %r from %s', self.name, self._value,
self._device) self._device)
if self._value is None and getattr(self._device, 'persister', None): if self._value is None and getattr(self._device, 'persister', None):
@ -350,7 +350,7 @@ class BitFieldSetting(Setting):
return self._value return self._value
if self._device.online: if self._device.online:
reply_map = dict() reply_map = {}
reply = self._rw.read(self._device) reply = self._rw.read(self._device)
if reply: if reply:
# keys are ints, because that is what the device uses, # keys are ints, because that is what the device uses,
@ -370,7 +370,7 @@ class BitFieldSetting(Setting):
assert key is not None assert key is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings read %r key %r from %s", self.name, _log.debug('%s: settings read %r key %r from %s', self.name,
self._value, key, self._device) self._value, key, self._device)
if self._value is None and getattr(self._device, 'persister', None): if self._value is None and getattr(self._device, 'persister', None):
@ -397,7 +397,7 @@ class BitFieldSetting(Setting):
assert map is not None assert map is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings write %r to %s", self.name, map, _log.debug('%s: settings write %r to %s', self.name, map,
self._device) self._device)
if self._device.online: if self._device.online:
@ -410,7 +410,7 @@ class BitFieldSetting(Setting):
data_bytes = self._validator.prepare_write(self._value) data_bytes = self._validator.prepare_write(self._value)
if data_bytes is not None: if data_bytes is not None:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings prepare map write(%s) => %r", _log.debug('%s: settings prepare map write(%s) => %r',
self.name, self._value, data_bytes) self.name, self._value, data_bytes)
reply = self._rw.write(self._device, data_bytes) reply = self._rw.write(self._device, data_bytes)
if not reply: if not reply:
@ -424,7 +424,7 @@ class BitFieldSetting(Setting):
assert value is not None assert value is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: settings write key %r value %r to %s", self.name, _log.debug('%s: settings write key %r value %r to %s', self.name,
key, value, self._device) key, value, self._device)
if self._device.online: if self._device.online:
@ -440,7 +440,7 @@ class BitFieldSetting(Setting):
if data_bytes is not None: if data_bytes is not None:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug( _log.debug(
"%s: settings prepare key value write(%s,%s) => %r", '%s: settings prepare key value write(%s,%s) => %r',
self.name, key, str(value), data_bytes) self.name, key, str(value), data_bytes)
reply = self._rw.write(self._device, data_bytes) reply = self._rw.write(self._device, data_bytes)
if not reply: if not reply:
@ -583,13 +583,13 @@ class BooleanValidator(object):
if isinstance(self.mask, int): if isinstance(self.mask, int):
reply_value = ord(reply_bytes[:1]) & self.mask reply_value = ord(reply_bytes[:1]) & self.mask
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("BooleanValidator: validate read %r => %02X", _log.debug('BooleanValidator: validate read %r => %02X',
reply_bytes, reply_value) reply_bytes, reply_value)
if reply_value == self.true_value: if reply_value == self.true_value:
return True return True
if reply_value == self.false_value: if reply_value == self.false_value:
return False return False
_log.warn("BooleanValidator: reply %02X mismatched %02X/%02X/%02X", _log.warn('BooleanValidator: reply %02X mismatched %02X/%02X/%02X',
reply_value, self.true_value, self.false_value, reply_value, self.true_value, self.false_value,
self.mask) self.mask)
return False return False
@ -606,7 +606,7 @@ class BooleanValidator(object):
if reply_value == false_value: if reply_value == false_value:
return False return False
_log.warn("BooleanValidator: reply %r mismatched %r/%r/%r", _log.warn('BooleanValidator: reply %r mismatched %r/%r/%r',
reply_bytes, self.true_value, self.false_value, self.mask) reply_bytes, self.true_value, self.false_value, self.mask)
return False return False
@ -642,7 +642,7 @@ class BooleanValidator(object):
return None return None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("BooleanValidator: prepare_write(%s, %s) => %r", _log.debug('BooleanValidator: prepare_write(%s, %s) => %r',
new_value, current_value, to_write) new_value, current_value, to_write)
return to_write return to_write
@ -706,7 +706,7 @@ class ChoicesValidator(object):
def validate_read(self, reply_bytes): def validate_read(self, reply_bytes):
reply_value = _bytes2int(reply_bytes[:self._bytes_count]) reply_value = _bytes2int(reply_bytes[:self._bytes_count])
valid_value = self.choices[reply_value] valid_value = self.choices[reply_value]
assert valid_value is not None, "%s: failed to validate read value %02X" % ( assert valid_value is not None, '%s: failed to validate read value %02X' % (
self.__class__.__name__, reply_value) self.__class__.__name__, reply_value)
return valid_value return valid_value
@ -724,7 +724,7 @@ class ChoicesValidator(object):
raise ValueError(new_value) raise ValueError(new_value)
if choice is None: if choice is None:
raise ValueError("invalid choice %r" % new_value) raise ValueError('invalid choice %r' % new_value)
assert isinstance(choice, _NamedInt) assert isinstance(choice, _NamedInt)
return choice.bytes(self._bytes_count) return choice.bytes(self._bytes_count)
@ -772,14 +772,14 @@ class ChoicesMapValidator(ChoicesValidator):
if self.extra_default is not None and self.extra_default == reply_value: if self.extra_default is not None and self.extra_default == reply_value:
return int(self.choices[key][0]) return int(self.choices[key][0])
assert reply_value in self.choices[ assert reply_value in self.choices[
key], "%s: failed to validate read value %02X" % ( key], '%s: failed to validate read value %02X' % (
self.__class__.__name__, reply_value) self.__class__.__name__, reply_value)
return reply_value return reply_value
def prepare_write(self, key, new_value): def prepare_write(self, key, new_value):
choices = self.choices[key] choices = self.choices[key]
if new_value not in choices and new_value != self.extra_default: if new_value not in choices and new_value != self.extra_default:
raise ValueError("invalid choice %r" % new_value) raise ValueError('invalid choice %r' % new_value)
return _int2bytes(new_value, return _int2bytes(new_value,
self._skip_bytes_count + self._value_bytes_count) self._skip_bytes_count + self._value_bytes_count)
@ -808,13 +808,13 @@ class RangeValidator(object):
def validate_read(self, reply_bytes): def validate_read(self, reply_bytes):
reply_value = _bytes2int(reply_bytes[:self._bytes_count]) reply_value = _bytes2int(reply_bytes[:self._bytes_count])
assert reply_value >= self.min_value, "%s: failed to validate read value %02X" % ( assert reply_value >= self.min_value, '%s: failed to validate read value %02X' % (
self.__class__.__name__, reply_value) self.__class__.__name__, reply_value)
assert reply_value <= self.max_value, "%s: failed to validate read value %02X" % ( assert reply_value <= self.max_value, '%s: failed to validate read value %02X' % (
self.__class__.__name__, reply_value) self.__class__.__name__, reply_value)
return reply_value return reply_value
def prepare_write(self, new_value, current_value=None): def prepare_write(self, new_value, current_value=None):
if new_value < self.min_value or new_value > self.max_value: if new_value < self.min_value or new_value > self.max_value:
raise ValueError("invalid choice %r" % new_value) raise ValueError('invalid choice %r' % new_value)
return _int2bytes(new_value, self._bytes_count) return _int2bytes(new_value, self._bytes_count)

View File

@ -314,48 +314,48 @@ def feature_range(name,
# #
_HAND_DETECTION = ( _HAND_DETECTION = (
'hand-detection', _("Hand Detection"), 'hand-detection', _('Hand Detection'),
_("Turn on illumination when the hands hover over the keyboard.")) _('Turn on illumination when the hands hover over the keyboard.'))
_SMOOTH_SCROLL = ( _SMOOTH_SCROLL = (
'smooth-scroll', _("Smooth Scrolling"), 'smooth-scroll', _('Smooth Scrolling'),
_("High-sensitivity mode for vertical scroll with the wheel.")) _('High-sensitivity mode for vertical scroll with the wheel.'))
_SIDE_SCROLL = ( _SIDE_SCROLL = (
'side-scroll', _("Side Scrolling"), 'side-scroll', _('Side Scrolling'),
_("When disabled, pushing the wheel sideways sends custom button events\n" _('When disabled, pushing the wheel sideways sends custom button events\n'
"instead of the standard side-scrolling events.")) 'instead of the standard side-scrolling events.'))
_HI_RES_SCROLL = ( _HI_RES_SCROLL = (
'hi-res-scroll', _("High Resolution Scrolling"), 'hi-res-scroll', _('High Resolution Scrolling'),
_("High-sensitivity mode for vertical scroll with the wheel.")) _('High-sensitivity mode for vertical scroll with the wheel.'))
_LOW_RES_SCROLL = ('lowres-smooth-scroll', _("HID++ Scrolling"), _LOW_RES_SCROLL = ('lowres-smooth-scroll', _('HID++ Scrolling'),
_("HID++ mode for vertical scroll with the wheel.") + '\n' + _('HID++ mode for vertical scroll with the wheel.') + '\n' +
_("Effectively turns off wheel scrolling in Linux.")) _('Effectively turns off wheel scrolling in Linux.'))
_HIRES_INV = ('hires-smooth-invert', _("High Resolution Wheel Invert"), _HIRES_INV = ('hires-smooth-invert', _('High Resolution Wheel Invert'),
_("High-sensitivity wheel invert mode for vertical scroll.")) _('High-sensitivity wheel invert mode for vertical scroll.'))
_HIRES_RES = ('hires-smooth-resolution', _("Wheel Resolution"), _HIRES_RES = ('hires-smooth-resolution', _('Wheel Resolution'),
_("High-sensitivity mode for vertical scroll with the wheel.")) _('High-sensitivity mode for vertical scroll with the wheel.'))
_FN_SWAP = ( _FN_SWAP = (
'fn-swap', _("Swap Fx function"), 'fn-swap', _('Swap Fx function'),
_("When set, the F1..F12 keys will activate their special function,\n" _('When set, the F1..F12 keys will activate their special function,\n'
"and you must hold the FN key to activate their standard function.") + 'and you must hold the FN key to activate their standard function.') +
'\n\n' + '\n\n' +
_("When unset, the F1..F12 keys will activate their standard function,\n" _('When unset, the F1..F12 keys will activate their standard function,\n'
"and you must hold the FN key to activate their special function.")) 'and you must hold the FN key to activate their special function.'))
_DPI = ('dpi', _("Sensitivity (DPI)"), None) _DPI = ('dpi', _('Sensitivity (DPI)'), None)
_POINTER_SPEED = ('pointer_speed', _("Sensitivity (Pointer Speed)"), _POINTER_SPEED = ('pointer_speed', _('Sensitivity (Pointer Speed)'),
_("Speed multiplier for mouse (256 is normal multiplier).")) _('Speed multiplier for mouse (256 is normal multiplier).'))
_SMART_SHIFT = ( _SMART_SHIFT = (
'smart-shift', _("Smart Shift"), 'smart-shift', _('Smart Shift'),
_("Automatically switch the mouse wheel between ratchet and freespin mode.\n" _('Automatically switch the mouse wheel between ratchet and freespin mode.\n'
"The mouse wheel is always free at 0, and always locked at 50")) 'The mouse wheel is always free at 0, and always locked at 50'))
_BACKLIGHT = ('backlight', _("Backlight"), _BACKLIGHT = ('backlight', _('Backlight'),
_("Turn illumination on or off on keyboard.")) _('Turn illumination on or off on keyboard.'))
_REPROGRAMMABLE_KEYS = ('reprogrammable-keys', _( _REPROGRAMMABLE_KEYS = ('reprogrammable-keys', _(
"Actions" 'Actions'
), _("Change the action for the key or button.") + "\n" + _( ), _('Change the action for the key or button.') + '\n' + _(
"Changing important actions (such as for the left mouse button) can result in an unusable system." 'Changing important actions (such as for the left mouse button) can result in an unusable system.'
)) ))
_DISABLE_KEYS = ('disable-keyboard-keys', _("Disable keys"), _DISABLE_KEYS = ('disable-keyboard-keys', _('Disable keys'),
_("Disable specific keyboard keys.")) _('Disable specific keyboard keys.'))
# #
# #
@ -741,12 +741,12 @@ def check_feature_settings(device, already_known):
try: try:
detected = featureFn()(device) detected = featureFn()(device)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("check_feature[%s] detected %s", featureId, _log.debug('check_feature[%s] detected %s', featureId,
detected) detected)
if detected: if detected:
already_known.append(detected) already_known.append(detected)
except Exception as reason: except Exception as reason:
_log.error("check_feature[%s] inconsistent feature %s", featureId, _log.error('check_feature[%s] inconsistent feature %s', featureId,
reason) reason)
for name, featureId, featureFn, _, _ in _SETTINGS_TABLE: for name, featureId, featureFn, _, _ in _SETTINGS_TABLE:

View File

@ -106,8 +106,8 @@ class ReceiverStatus(dict):
def __str__(self): def __str__(self):
count = len(self._receiver) count = len(self._receiver)
return (_("No paired devices.") if count == 0 else ngettext( return (_('No paired devices.') if count == 0 else ngettext(
"%(count)s paired device.", "%(count)s paired devices.", count) % { '%(count)s paired device.', '%(count)s paired devices.', count) % {
'count': count 'count': count
}) })
@ -161,11 +161,11 @@ class DeviceStatus(dict):
battery_level = self.get(KEYS.BATTERY_LEVEL) battery_level = self.get(KEYS.BATTERY_LEVEL)
if battery_level is not None: if battery_level is not None:
if isinstance(battery_level, _NamedInt): if isinstance(battery_level, _NamedInt):
yield _("Battery: %(level)s") % { yield _('Battery: %(level)s') % {
'level': _(str(battery_level)) 'level': _(str(battery_level))
} }
else: else:
yield _("Battery: %(percent)d%%") % { yield _('Battery: %(percent)d%%') % {
'percent': battery_level 'percent': battery_level
} }
@ -178,7 +178,7 @@ class DeviceStatus(dict):
light_level = self.get(KEYS.LIGHT_LEVEL) light_level = self.get(KEYS.LIGHT_LEVEL)
if light_level is not None: if light_level is not None:
if comma: yield ', ' if comma: yield ', '
yield _("Lighting: %(level)s lux") % {'level': light_level} yield _('Lighting: %(level)s lux') % {'level': light_level}
return ''.join(i for i in _items()) return ''.join(i for i in _items())
@ -198,7 +198,7 @@ class DeviceStatus(dict):
voltage=None, voltage=None,
timestamp=None): timestamp=None):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s: battery %s, %s", self._device, level, status) _log.debug('%s: battery %s, %s', self._device, level, status)
if level is None: if level is None:
# Some notifications may come with no battery level info, just # Some notifications may come with no battery level info, just
@ -239,19 +239,19 @@ class DeviceStatus(dict):
level > _BATTERY_ATTENTION_LEVEL): level > _BATTERY_ATTENTION_LEVEL):
self[KEYS.ERROR] = None self[KEYS.ERROR] = None
else: else:
_log.warn("%s: battery %d%%, ALERT %s", self._device, level, _log.warn('%s: battery %d%%, ALERT %s', self._device, level,
status) status)
if self.get(KEYS.ERROR) != status: if self.get(KEYS.ERROR) != status:
self[KEYS.ERROR] = status self[KEYS.ERROR] = status
# only show the notification once # only show the notification once
alert = ALERT.NOTIFICATION | ALERT.ATTENTION alert = ALERT.NOTIFICATION | ALERT.ATTENTION
if isinstance(level, _NamedInt): if isinstance(level, _NamedInt):
reason = _("Battery: %(level)s (%(status)s)") % { reason = _('Battery: %(level)s (%(status)s)') % {
'level': _(level), 'level': _(level),
'status': _(status) 'status': _(status)
} }
else: else:
reason = _("Battery: %(percent)d%% (%(status)s)") % { reason = _('Battery: %(percent)d%% (%(status)s)') % {
'percent': level, 'percent': level,
'status': status.name 'status': status.name
} }
@ -336,7 +336,7 @@ class DeviceStatus(dict):
# Devices lose configuration when they are turned off, # Devices lose configuration when they are turned off,
# make sure they're up-to-date. # make sure they're up-to-date.
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s pushing device settings %s", d, _log.debug('%s pushing device settings %s', d,
d.settings) d.settings)
for s in d.settings: for s in d.settings:
s.apply() s.apply()

View File

@ -113,12 +113,12 @@ def _receivers(dev_path=None):
try: try:
r = Receiver.open(dev_info) r = Receiver.open(dev_info)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("[%s] => %s", dev_info.path, r) _log.debug('[%s] => %s', dev_info.path, r)
if r: if r:
yield r yield r
except Exception as e: except Exception as e:
_log.exception('opening ' + str(dev_info)) _log.exception('opening ' + str(dev_info))
_sys.exit("%s: error: %s" % (NAME, str(e))) _sys.exit('%s: error: %s' % (NAME, str(e)))
def _find_receiver(receivers, name): def _find_receiver(receivers, name):

View File

@ -127,7 +127,7 @@ def run(receivers, args, find_receiver, find_device):
raise Exception("can't interpret '%s' as integer" % args.value) raise Exception("can't interpret '%s' as integer" % args.value)
else: else:
raise Exception("NotImplemented") raise Exception('NotImplemented')
result = setting.write(value) result = setting.write(value)
if result is None: if result is None:

View File

@ -96,6 +96,6 @@ def run(receivers, args, find_receiver, _ignore):
else: else:
error = receiver.status.get(_status.KEYS.ERROR) error = receiver.status.get(_status.KEYS.ERROR)
if error: if error:
raise Exception("pairing failed: %s" % error) raise Exception('pairing failed: %s' % error)
else: else:
print('Paired a device') # this is better than an error print('Paired a device') # this is better than an error

View File

@ -48,32 +48,32 @@ def run(receivers, args, find_receiver, _ignore):
print(' Register Dump') print(' Register Dump')
register = receiver.read_register(_R.notifications) register = receiver.read_register(_R.notifications)
print(" Notification Register %#04x: %s" % print(' Notification Register %#04x: %s' %
(_R.notifications % 0x100, (_R.notifications % 0x100,
'0x' + _strhex(register) if register else "None")) '0x' + _strhex(register) if register else 'None'))
register = receiver.read_register(_R.receiver_connection) register = receiver.read_register(_R.receiver_connection)
print(" Connection State %#04x: %s" % print(' Connection State %#04x: %s' %
(_R.receiver_connection % 0x100, (_R.receiver_connection % 0x100,
'0x' + _strhex(register) if register else "None")) '0x' + _strhex(register) if register else 'None'))
register = receiver.read_register(_R.devices_activity) register = receiver.read_register(_R.devices_activity)
print(" Device Activity %#04x: %s" % print(' Device Activity %#04x: %s' %
(_R.devices_activity % 0x100, (_R.devices_activity % 0x100,
'0x' + _strhex(register) if register else "None")) '0x' + _strhex(register) if register else 'None'))
for device in range(0, 6): for device in range(0, 6):
for sub_reg in [0x0, 0x10, 0x20, 0x30]: for sub_reg in [0x0, 0x10, 0x20, 0x30]:
register = receiver.read_register(_R.receiver_info, register = receiver.read_register(_R.receiver_info,
sub_reg + device) sub_reg + device)
print(" Pairing Register %#04x %#04x: %s" % print(' Pairing Register %#04x %#04x: %s' %
(_R.receiver_info % 0x100, sub_reg + device, (_R.receiver_info % 0x100, sub_reg + device,
'0x' + _strhex(register) if register else "None")) '0x' + _strhex(register) if register else 'None'))
register = receiver.read_register(_R.receiver_info, 0x40 + device) register = receiver.read_register(_R.receiver_info, 0x40 + device)
print(" Pairing Name %#04x %#02x: %s" % print(' Pairing Name %#04x %#02x: %s' %
(_R.receiver_info % 0x100, 0x40 + device, (_R.receiver_info % 0x100, 0x40 + device,
register[2:2 + ord(register[1:2])] if register else "None")) register[2:2 + ord(register[1:2])] if register else 'None'))
for sub_reg in range(0, 5): for sub_reg in range(0, 5):
register = receiver.read_register(_R.firmware, sub_reg) register = receiver.read_register(_R.firmware, sub_reg)
print(" Firmware %#04x %#04x: %s" % print(' Firmware %#04x %#04x: %s' %
(_R.firmware % 0x100, sub_reg, (_R.firmware % 0x100, sub_reg,
'0x' + _strhex(register) if register else "None")) '0x' + _strhex(register) if register else 'None'))

View File

@ -124,79 +124,79 @@ def _print_device(dev):
wheel = _hidpp20.get_hires_wheel(dev) wheel = _hidpp20.get_hires_wheel(dev)
if wheel: if wheel:
multi, has_invert, has_switch, inv, res, target, ratchet = wheel multi, has_invert, has_switch, inv, res, target, ratchet = wheel
print(" Multiplier: %s" % multi) print(' Multiplier: %s' % multi)
if has_invert: if has_invert:
print(" Has invert") print(' Has invert')
if inv: if inv:
print(" Inverse wheel motion") print(' Inverse wheel motion')
else: else:
print(" Normal wheel motion") print(' Normal wheel motion')
if has_switch: if has_switch:
print(" Has ratchet switch") print(' Has ratchet switch')
if ratchet: if ratchet:
print(" Normal wheel mode") print(' Normal wheel mode')
else: else:
print(" Free wheel mode") print(' Free wheel mode')
if res: if res:
print(" High resolution mode") print(' High resolution mode')
else: else:
print(" Low resolution mode") print(' Low resolution mode')
if target: if target:
print(" HID++ notification") print(' HID++ notification')
else: else:
print(" HID notification") print(' HID notification')
elif feature == _hidpp20.FEATURE.MOUSE_POINTER: elif feature == _hidpp20.FEATURE.MOUSE_POINTER:
mouse_pointer = _hidpp20.get_mouse_pointer_info(dev) mouse_pointer = _hidpp20.get_mouse_pointer_info(dev)
if mouse_pointer: if mouse_pointer:
print(" DPI: %s" % mouse_pointer['dpi']) print(' DPI: %s' % mouse_pointer['dpi'])
print(" Acceleration: %s" % print(' Acceleration: %s' %
mouse_pointer['acceleration']) mouse_pointer['acceleration'])
if mouse_pointer['suggest_os_ballistics']: if mouse_pointer['suggest_os_ballistics']:
print(" Use OS ballistics") print(' Use OS ballistics')
else: else:
print(" Override OS ballistics") print(' Override OS ballistics')
if mouse_pointer['suggest_vertical_orientation']: if mouse_pointer['suggest_vertical_orientation']:
print(" Provide vertical tuning, trackball") print(' Provide vertical tuning, trackball')
else: else:
print(" No vertical tuning, standard mice") print(' No vertical tuning, standard mice')
if feature == _hidpp20.FEATURE.VERTICAL_SCROLLING: if feature == _hidpp20.FEATURE.VERTICAL_SCROLLING:
vertical_scrolling_info = _hidpp20.get_vertical_scrolling_info( vertical_scrolling_info = _hidpp20.get_vertical_scrolling_info(
dev) dev)
if vertical_scrolling_info: if vertical_scrolling_info:
print(" Roller type: %s" % print(' Roller type: %s' %
vertical_scrolling_info['roller']) vertical_scrolling_info['roller'])
print(" Ratchet per turn: %s" % print(' Ratchet per turn: %s' %
vertical_scrolling_info['ratchet']) vertical_scrolling_info['ratchet'])
print(" Scroll lines: %s" % print(' Scroll lines: %s' %
vertical_scrolling_info['lines']) vertical_scrolling_info['lines'])
elif feature == _hidpp20.FEATURE.HI_RES_SCROLLING: elif feature == _hidpp20.FEATURE.HI_RES_SCROLLING:
scrolling_mode, scrolling_resolution = _hidpp20.get_hi_res_scrolling_info( scrolling_mode, scrolling_resolution = _hidpp20.get_hi_res_scrolling_info(
dev) dev)
if scrolling_mode: if scrolling_mode:
print(" Hi-res scrolling enabled") print(' Hi-res scrolling enabled')
else: else:
print(" Hi-res scrolling disabled") print(' Hi-res scrolling disabled')
if scrolling_resolution: if scrolling_resolution:
print(" Hi-res scrolling multiplier: %s" % print(' Hi-res scrolling multiplier: %s' %
scrolling_resolution) scrolling_resolution)
elif feature == _hidpp20.FEATURE.POINTER_SPEED: elif feature == _hidpp20.FEATURE.POINTER_SPEED:
pointer_speed = _hidpp20.get_pointer_speed_info(dev) pointer_speed = _hidpp20.get_pointer_speed_info(dev)
if pointer_speed: if pointer_speed:
print(" Pointer Speed: %s" % pointer_speed) print(' Pointer Speed: %s' % pointer_speed)
elif feature == _hidpp20.FEATURE.LOWRES_WHEEL: elif feature == _hidpp20.FEATURE.LOWRES_WHEEL:
wheel_status = _hidpp20.get_lowres_wheel_status(dev) wheel_status = _hidpp20.get_lowres_wheel_status(dev)
if wheel_status: if wheel_status:
print(" Wheel Reports: %s" % wheel_status) print(' Wheel Reports: %s' % wheel_status)
elif feature == _hidpp20.FEATURE.NEW_FN_INVERSION: elif feature == _hidpp20.FEATURE.NEW_FN_INVERSION:
inverted, default_inverted = _hidpp20.get_new_fn_inversion(dev) inverted, default_inverted = _hidpp20.get_new_fn_inversion(dev)
print(" Fn-swap:", print(' Fn-swap:',
"enabled" if inverted else "disabled") 'enabled' if inverted else 'disabled')
print(" Fn-swap default:", print(' Fn-swap default:',
"enabled" if default_inverted else "disabled") 'enabled' if default_inverted else 'disabled')
for setting in dev_settings: for setting in dev_settings:
if setting.feature == feature: if setting.feature == feature:
v = setting.read(False) v = setting.read(False)
print(" %s: %s" % (setting.label, v)) print(' %s: %s' % (setting.label, v))
if dev.online and dev.keys: if dev.online and dev.keys:
print(' Has %d reprogrammable keys:' % len(dev.keys)) print(' Has %d reprogrammable keys:' % len(dev.keys))

View File

@ -47,14 +47,14 @@ def _load():
with open(_file_path, 'r') as config_file: with open(_file_path, 'r') as config_file:
loaded_configuration = _json_load(config_file) loaded_configuration = _json_load(config_file)
except: except:
_log.error("failed to load from %s", _file_path) _log.error('failed to load from %s', _file_path)
# loaded_configuration.update(_configuration) # loaded_configuration.update(_configuration)
_configuration.clear() _configuration.clear()
_configuration.update(loaded_configuration) _configuration.update(loaded_configuration)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("load => %s", _configuration) _log.debug('load => %s', _configuration)
_cleanup(_configuration) _cleanup(_configuration)
_configuration[_KEY_VERSION] = __version__ _configuration[_KEY_VERSION] = __version__
@ -71,7 +71,7 @@ def save():
try: try:
_os.makedirs(dirname) _os.makedirs(dirname)
except: except:
_log.error("failed to create %s", dirname) _log.error('failed to create %s', dirname)
return False return False
_cleanup(_configuration) _cleanup(_configuration)
@ -85,10 +85,10 @@ def save():
sort_keys=True) sort_keys=True)
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("saved %s to %s", _configuration, _file_path) _log.info('saved %s to %s', _configuration, _file_path)
return True return True
except: except:
_log.error("failed to save to %s", _file_path) _log.error('failed to save to %s', _file_path)
def _cleanup(d): def _cleanup(d):

View File

@ -39,7 +39,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None):
return importlib.import_module(module) return importlib.import_module(module)
except (ImportError, ValueError): except (ImportError, ValueError):
import sys import sys
sys.exit("%s: missing required system package %s" % (NAME, os_package)) sys.exit('%s: missing required system package %s' % (NAME, os_package))
prefer_symbolic_battery_icons = False prefer_symbolic_battery_icons = False
@ -115,7 +115,7 @@ def _parse_arguments():
if not args.action: if not args.action:
if logging.root.isEnabledFor(logging.INFO): if logging.root.isEnabledFor(logging.INFO):
logging.info("language %s (%s), translations path %s", logging.info('language %s (%s), translations path %s',
_i18n.language, _i18n.encoding, _i18n.path) _i18n.language, _i18n.encoding, _i18n.path)
return args return args

View File

@ -84,7 +84,7 @@ class ReceiverListener(_listener.EventsListener):
def has_started(self): def has_started(self):
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: notifications listener has started (%s)", _log.info('%s: notifications listener has started (%s)',
self.receiver, self.receiver.handle) self.receiver, self.receiver.handle)
notification_flags = self.receiver.enable_notifications() notification_flags = self.receiver.enable_notifications()
self.receiver.status[ self.receiver.status[
@ -96,18 +96,18 @@ class ReceiverListener(_listener.EventsListener):
r, self.receiver = self.receiver, None r, self.receiver = self.receiver, None
assert r is not None assert r is not None
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: notifications listener has stopped", r) _log.info('%s: notifications listener has stopped', r)
# because udev is not notifying us about device removal, # because udev is not notifying us about device removal,
# make sure to clean up in _all_listeners # make sure to clean up in _all_listeners
_all_listeners.pop(r.path, None) _all_listeners.pop(r.path, None)
r.status = _("The receiver was unplugged.") r.status = _('The receiver was unplugged.')
if r: if r:
try: try:
r.close() r.close()
except: except:
_log.exception("closing receiver %s" % r.path) _log.exception('closing receiver %s' % r.path)
self.status_changed_callback(r) #, _status.ALERT.NOTIFICATION) self.status_changed_callback(r) #, _status.ALERT.NOTIFICATION)
# def tick(self, timestamp): # def tick(self, timestamp):
@ -151,11 +151,11 @@ class ReceiverListener(_listener.EventsListener):
assert device is not None assert device is not None
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
if device.kind is None: if device.kind is None:
_log.info("status_changed %s: %s, %s (%X) %s", device, _log.info('status_changed %s: %s, %s (%X) %s', device,
'present' if bool(device) else 'removed', 'present' if bool(device) else 'removed',
device.status, alert, reason or '') device.status, alert, reason or '')
else: else:
_log.info("status_changed %s: %s %s, %s (%X) %s", device, _log.info('status_changed %s: %s %s, %s (%X) %s', device,
'paired' if bool(device) else 'unpaired', 'paired' if bool(device) else 'unpaired',
'online' if device.online else 'offline', 'online' if device.online else 'offline',
device.status, alert, reason or '') device.status, alert, reason or '')
@ -171,7 +171,7 @@ class ReceiverListener(_listener.EventsListener):
# Device was unpaired, and isn't valid anymore. # Device was unpaired, and isn't valid anymore.
# We replace it with a ghost so that the UI has something to work # We replace it with a ghost so that the UI has something to work
# with while cleaning up. # with while cleaning up.
_log.warn("device %s was unpaired, ghosting", device) _log.warn('device %s was unpaired, ghosting', device)
device = _ghost(device) device = _ghost(device)
self.status_changed_callback(device, alert, reason) self.status_changed_callback(device, alert, reason)
@ -194,7 +194,7 @@ class ReceiverListener(_listener.EventsListener):
if not (0 < n.devnumber <= self.receiver.max_devices): if not (0 < n.devnumber <= self.receiver.max_devices):
if _log.isEnabledFor(_WARNING): if _log.isEnabledFor(_WARNING):
_log.warning( _log.warning(
_("Unexpected device number (%s) in notification %s." % _('Unexpected device number (%s) in notification %s.' %
(n.devnumber, n))) (n.devnumber, n)))
return return
already_known = n.devnumber in self.receiver already_known = n.devnumber in self.receiver
@ -231,14 +231,14 @@ class ReceiverListener(_listener.EventsListener):
dev = self.receiver[n.devnumber] dev = self.receiver[n.devnumber]
if not dev: if not dev:
_log.warn("%s: received %s for invalid device %d: %r", _log.warn('%s: received %s for invalid device %d: %r',
self.receiver, n, n.devnumber, dev) self.receiver, n, n.devnumber, dev)
return return
# Apply settings every time the device connects # Apply settings every time the device connects
if n.sub_id == 0x41: if n.sub_id == 0x41:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s triggered new device %s (%s)", n, dev, dev.kind) _log.info('%s triggered new device %s (%s)', n, dev, dev.kind)
# If there are saved configs, bring the device's settings up-to-date. # If there are saved configs, bring the device's settings up-to-date.
# They will be applied when the device is marked as online. # They will be applied when the device is marked as online.
configuration.attach_to(dev) configuration.attach_to(dev)
@ -253,7 +253,7 @@ class ReceiverListener(_listener.EventsListener):
# this should be the first notification after a device was paired # this should be the first notification after a device was paired
assert n.sub_id == 0x41 and n.address == 0x04 assert n.sub_id == 0x41 and n.address == 0x04
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("%s: pairing detected new device", self.receiver) _log.info('%s: pairing detected new device', self.receiver)
self.receiver.status.new_device = dev self.receiver.status.new_device = dev
elif dev.online is None: elif dev.online is None:
dev.ping() dev.ping()
@ -283,7 +283,7 @@ def _start(device_info):
_all_listeners[device_info.path] = rl _all_listeners[device_info.path] = rl
return rl return rl
_log.warn("failed to open %s", device_info) _log.warn('failed to open %s', device_info)
def start_all(): def start_all():
@ -291,7 +291,7 @@ def start_all():
stop_all() stop_all()
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("starting receiver listening threads") _log.info('starting receiver listening threads')
for device_info in _base.receivers(): for device_info in _base.receivers():
_process_receiver_event('add', device_info) _process_receiver_event('add', device_info)
@ -302,7 +302,7 @@ def stop_all():
if listeners: if listeners:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("stopping receiver listening threads %s", listeners) _log.info('stopping receiver listening threads %s', listeners)
for l in listeners: for l in listeners:
l.stop() l.stop()
@ -352,7 +352,7 @@ def _process_receiver_event(action, device_info):
assert _error_callback assert _error_callback
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("receiver event %s %s", action, device_info) _log.info('receiver event %s %s', action, device_info)
# whatever the action, stop any previous receivers at this path # whatever the action, stop any previous receivers at this path
l = _all_listeners.pop(device_info.path, None) l = _all_listeners.pop(device_info.path, None)

View File

@ -56,7 +56,7 @@ class TaskRunner(_Thread):
self.alive = True self.alive = True
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("started") _log.debug('started')
while self.alive: while self.alive:
task = self.queue.get() task = self.queue.get()
@ -66,7 +66,7 @@ class TaskRunner(_Thread):
try: try:
function(*args, **kwargs) function(*args, **kwargs)
except: except:
_log.exception("calling %s", function) _log.exception('calling %s', function)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("stopped") _log.debug('stopped')

View File

@ -43,18 +43,18 @@ GLib.threads_init()
def _error_dialog(reason, object): def _error_dialog(reason, object):
_log.error("error: %s %s", reason, object) _log.error('error: %s %s', reason, object)
if reason == 'permissions': if reason == 'permissions':
title = _("Permissions error") title = _('Permissions error')
text = _("Found a Logitech Receiver (%s), but did not have permission to open it.") % object + \ text = _('Found a Logitech Receiver (%s), but did not have permission to open it.') % object + \
'\n\n' + \ '\n\n' + \
_("If you've just installed Solaar, try removing the receiver and plugging it back in.") _("If you've just installed Solaar, try removing the receiver and plugging it back in.")
elif reason == 'unpair': elif reason == 'unpair':
title = _("Unpairing failed") title = _('Unpairing failed')
text = _("Failed to unpair %{device} from %{receiver}.").format(device=object.name, receiver=object.receiver.name) + \ text = _('Failed to unpair %{device} from %{receiver}.').format(device=object.name, receiver=object.receiver.name) + \
'\n\n' + \ '\n\n' + \
_("The receiver returned an error, with no further details.") _('The receiver returned an error, with no further details.')
else: else:
raise Exception("ui.error_dialog: don't know how to handle (%s, %s)", raise Exception("ui.error_dialog: don't know how to handle (%s, %s)",
reason, object) reason, object)
@ -95,7 +95,7 @@ from . import notify, tray, window # isort:skip # noqa: E402
def _startup(app, startup_hook, use_tray, show_window): def _startup(app, startup_hook, use_tray, show_window):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("startup registered=%s, remote=%s", app.get_is_registered(), _log.debug('startup registered=%s, remote=%s', app.get_is_registered(),
app.get_is_remote()) app.get_is_remote())
from solaar.tasks import TaskRunner as _TaskRunner from solaar.tasks import TaskRunner as _TaskRunner
@ -113,7 +113,7 @@ def _startup(app, startup_hook, use_tray, show_window):
def _activate(app): def _activate(app):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("activate") _log.debug('activate')
if app.get_windows(): if app.get_windows():
window.popup() window.popup()
else: else:
@ -122,14 +122,14 @@ def _activate(app):
def _command_line(app, command_line): def _command_line(app, command_line):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("command_line %s", command_line.get_arguments()) _log.debug('command_line %s', command_line.get_arguments())
return 0 return 0
def _shutdown(app, shutdown_hook): def _shutdown(app, shutdown_hook):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("shutdown") _log.debug('shutdown')
shutdown_hook() shutdown_hook()
@ -167,7 +167,7 @@ def run_loop(startup_hook, shutdown_hook, use_tray, show_window, args=None):
def _status_changed(device, alert, reason): def _status_changed(device, alert, reason):
assert device is not None assert device is not None
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("status changed: %s (%s) %s", device, alert, reason) _log.debug('status changed: %s (%s) %s', device, alert, reason)
tray.update(device) tray.update(device)
if alert & ALERT.ATTENTION: if alert & ALERT.ATTENTION:

View File

@ -36,7 +36,7 @@ def _create():
about.set_program_name(NAME) about.set_program_name(NAME)
about.set_version(__version__) about.set_version(__version__)
about.set_comments( about.set_comments(
_("Shows status of devices connected\nthrough wireless Logitech receivers." _('Shows status of devices connected\nthrough wireless Logitech receivers.'
)) ))
about.set_logo_icon_name(NAME.lower()) about.set_logo_icon_name(NAME.lower())
@ -46,25 +46,25 @@ def _create():
about.set_authors(('Daniel Pavel http://github.com/pwr', )) about.set_authors(('Daniel Pavel http://github.com/pwr', ))
try: try:
about.add_credit_section(_("GUI design"), about.add_credit_section(_('GUI design'),
('Julien Gascard', 'Daniel Pavel')) ('Julien Gascard', 'Daniel Pavel'))
about.add_credit_section(_("Testing"), ( about.add_credit_section(_('Testing'), (
'Douglas Wagner', 'Douglas Wagner',
'Julien Gascard', 'Julien Gascard',
'Peter Wu http://www.lekensteyn.nl/logitech-unifying.html', 'Peter Wu http://www.lekensteyn.nl/logitech-unifying.html',
)) ))
about.add_credit_section(_("Logitech documentation"), ( about.add_credit_section(_('Logitech documentation'), (
'Julien Danjou http://julien.danjou.info/blog/2012/logitech-unifying-upower', 'Julien Danjou http://julien.danjou.info/blog/2012/logitech-unifying-upower',
'Nestor Lopez Casado http://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28', 'Nestor Lopez Casado http://drive.google.com/folderview?id=0BxbRzx7vEV7eWmgwazJ3NUFfQ28',
)) ))
except TypeError: except TypeError:
# gtk3 < ~3.6.4 has incorrect gi bindings # gtk3 < ~3.6.4 has incorrect gi bindings
import logging import logging
logging.exception("failed to fully create the about dialog") logging.exception('failed to fully create the about dialog')
except: except:
# the Gtk3 version may be too old, and the function does not exist # the Gtk3 version may be too old, and the function does not exist
import logging import logging
logging.exception("failed to fully create the about dialog") logging.exception('failed to fully create the about dialog')
about.set_translator_credits('\n'.join(( about.set_translator_credits('\n'.join((
'gogo (croatian)', 'gogo (croatian)',

View File

@ -68,7 +68,7 @@ def make_toggle(name, label, function, stock_id=None, *args):
# toggle_notifications = make_toggle('notifications', 'Notifications', _toggle_notifications) # toggle_notifications = make_toggle('notifications', 'Notifications', _toggle_notifications)
about = make('help-about', about = make('help-about',
_("About") + ' ' + NAME, _('About') + ' ' + NAME,
_show_about_window, _show_about_window,
stock_id=Gtk.STOCK_ABOUT) stock_id=Gtk.STOCK_ABOUT)
@ -96,10 +96,10 @@ def unpair(window, device):
qdialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.QUESTION, qdialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.QUESTION,
Gtk.ButtonsType.NONE, Gtk.ButtonsType.NONE,
_("Unpair") + ' ' + device.name + ' ?') _('Unpair') + ' ' + device.name + ' ?')
qdialog.set_icon_name('remove') qdialog.set_icon_name('remove')
qdialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) qdialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
qdialog.add_button(_("Unpair"), Gtk.ResponseType.ACCEPT) qdialog.add_button(_('Unpair'), Gtk.ResponseType.ACCEPT)
choice = qdialog.run() choice = qdialog.run()
qdialog.destroy() qdialog.destroy()
if choice == Gtk.ResponseType.ACCEPT: if choice == Gtk.ResponseType.ACCEPT:

View File

@ -184,11 +184,11 @@ def _create_sbox(s):
sbox.pack_start(Gtk.Label(s.label), False, False, 0) sbox.pack_start(Gtk.Label(s.label), False, False, 0)
spinner = Gtk.Spinner() spinner = Gtk.Spinner()
spinner.set_tooltip_text(_("Working") + '...') spinner.set_tooltip_text(_('Working') + '...')
failed = Gtk.Image.new_from_icon_name('dialog-warning', failed = Gtk.Image.new_from_icon_name('dialog-warning',
Gtk.IconSize.SMALL_TOOLBAR) Gtk.IconSize.SMALL_TOOLBAR)
failed.set_tooltip_text(_("Read/write operation failed.")) failed.set_tooltip_text(_('Read/write operation failed.'))
if s.kind == _SETTING_KIND.toggle: if s.kind == _SETTING_KIND.toggle:
control = _create_toggle_control(s) control = _create_toggle_control(s)
@ -220,7 +220,7 @@ def _create_sbox(s):
control = _create_map_choice_control(X(s, {'choices': choices})) control = _create_map_choice_control(X(s, {'choices': choices}))
sbox.pack_end(control, True, True, 0) sbox.pack_end(control, True, True, 0)
else: else:
raise Exception("NotImplemented") raise Exception('NotImplemented')
control.set_sensitive(False) # the first read will enable it control.set_sensitive(False) # the first read will enable it
sbox.pack_end(spinner, False, False, 0) sbox.pack_end(spinner, False, False, 0)
@ -259,7 +259,7 @@ def _update_setting_item(sbox, value, is_online=True):
if value.get(kbox.get_active_id()): if value.get(kbox.get_active_id()):
vbox.set_active_id(str(value.get(kbox.get_active_id()))) vbox.set_active_id(str(value.get(kbox.get_active_id())))
else: else:
raise Exception("NotImplemented") raise Exception('NotImplemented')
control.set_sensitive(True) control.set_sensitive(True)

View File

@ -54,7 +54,7 @@ def _look_for_application_icons():
import sys as _sys import sys as _sys
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("sys.path[0] = %s", _sys.path[0]) _log.debug('sys.path[0] = %s', _sys.path[0])
prefix_share = _path.normpath( prefix_share = _path.normpath(
_path.join(_path.realpath(_sys.path[0]), '..')) _path.join(_path.realpath(_sys.path[0]), '..'))
src_share = _path.normpath( src_share = _path.normpath(
@ -75,7 +75,7 @@ def _look_for_application_icons():
for location in share_solaar: for location in share_solaar:
location = _path.join(location, 'icons') location = _path.join(location, 'icons')
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("looking for icons in %s", location) _log.debug('looking for icons in %s', location)
if _path.exists(_path.join(location, TRAY_ATTENTION + '.svg')): if _path.exists(_path.join(location, TRAY_ATTENTION + '.svg')):
yield location yield location
@ -97,7 +97,7 @@ def _init_icon_paths():
for p in _look_for_application_icons(): for p in _look_for_application_icons():
_default_theme.prepend_search_path(p) _default_theme.prepend_search_path(p)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("icon theme paths: %s", _default_theme.get_search_path()) _log.debug('icon theme paths: %s', _default_theme.get_search_path())
if gtk.prefer_symbolic_battery_icons: if gtk.prefer_symbolic_battery_icons:
if _default_theme.has_icon('battery-good-symbolic'): if _default_theme.has_icon('battery-good-symbolic'):
@ -105,9 +105,9 @@ def _init_icon_paths():
_use_symbolic_icons = True _use_symbolic_icons = True
return return
else: else:
_log.warning("failed to detect symbolic icons") _log.warning('failed to detect symbolic icons')
if not _default_theme.has_icon('battery-good'): if not _default_theme.has_icon('battery-good'):
_log.warning("failed to detect icons") _log.warning('failed to detect icons')
# #
@ -118,10 +118,10 @@ def _init_icon_paths():
def battery(level=None, charging=False): def battery(level=None, charging=False):
icon_name = _battery_icon_name(level, charging) icon_name = _battery_icon_name(level, charging)
if not _default_theme.has_icon(icon_name): if not _default_theme.has_icon(icon_name):
_log.warning("icon %s not found in current theme", icon_name) _log.warning('icon %s not found in current theme', icon_name)
return TRAY_OKAY # use Solaar icon if battery icon not available return TRAY_OKAY # use Solaar icon if battery icon not available
elif _log.isEnabledFor(_DEBUG): elif _log.isEnabledFor(_DEBUG):
_log.debug("battery icon for %s:%s = %s", level, charging, icon_name) _log.debug('battery icon for %s:%s = %s', level, charging, icon_name)
return icon_name return icon_name
@ -222,4 +222,4 @@ def icon_file(name, size=_LARGE_SIZE):
# _log.debug("icon %s(%d) => %s", name, size, file_name) # _log.debug("icon %s(%d) => %s", name, size, file_name)
return file_name return file_name
_log.warn("icon %s(%d) not found in current theme", name, size) _log.warn('icon %s(%d) not found in current theme', name, size)

View File

@ -57,18 +57,18 @@ if available:
if available: if available:
if not Notify.is_initted(): if not Notify.is_initted():
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("starting desktop notifications") _log.info('starting desktop notifications')
try: try:
return Notify.init(NAME) return Notify.init(NAME)
except: except:
_log.exception("initializing desktop notifications") _log.exception('initializing desktop notifications')
available = False available = False
return available and Notify.is_initted() return available and Notify.is_initted()
def uninit(): def uninit():
if available and Notify.is_initted(): if available and Notify.is_initted():
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("stopping desktop notifications") _log.info('stopping desktop notifications')
_notifications.clear() _notifications.clear()
Notify.uninit() Notify.uninit()
@ -95,14 +95,14 @@ if available:
n.update(NAME, reason, icon_file) n.update(NAME, reason, icon_file)
n.set_urgency(Notify.Urgency.NORMAL) n.set_urgency(Notify.Urgency.NORMAL)
n.set_hint("desktop-entry", GLib.Variant('s', NAME.lower())) n.set_hint('desktop-entry', GLib.Variant('s', NAME.lower()))
try: try:
# if _log.isEnabledFor(_DEBUG): # if _log.isEnabledFor(_DEBUG):
# _log.debug("showing %s", n) # _log.debug("showing %s", n)
n.show() n.show()
except Exception: except Exception:
_log.exception("showing %s", n) _log.exception('showing %s', n)
def show(dev, reason=None, icon=None): def show(dev, reason=None, icon=None):
"""Show a notification with title and text.""" """Show a notification with title and text."""
@ -117,11 +117,11 @@ if available:
if reason: if reason:
message = reason message = reason
elif dev.status is None: elif dev.status is None:
message = _("unpaired") message = _('unpaired')
elif bool(dev.status): elif bool(dev.status):
message = dev.status.to_string() or _("connected") message = dev.status.to_string() or _('connected')
else: else:
message = _("offline") message = _('offline')
# we need to use the filename here because the notifications daemon # we need to use the filename here because the notifications daemon
# is an external application that does not know about our icon sets # is an external application that does not know about our icon sets
@ -131,14 +131,14 @@ if available:
n.update(summary, message, icon_file) n.update(summary, message, icon_file)
urgency = Notify.Urgency.LOW if dev.status else Notify.Urgency.NORMAL urgency = Notify.Urgency.LOW if dev.status else Notify.Urgency.NORMAL
n.set_urgency(urgency) n.set_urgency(urgency)
n.set_hint("desktop-entry", GLib.Variant('s', NAME.lower())) n.set_hint('desktop-entry', GLib.Variant('s', NAME.lower()))
try: try:
# if _log.isEnabledFor(_DEBUG): # if _log.isEnabledFor(_DEBUG):
# _log.debug("showing %s", n) # _log.debug("showing %s", n)
n.show() n.show()
except Exception: except Exception:
_log.exception("showing %s", n) _log.exception('showing %s', n)
else: else:
init = lambda: False init = lambda: False

View File

@ -70,7 +70,7 @@ def _create_page(assistant, kind, header=None, icon_name=None, text=None):
def _check_lock_state(assistant, receiver, count=2): def _check_lock_state(assistant, receiver, count=2):
if not assistant.is_drawable(): if not assistant.is_drawable():
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("assistant %s destroyed, bailing out", assistant) _log.debug('assistant %s destroyed, bailing out', assistant)
return False return False
if receiver.status.get(_K.ERROR): if receiver.status.get(_K.ERROR):
@ -99,7 +99,7 @@ def _check_lock_state(assistant, receiver, count=2):
def _prepare(assistant, page, receiver): def _prepare(assistant, page, receiver):
index = assistant.get_current_page() index = assistant.get_current_page()
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("prepare %s %d %s", assistant, index, page) _log.debug('prepare %s %d %s', assistant, index, page)
if index == 0: if index == 0:
if receiver.set_lock(False, timeout=_PAIRING_TIMEOUT): if receiver.set_lock(False, timeout=_PAIRING_TIMEOUT):
@ -119,7 +119,7 @@ def _prepare(assistant, page, receiver):
def _finish(assistant, receiver): def _finish(assistant, receiver):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("finish %s", assistant) _log.debug('finish %s', assistant)
assistant.destroy() assistant.destroy()
receiver.status.new_device = None receiver.status.new_device = None
if receiver.status.lock_open: if receiver.status.lock_open:
@ -130,23 +130,23 @@ def _finish(assistant, receiver):
def _pairing_failed(assistant, receiver, error): def _pairing_failed(assistant, receiver, error):
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s fail: %s", receiver, error) _log.debug('%s fail: %s', receiver, error)
assistant.commit() assistant.commit()
header = _("Pairing failed") + ': ' + _(str(error)) + '.' header = _('Pairing failed') + ': ' + _(str(error)) + '.'
if 'timeout' in str(error): if 'timeout' in str(error):
text = _( text = _(
"Make sure your device is within range, and has a decent battery charge." 'Make sure your device is within range, and has a decent battery charge.'
) )
elif str(error) == 'device not supported': elif str(error) == 'device not supported':
text = _( text = _(
"A new device was detected, but it is not compatible with this receiver." 'A new device was detected, but it is not compatible with this receiver.'
) )
elif 'many' in str(error): elif 'many' in str(error):
text = _("The receiver only supports %d paired device(s).") text = _('The receiver only supports %d paired device(s).')
else: else:
text = _("No further details are available about the error.") text = _('No further details are available about the error.')
_create_page(assistant, Gtk.AssistantPageType.SUMMARY, header, _create_page(assistant, Gtk.AssistantPageType.SUMMARY, header,
'dialog-error', text) 'dialog-error', text)
@ -157,11 +157,11 @@ def _pairing_failed(assistant, receiver, error):
def _pairing_succeeded(assistant, receiver, device): def _pairing_succeeded(assistant, receiver, device):
assert device assert device
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("%s success: %s", receiver, device) _log.debug('%s success: %s', receiver, device)
page = _create_page(assistant, Gtk.AssistantPageType.SUMMARY) page = _create_page(assistant, Gtk.AssistantPageType.SUMMARY)
header = Gtk.Label(_("Found a new device:")) header = Gtk.Label(_('Found a new device:'))
header.set_alignment(0.5, 0) header.set_alignment(0.5, 0)
page.pack_start(header, False, False, 0) page.pack_start(header, False, False, 0)
@ -190,7 +190,7 @@ def _pairing_succeeded(assistant, receiver, device):
Gtk.IconSize.MENU), False, Gtk.IconSize.MENU), False,
False, 0) False, 0)
hbox.pack_start( hbox.pack_start(
Gtk.Label(_("The wireless link is not encrypted") + '!'), Gtk.Label(_('The wireless link is not encrypted') + '!'),
False, False, 0) False, False, 0)
hbox.show_all() hbox.show_all()
else: else:
@ -219,14 +219,14 @@ def create(receiver):
assistant.set_role('pair-device') assistant.set_role('pair-device')
page_text = _( page_text = _(
"If the device is already turned on, turn if off and on again.") 'If the device is already turned on, turn if off and on again.')
if receiver.remaining_pairings() and receiver.remaining_pairings() >= 0: if receiver.remaining_pairings() and receiver.remaining_pairings() >= 0:
page_text += _("\n\nThis receiver has %d pairing(s) remaining." page_text += _('\n\nThis receiver has %d pairing(s) remaining.'
) % receiver.remaining_pairings() ) % receiver.remaining_pairings()
page_text += _("\nCancelling at this point will not use up a pairing.") page_text += _('\nCancelling at this point will not use up a pairing.')
page_intro = _create_page(assistant, Gtk.AssistantPageType.PROGRESS, page_intro = _create_page(assistant, Gtk.AssistantPageType.PROGRESS,
_("Turn on the device you want to pair."), _('Turn on the device you want to pair.'),
'preferences-desktop-peripherals', page_text) 'preferences-desktop-peripherals', page_text)
spinner = Gtk.Spinner() spinner = Gtk.Spinner()
spinner.set_visible(True) spinner.set_visible(True)

View File

@ -56,7 +56,7 @@ def _create_menu(quit_handler):
# per-device menu entries will be generated as-needed # per-device menu entries will be generated as-needed
no_receiver = Gtk.MenuItem.new_with_label(_("No Logitech receiver found")) no_receiver = Gtk.MenuItem.new_with_label(_('No Logitech receiver found'))
no_receiver.set_sensitive(False) no_receiver.set_sensitive(False)
menu.append(no_receiver) menu.append(no_receiver)
menu.append(Gtk.SeparatorMenuItem.new()) menu.append(Gtk.SeparatorMenuItem.new())
@ -65,7 +65,7 @@ def _create_menu(quit_handler):
menu.append(about.create_menu_item()) menu.append(about.create_menu_item())
menu.append( menu.append(
make('application-exit', make('application-exit',
_("Quit"), _('Quit'),
quit_handler, quit_handler,
stock_id=Gtk.STOCK_QUIT).create_menu_item()) stock_id=Gtk.STOCK_QUIT).create_menu_item())
del about, make del about, make
@ -149,7 +149,7 @@ def _scroll(tray_icon, event, direction=None):
_picked_device = candidate or _picked_device _picked_device = candidate or _picked_device
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("scroll: picked %s", _picked_device) _log.debug('scroll: picked %s', _picked_device)
_update_tray_icon() _update_tray_icon()
@ -172,7 +172,7 @@ try:
from gi.repository import AppIndicator3 from gi.repository import AppIndicator3
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("using %sAppIndicator3" % _log.debug('using %sAppIndicator3' %
('Ayatana ' if ayatana_appindicator_found else '')) ('Ayatana ' if ayatana_appindicator_found else ''))
# Defense against AppIndicator3 bug that treats files in current directory as icon files # Defense against AppIndicator3 bug that treats files in current directory as icon files
@ -238,7 +238,7 @@ try:
except ImportError: except ImportError:
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("using StatusIcon") _log.debug('using StatusIcon')
def _create(menu): def _create(menu):
icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT) icon = Gtk.StatusIcon.new_from_icon_name(_icons.TRAY_INIT)
@ -302,7 +302,7 @@ except ImportError:
def _generate_tooltip_lines(): def _generate_tooltip_lines():
if not _devices_info: if not _devices_info:
yield '<b>%s</b>: ' % NAME + _("no receiver") yield '<b>%s</b>: ' % NAME + _('no receiver')
return return
yield from _generate_description_lines() yield from _generate_description_lines()
@ -310,7 +310,7 @@ def _generate_tooltip_lines():
def _generate_description_lines(): def _generate_description_lines():
if not _devices_info: if not _devices_info:
yield _("no receiver") yield _('no receiver')
return return
for _ignore, number, name, status in _devices_info: for _ignore, number, name, status in _devices_info:
@ -323,13 +323,13 @@ def _generate_description_lines():
if status: if status:
yield '\t%s' % p yield '\t%s' % p
else: else:
yield '\t%s <small>(' % p + _("offline") + ')</small>' yield '\t%s <small>(' % p + _('offline') + ')</small>'
else: else:
if status: if status:
yield '<b>%s</b> <small>(' % name + _( yield '<b>%s</b> <small>(' % name + _(
"no status") + ')</small>' 'no status') + ')</small>'
else: else:
yield '<b>%s</b> <small>(' % name + _("offline") + ')</small>' yield '<b>%s</b> <small>(' % name + _('offline') + ')</small>'
yield '' yield ''
@ -350,7 +350,7 @@ def _pick_device_with_lowest_battery():
picked_level = level or 0 picked_level = level or 0
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("picked device with lowest battery: %s", picked) _log.debug('picked device with lowest battery: %s', picked)
return picked return picked

View File

@ -52,7 +52,7 @@ _INFO_ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR
_DEVICE_ICON_SIZE = Gtk.IconSize.DND _DEVICE_ICON_SIZE = Gtk.IconSize.DND
try: try:
import gi import gi
gi.check_version("3.7.4") gi.check_version('3.7.4')
_CAN_SET_ROW_NONE = None _CAN_SET_ROW_NONE = None
except (ValueError, AttributeError): except (ValueError, AttributeError):
_CAN_SET_ROW_NONE = '' _CAN_SET_ROW_NONE = ''
@ -112,7 +112,7 @@ def _create_receiver_panel():
p._count.set_alignment(0, 0.5) p._count.set_alignment(0, 0.5)
p.pack_start(p._count, True, True, 0) p.pack_start(p._count, True, True, 0)
p._scanning = Gtk.Label(_("Scanning") + '...') p._scanning = Gtk.Label(_('Scanning') + '...')
p._spinner = Gtk.Spinner() p._spinner = Gtk.Spinner()
bp = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 8) bp = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 8)
@ -145,14 +145,14 @@ def _create_device_panel():
return b return b
p._battery = _status_line(_("Battery")) p._battery = _status_line(_('Battery'))
p.pack_start(p._battery, False, False, 0) p.pack_start(p._battery, False, False, 0)
p._secure = _status_line(_("Wireless Link")) p._secure = _status_line(_('Wireless Link'))
p._secure._icon.set_from_icon_name('dialog-warning', _INFO_ICON_SIZE) p._secure._icon.set_from_icon_name('dialog-warning', _INFO_ICON_SIZE)
p.pack_start(p._secure, False, False, 0) p.pack_start(p._secure, False, False, 0)
p._lux = _status_line(_("Lighting")) p._lux = _status_line(_('Lighting'))
p.pack_start(p._lux, False, False, 0) p.pack_start(p._lux, False, False, 0)
p._config = _config_panel.create() p._config = _config_panel.create()
@ -183,7 +183,7 @@ def _create_buttons_box():
bb._details = _new_button(None, bb._details = _new_button(None,
'dialog-information', 'dialog-information',
_SMALL_BUTTON_ICON_SIZE, _SMALL_BUTTON_ICON_SIZE,
tooltip=_("Show Technical Details"), tooltip=_('Show Technical Details'),
toggle=True, toggle=True,
clicked=_update_details) clicked=_update_details)
bb.add(bb._details) bb.add(bb._details)
@ -198,7 +198,7 @@ def _create_buttons_box():
assert receiver.kind is None assert receiver.kind is None
_action.pair(_window, receiver) _action.pair(_window, receiver)
bb._pair = _new_button(_("Pair new device"), bb._pair = _new_button(_('Pair new device'),
'list-add', 'list-add',
clicked=_pair_new_device) clicked=_pair_new_device)
bb.add(bb._pair) bb.add(bb._pair)
@ -211,7 +211,7 @@ def _create_buttons_box():
assert device.kind is not None assert device.kind is not None
_action.unpair(_window, device) _action.unpair(_window, device)
bb._unpair = _new_button(_("Unpair"), bb._unpair = _new_button(_('Unpair'),
'edit-delete', 'edit-delete',
clicked=_unpair_current_device) clicked=_unpair_current_device)
bb.add(bb._unpair) bb.add(bb._unpair)
@ -221,7 +221,7 @@ def _create_buttons_box():
def _create_empty_panel(): def _create_empty_panel():
p = Gtk.Label() p = Gtk.Label()
p.set_markup('<small>' + _("Select a device") + '</small>') p.set_markup('<small>' + _('Select a device') + '</small>')
p.set_sensitive(False) p.set_sensitive(False)
return p return p
@ -339,12 +339,12 @@ def _create_window_layout():
bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL) bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL)
bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START) bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START)
bottom_buttons_box.set_spacing(20) bottom_buttons_box.set_spacing(20)
quit_button = _new_button(_("Quit") + ' ' + NAME, quit_button = _new_button(_('Quit') + ' ' + NAME,
'application-exit', 'application-exit',
icon_size=_SMALL_BUTTON_ICON_SIZE, icon_size=_SMALL_BUTTON_ICON_SIZE,
clicked=destroy) clicked=destroy)
bottom_buttons_box.add(quit_button) bottom_buttons_box.add(quit_button)
about_button = _new_button(_("About") + ' ' + NAME, about_button = _new_button(_('About') + ' ' + NAME,
'help-about', 'help-about',
icon_size=_SMALL_BUTTON_ICON_SIZE, icon_size=_SMALL_BUTTON_ICON_SIZE,
clicked=_show_about_window) clicked=_show_about_window)
@ -444,7 +444,7 @@ def _receiver_row(receiver_path, receiver=None):
status_text, status_icon, receiver) status_text, status_icon, receiver)
assert len(row_data) == len(_TREE_SEPATATOR) assert len(row_data) == len(_TREE_SEPATATOR)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("new receiver row %s", row_data) _log.debug('new receiver row %s', row_data)
item = _model.append(None, row_data) item = _model.append(None, row_data)
if _TREE_SEPATATOR: if _TREE_SEPATATOR:
_model.append(None, _TREE_SEPATATOR) _model.append(None, _TREE_SEPATATOR)
@ -480,7 +480,7 @@ def _device_row(receiver_path, device_number, device=None):
device) device)
assert len(row_data) == len(_TREE_SEPATATOR) assert len(row_data) == len(_TREE_SEPATATOR)
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("new device row %s at index %d", row_data, _log.debug('new device row %s at index %d', row_data,
new_child_index) new_child_index)
item = _model.insert(receiver_row, new_child_index, row_data) item = _model.insert(receiver_row, new_child_index, row_data)
@ -503,7 +503,7 @@ def select(receiver_path, device_number=None):
selection = _tree.get_selection() selection = _tree.get_selection()
selection.select_iter(item) selection.select_iter(item)
else: else:
_log.warn("select(%s, %s) failed to find an item", receiver_path, _log.warn('select(%s, %s) failed to find an item', receiver_path,
device_number) device_number)
@ -548,33 +548,33 @@ def _update_details(button):
# cached, and involves no HID++ calls. # cached, and involves no HID++ calls.
if device.kind is None: if device.kind is None:
yield (_("Path"), device.path) yield (_('Path'), device.path)
# 046d is the Logitech vendor id # 046d is the Logitech vendor id
yield (_("USB id"), '046d:' + device.product_id) yield (_('USB id'), '046d:' + device.product_id)
if read_all: if read_all:
yield (_("Serial"), device.serial) yield (_('Serial'), device.serial)
else: else:
yield (_("Serial"), '...') yield (_('Serial'), '...')
else: else:
# yield ('Codename', device.codename) # yield ('Codename', device.codename)
yield (_("Index"), device.number) yield (_('Index'), device.number)
yield (_("Wireless PID"), device.wpid) yield (_('Wireless PID'), device.wpid)
hid_version = device.protocol hid_version = device.protocol
yield (_("Protocol"), 'HID++ %1.1f' % yield (_('Protocol'), 'HID++ %1.1f' %
hid_version if hid_version else _('Unknown')) hid_version if hid_version else _('Unknown'))
if read_all and device.polling_rate: if read_all and device.polling_rate:
yield (_("Polling rate"), yield (_('Polling rate'),
_('%(rate)d ms (%(rate_hz)dHz)') % { _('%(rate)d ms (%(rate_hz)dHz)') % {
'rate': device.polling_rate, 'rate': device.polling_rate,
'rate_hz': 1000 // device.polling_rate 'rate_hz': 1000 // device.polling_rate
}) })
if read_all or not device.online: if read_all or not device.online:
yield (_("Serial"), device.serial) yield (_('Serial'), device.serial)
else: else:
yield (_("Serial"), '...') yield (_('Serial'), '...')
if read_all: if read_all:
if device.firmware: if device.firmware:
@ -582,15 +582,15 @@ def _update_details(button):
yield (' ' + _(str(fw.kind)), yield (' ' + _(str(fw.kind)),
(fw.name + ' ' + fw.version).strip()) (fw.name + ' ' + fw.version).strip())
elif device.kind is None or device.online: elif device.kind is None or device.online:
yield (' %s' % _("Firmware"), '...') yield (' %s' % _('Firmware'), '...')
flag_bits = device.status.get(_K.NOTIFICATION_FLAGS) flag_bits = device.status.get(_K.NOTIFICATION_FLAGS)
if flag_bits is not None: if flag_bits is not None:
flag_names = ( flag_names = (
'(%s)' % _("none"), '(%s)' % _('none'),
) if flag_bits == 0 else _hidpp10.NOTIFICATION_FLAG.flag_names( ) if flag_bits == 0 else _hidpp10.NOTIFICATION_FLAG.flag_names(
flag_bits) flag_bits)
yield (_("Notifications"), ('\n%15s' % ' ').join(flag_names)) yield (_('Notifications'), ('\n%15s' % ' ').join(flag_names))
def _set_details(text): def _set_details(text):
_details._text.set_markup(text) _details._text.set_markup(text)
@ -696,7 +696,7 @@ def _update_device_panel(device, panel, buttons, full=False):
panel._battery._icon.set_sensitive(False) panel._battery._icon.set_sensitive(False)
panel._battery._icon.set_from_icon_name(icon_name, _INFO_ICON_SIZE) panel._battery._icon.set_from_icon_name(icon_name, _INFO_ICON_SIZE)
panel._battery._text.set_sensitive(True) panel._battery._text.set_sensitive(True)
panel._battery._text.set_markup('<small>%s</small>' % _("unknown")) panel._battery._text.set_markup('<small>%s</small>' % _('unknown'))
else: else:
charging = device.status.get(_K.BATTERY_CHARGING) charging = device.status.get(_K.BATTERY_CHARGING)
icon_name = _icons.battery(battery_level, charging) icon_name = _icons.battery(battery_level, charging)
@ -704,52 +704,52 @@ def _update_device_panel(device, panel, buttons, full=False):
panel._battery._icon.set_sensitive(True) panel._battery._icon.set_sensitive(True)
if battery_voltage is not None: if battery_voltage is not None:
text = "%(battery_voltage)dmV" % { text = '%(battery_voltage)dmV' % {
'battery_voltage': battery_voltage 'battery_voltage': battery_voltage
} }
elif isinstance(battery_level, _NamedInt): elif isinstance(battery_level, _NamedInt):
text = _(str(battery_level)) text = _(str(battery_level))
else: else:
text = "%(battery_percent)d%%" % {'battery_percent': battery_level} text = '%(battery_percent)d%%' % {'battery_percent': battery_level}
if battery_next_level is not None: if battery_next_level is not None:
if isinstance(battery_next_level, _NamedInt): if isinstance(battery_next_level, _NamedInt):
text += "<small> (" + _("next ") + _( text += '<small> (' + _('next ') + _(
str(battery_next_level)) + ")</small>" str(battery_next_level)) + ')</small>'
else: else:
text += "<small> (" + _("next ") + ( text += '<small> (' + _('next ') + (
"%d%%" % battery_next_level) + ")</small>" '%d%%' % battery_next_level) + ')</small>'
if is_online: if is_online:
if charging: if charging:
text += ' <small>(%s)</small>' % _("charging") text += ' <small>(%s)</small>' % _('charging')
else: else:
text += ' <small>(%s)</small>' % _("last known") text += ' <small>(%s)</small>' % _('last known')
panel._battery._text.set_sensitive(is_online) panel._battery._text.set_sensitive(is_online)
panel._battery._text.set_markup(text) panel._battery._text.set_markup(text)
if is_online: if is_online:
not_secure = device.status.get(_K.LINK_ENCRYPTED) == False not_secure = device.status.get(_K.LINK_ENCRYPTED) == False
if not_secure: if not_secure:
panel._secure._text.set_text(_("not encrypted")) panel._secure._text.set_text(_('not encrypted'))
panel._secure._icon.set_from_icon_name('security-low', panel._secure._icon.set_from_icon_name('security-low',
_INFO_ICON_SIZE) _INFO_ICON_SIZE)
panel._secure.set_tooltip_text( panel._secure.set_tooltip_text(
_("The wireless link between this device and its receiver is not encrypted.\n" _('The wireless link between this device and its receiver is not encrypted.\n'
"\n" '\n'
"For pointing devices (mice, trackballs, trackpads), this is a minor security issue.\n" 'For pointing devices (mice, trackballs, trackpads), this is a minor security issue.\n'
"\n" '\n'
"It is, however, a major security issue for text-input devices (keyboards, numpads),\n" 'It is, however, a major security issue for text-input devices (keyboards, numpads),\n'
"because typed text can be sniffed inconspicuously by 3rd parties within range." 'because typed text can be sniffed inconspicuously by 3rd parties within range.'
)) ))
else: else:
panel._secure._text.set_text(_("encrypted")) panel._secure._text.set_text(_('encrypted'))
panel._secure._icon.set_from_icon_name('security-high', panel._secure._icon.set_from_icon_name('security-high',
_INFO_ICON_SIZE) _INFO_ICON_SIZE)
panel._secure.set_tooltip_text( panel._secure.set_tooltip_text(
_("The wireless link between this device and its receiver is encrypted." _('The wireless link between this device and its receiver is encrypted.'
)) ))
panel._secure._icon.set_visible(True) panel._secure._icon.set_visible(True)
else: else:
panel._secure._text.set_markup('<small>%s</small>' % _("offline")) panel._secure._text.set_markup('<small>%s</small>' % _('offline'))
panel._secure._icon.set_visible(False) panel._secure._icon.set_visible(False)
panel._secure.set_tooltip_text('') panel._secure.set_tooltip_text('')
@ -761,7 +761,7 @@ def _update_device_panel(device, panel, buttons, full=False):
panel._lux._icon.set_from_icon_name(_icons.lux(light_level), panel._lux._icon.set_from_icon_name(_icons.lux(light_level),
_INFO_ICON_SIZE) _INFO_ICON_SIZE)
panel._lux._text.set_text( panel._lux._text.set_text(
_("%(light_level)d lux") % {'light_level': light_level}) _('%(light_level)d lux') % {'light_level': light_level})
panel._lux.set_visible(True) panel._lux.set_visible(True)
else: else:
panel._lux.set_visible(False) panel._lux.set_visible(False)
@ -898,7 +898,7 @@ def update(device, need_popup=False):
# peripheral # peripheral
is_paired = bool(device) is_paired = bool(device)
assert device.receiver assert device.receiver
assert device.number is not None and device.number > 0, "invalid device number" + str( assert device.number is not None and device.number > 0, 'invalid device number' + str(
device.number) device.number)
item = _device_row(device.receiver.path, device.number, item = _device_row(device.receiver.path, device.number,
device if is_paired else None) device if is_paired else None)
@ -915,13 +915,13 @@ def update(device, need_popup=False):
_model.set_value(item, _COLUMN.STATUS_ICON, _CAN_SET_ROW_NONE) _model.set_value(item, _COLUMN.STATUS_ICON, _CAN_SET_ROW_NONE)
else: else:
if battery_voltage is not None: if battery_voltage is not None:
status_text = "%(battery_voltage)dmV" % { status_text = '%(battery_voltage)dmV' % {
'battery_voltage': battery_voltage 'battery_voltage': battery_voltage
} }
elif isinstance(battery_level, _NamedInt): elif isinstance(battery_level, _NamedInt):
status_text = _(str(battery_level)) status_text = _(str(battery_level))
else: else:
status_text = "%(battery_percent)d%%" % { status_text = '%(battery_percent)d%%' % {
'battery_percent': battery_level 'battery_percent': battery_level
} }
_model.set_value(item, _COLUMN.STATUS_TEXT, status_text) _model.set_value(item, _COLUMN.STATUS_TEXT, status_text)

View File

@ -35,7 +35,7 @@ _suspend_callback = None
def _suspend(): def _suspend():
if _suspend_callback: if _suspend_callback:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("received suspend event") _log.info('received suspend event')
_suspend_callback() _suspend_callback()
@ -45,7 +45,7 @@ _resume_callback = None
def _resume(): def _resume():
if _resume_callback: if _resume_callback:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info("received resume event") _log.info('received resume event')
_resume_callback() _resume_callback()
@ -93,11 +93,11 @@ try:
if _log.isEnabledFor(_INFO): if _log.isEnabledFor(_INFO):
_log.info( _log.info(
"connected to system dbus, watching for suspend/resume events") 'connected to system dbus, watching for suspend/resume events')
except: except:
# Either: # Either:
# - the dbus library is not available # - the dbus library is not available
# - the system dbus is not running # - the system dbus is not running
_log.warn("failed to register suspend/resume callbacks") _log.warn('failed to register suspend/resume callbacks')
pass pass

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from glob import glob as _glob from glob import glob as _glob
try: try:
from setuptools import setup from setuptools import setup
except ImportError: except ImportError:

View File

@ -13,7 +13,7 @@ sys.path += (sys.path[0] + '/../lib', )
def print_event(action, device): def print_event(action, device):
print("~~~~ device [%s] %s" % (action, device)) print('~~~~ device [%s] %s' % (action, device))
hidapi.monitor(print_event, DEVICE_UNIFYING_RECEIVER, hidapi.monitor(print_event, DEVICE_UNIFYING_RECEIVER,