python 3 fixes
This commit is contained in:
parent
84540fb087
commit
d6b18cd426
|
|
@ -16,7 +16,7 @@ class _DUMMY_RECEIVER(object):
|
||||||
__slots__ = ['name', 'max_devices', 'status']
|
__slots__ = ['name', 'max_devices', 'status']
|
||||||
name = _lur.Receiver.name
|
name = _lur.Receiver.name
|
||||||
max_devices = _lur.Receiver.max_devices
|
max_devices = _lur.Receiver.max_devices
|
||||||
status = 'Receiver not found'
|
status = 'Receiver not found.'
|
||||||
__bool__ = __nonzero__ = lambda self: False
|
__bool__ = __nonzero__ = lambda self: False
|
||||||
__str__ = lambda self: 'DUMMY'
|
__str__ = lambda self: 'DUMMY'
|
||||||
DUMMY = _DUMMY_RECEIVER()
|
DUMMY = _DUMMY_RECEIVER()
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ GObject.threads_init()
|
||||||
|
|
||||||
|
|
||||||
from solaar import NAME
|
from solaar import NAME
|
||||||
_APP_ICONS = (NAME + '-fail', NAME + '-init', NAME)
|
_APP_ICONS = (NAME + '-init', NAME + '-fail', NAME)
|
||||||
def appicon(receiver_status):
|
def appicon(receiver_status):
|
||||||
return (_APP_ICONS[0] if receiver_status < 0 else
|
return (_APP_ICONS[1] if type(receiver_status) == str else
|
||||||
_APP_ICONS[1] if receiver_status < 1 else
|
_APP_ICONS[2] if receiver_status else
|
||||||
_APP_ICONS[2])
|
_APP_ICONS[0])
|
||||||
|
|
||||||
|
|
||||||
_ICON_THEME = Gtk.IconTheme.get_default()
|
_ICON_THEME = Gtk.IconTheme.get_default()
|
||||||
|
|
|
||||||
|
|
@ -47,13 +47,13 @@ def _show_about_window(action):
|
||||||
about.set_comments('Shows status of devices connected\nto a Logitech Unifying Receiver.')
|
about.set_comments('Shows status of devices connected\nto a Logitech Unifying Receiver.')
|
||||||
|
|
||||||
about.set_license_type(Gtk.License.GPL_2_0)
|
about.set_license_type(Gtk.License.GPL_2_0)
|
||||||
about.set_copyright('\xC2\xA9 2012 Daniel Pavel')
|
about.set_copyright(b'\xC2\xA9'.decode('utf-8') + ' 2012 Daniel Pavel')
|
||||||
|
|
||||||
about.set_authors(('Daniel Pavel http://github.com/pwr',))
|
about.set_authors(('Daniel Pavel http://github.com/pwr',))
|
||||||
try:
|
try:
|
||||||
about.add_credit_section('Testing', ('Douglas Wagner',))
|
about.add_credit_section('Testing', ('Douglas Wagner',))
|
||||||
except Exception as e:
|
except Exception:
|
||||||
print e
|
pass
|
||||||
|
|
||||||
about.set_website('http://github.com/pwr/Solaar/wiki')
|
about.set_website('http://github.com/pwr/Solaar/wiki')
|
||||||
about.set_website_label('Solaar Wiki')
|
about.set_website_label('Solaar Wiki')
|
||||||
|
|
|
||||||
|
|
@ -4,5 +4,5 @@ Z=`readlink -f "$0"`
|
||||||
LIB=`readlink -f $(dirname "$Z")/../lib`
|
LIB=`readlink -f $(dirname "$Z")/../lib`
|
||||||
export PYTHONPATH=$LIB
|
export PYTHONPATH=$LIB
|
||||||
|
|
||||||
PYTHON=`which python python2 python3 | head -n 1`
|
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
|
||||||
exec $PYTHON -u -m hidapi.hidconsole "$@"
|
exec $PYTHON -u -m hidapi.hidconsole "$@"
|
||||||
|
|
|
||||||
2
bin/scan
2
bin/scan
|
|
@ -4,5 +4,5 @@ Z=`readlink -f "$0"`
|
||||||
LIB=`readlink -f $(dirname "$Z")/../lib`
|
LIB=`readlink -f $(dirname "$Z")/../lib`
|
||||||
export PYTHONPATH=$LIB
|
export PYTHONPATH=$LIB
|
||||||
|
|
||||||
PYTHON=`which python python2 python3 | head -n 1`
|
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
|
||||||
exec $PYTHON -u -m logitech.scanner "$@"
|
exec $PYTHON -u -m logitech.scanner "$@"
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,5 @@ SHARE=`readlink -f $(dirname "$Z")/../share`
|
||||||
export PYTHONPATH=$APP:$LIB
|
export PYTHONPATH=$APP:$LIB
|
||||||
export XDG_DATA_DIRS=${SHARE}_override:$SHARE:$XDG_DATA_DIRS
|
export XDG_DATA_DIRS=${SHARE}_override:$SHARE:$XDG_DATA_DIRS
|
||||||
|
|
||||||
PYTHON=`which python python2 python3 | head -n 1`
|
PYTHON=${PYTHON:-`which python python2 python3 | head -n 1`}
|
||||||
exec $PYTHON -u -m solaar "$@"
|
exec $PYTHON -u -m solaar "$@"
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ def print_receiver(receiver):
|
||||||
print (" Reported %d paired device(s)." % len(receiver))
|
print (" Reported %d paired device(s)." % len(receiver))
|
||||||
activity = receiver.request(0x83B3)
|
activity = receiver.request(0x83B3)
|
||||||
if activity:
|
if activity:
|
||||||
activity = [(d, ord(activity[d - 1])) for d in range(1, receiver.max_devices)]
|
activity = [(d, ord(activity[d - 1:d])) for d in range(1, receiver.max_devices)]
|
||||||
print(" Device activity counters: %s" % ', '.join(('%d=%d' % (d, a)) for d, a in activity if a > 0))
|
print(" Device activity counters: %s" % ', '.join(('%d=%d' % (d, a)) for d, a in activity if a > 0))
|
||||||
|
|
||||||
def scan_devices(receiver):
|
def scan_devices(receiver):
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ _log = getLogger('LUR.base')
|
||||||
del getLogger
|
del getLogger
|
||||||
|
|
||||||
from .common import strhex as _strhex, KwException as _KwException
|
from .common import strhex as _strhex, KwException as _KwException
|
||||||
import hidpp10 as _hidpp10
|
from . import hidpp10 as _hidpp10
|
||||||
import hidpp20 as _hidpp20
|
from . import hidpp20 as _hidpp20
|
||||||
import hidapi as _hid
|
import hidapi as _hid
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -45,7 +45,7 @@ class NoReceiver(_KwException):
|
||||||
|
|
||||||
class NoSuchDevice(_KwException):
|
class NoSuchDevice(_KwException):
|
||||||
"""Raised when trying to reach a device number not paired to the receiver."""
|
"""Raised when trying to reach a device number not paired to the receiver."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DeviceUnreachable(_KwException):
|
class DeviceUnreachable(_KwException):
|
||||||
|
|
@ -135,14 +135,14 @@ 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[0]), devnumber, _strhex(wdata[2:4]), _strhex(wdata[4:]))
|
_log.debug("(%s) <= w[%02X %02X %s %s]", handle, ord(wdata[:1]), 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 %s no longer available", repr(handle))
|
_log.error("write failed, assuming handle %s no longer available", repr(handle))
|
||||||
close(handle)
|
close(handle)
|
||||||
raise NoReceiver(reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
|
|
||||||
def read(handle, timeout=DEFAULT_TIMEOUT):
|
def read(handle, timeout=DEFAULT_TIMEOUT):
|
||||||
|
|
@ -167,7 +167,7 @@ def _read(handle, timeout):
|
||||||
except Exception as reason:
|
except Exception as reason:
|
||||||
_log.error("read failed, assuming handle %s no longer available", repr(handle))
|
_log.error("read failed, assuming handle %s no longer available", repr(handle))
|
||||||
close(handle)
|
close(handle)
|
||||||
raise NoReceiver(reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
report_id = ord(data[:1])
|
report_id = ord(data[:1])
|
||||||
|
|
@ -192,7 +192,7 @@ def _skip_incoming(handle):
|
||||||
except Exception as reason:
|
except Exception as reason:
|
||||||
_log.error("read failed, assuming receiver %s no longer available", handle)
|
_log.error("read failed, assuming receiver %s no longer available", handle)
|
||||||
close(handle)
|
close(handle)
|
||||||
raise NoReceiver(reason)
|
raise NoReceiver(reason=reason)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
report_id = ord(data[:1])
|
report_id = ord(data[:1])
|
||||||
|
|
@ -320,7 +320,8 @@ def request(handle, devnumber, request_id, *params):
|
||||||
|
|
||||||
if delta >= timeout:
|
if delta >= timeout:
|
||||||
_log.warn("timeout on device %d request {%04X} params[%s]", devnumber, request_id, _strhex(params))
|
_log.warn("timeout on device %d request {%04X} params[%s]", devnumber, request_id, _strhex(params))
|
||||||
raise DeviceUnreachable(number=devnumber, request=request_id)
|
break
|
||||||
|
# raise DeviceUnreachable(number=devnumber, request=request_id)
|
||||||
|
|
||||||
|
|
||||||
def ping(handle, devnumber):
|
def ping(handle, devnumber):
|
||||||
|
|
@ -362,14 +363,15 @@ def ping(handle, devnumber):
|
||||||
return 1.0
|
return 1.0
|
||||||
|
|
||||||
if error == _hidpp10.ERROR.resource_error: # device unreachable
|
if error == _hidpp10.ERROR.resource_error: # device unreachable
|
||||||
raise DeviceUnreachable(number=devnumber, request=request_id)
|
# raise DeviceUnreachable(number=devnumber, request=request_id)
|
||||||
|
break
|
||||||
|
|
||||||
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("(%s) device %d error on ping request: unknown device", handle, devnumber)
|
_log.error("(%s) device %d error on ping request: unknown device", handle, devnumber)
|
||||||
raise NoSuchDevice(devnumber)
|
raise NoSuchDevice(number=devnumber, request=request_id)
|
||||||
|
|
||||||
_unhandled(report_id, number, data)
|
_unhandled(report_id, number, data)
|
||||||
|
|
||||||
if delta >= _PING_TIMEOUT:
|
if delta >= _PING_TIMEOUT:
|
||||||
_log.warn("(%s) timeout on device %d ping", handle, devnumber)
|
_log.warn("(%s) timeout on device %d ping", handle, devnumber)
|
||||||
raise DeviceUnreachable(number=devnumber, request=request_id)
|
# raise DeviceUnreachable(number=devnumber, request=request_id)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from struct import pack as _pack
|
||||||
|
|
||||||
class NamedInt(int):
|
class NamedInt(int):
|
||||||
"""An integer with an attached name."""
|
"""An integer with an attached name."""
|
||||||
__slots__ = ['name']
|
# __slots__ = ['name']
|
||||||
|
|
||||||
def __new__(cls, value, name):
|
def __new__(cls, value, name):
|
||||||
obj = int.__new__(cls, value)
|
obj = int.__new__(cls, value)
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ class EventsListener(_threading.Thread):
|
||||||
|
|
||||||
self.has_started()
|
self.has_started()
|
||||||
|
|
||||||
last_tick = _timestamp() if self.tick_period else 0
|
last_tick = 0
|
||||||
|
|
||||||
while self._active:
|
while self._active:
|
||||||
if self._queued_events.empty():
|
if self._queued_events.empty():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue