Skip to content

Commit

Permalink
device: improve imports in logitech_receiver
Browse files Browse the repository at this point in the history
device: move imports of ui modules to beginning of files

logitech_receiver: remove imports from __init__.py
  • Loading branch information
pfps committed Feb 18, 2024
1 parent d1c899d commit 12de240
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
7 changes: 0 additions & 7 deletions lib/logitech_receiver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@

import logging

from . import listener, status # noqa: F401
from .base import DeviceUnreachable, NoReceiver, NoSuchDevice # noqa: F401
from .common import strhex # noqa: F401
from .device import Device # noqa: F401
from .hidpp20 import FeatureCallError, FeatureNotSupported # noqa: F401
from .receiver import Receiver # noqa: F401

logger = logging.getLogger(__name__)
logger.setLevel(logging.root.level)
# if logging.root.level > logging.DEBUG:
Expand Down
5 changes: 2 additions & 3 deletions lib/logitech_receiver/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from struct import unpack as _unpack

from solaar.ui.config_panel import record_setting

from . import diversion as _diversion
from . import hidpp10 as _hidpp10
from . import hidpp20 as _hidpp20
Expand Down Expand Up @@ -410,7 +412,6 @@ def _process_feature_notification(device, status, n, feature):
elif feature == _F.BACKLIGHT2:
if (n.address == 0x00):
level = _unpack('!B', n.data[1:2])[0]
from solaar.ui.config_panel import record_setting # prevent circular import
record_setting(device, _st.Backlight2Level, [level])

elif feature == _F.REPROG_CONTROLS_V4:
Expand Down Expand Up @@ -440,7 +441,6 @@ def _process_feature_notification(device, status, n, feature):
if logger.isEnabledFor(logging.INFO):
logger.info('%s: WHEEL: ratchet: %d', device, ratchet)
if ratchet < 2: # don't process messages with unusual ratchet values
from solaar.ui.config_panel import record_setting # prevent circular import
record_setting(device, _st.ScrollRatchet, [2 if ratchet else 1])
else:
if logger.isEnabledFor(logging.INFO):
Expand All @@ -460,7 +460,6 @@ def _process_feature_notification(device, status, n, feature):
profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0]
for profile in device.profiles.profiles.values() if device.profiles else []:
if profile.sector == profile_sector:
from solaar.ui.config_panel import record_setting # prevent circular import
record_setting(device, _st.AdjustableDpi, [profile.resolutions[resolution_index]])

_diversion.process_notification(device, status, n, feature)
Expand Down
8 changes: 5 additions & 3 deletions lib/solaar/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
from importlib import import_module
from traceback import extract_tb, format_exc

from logitech_receiver import Device, Receiver
import logitech_receiver.device as _device
import logitech_receiver.receiver as _receiver

from logitech_receiver.base import receivers, receivers_and_devices
from solaar import NAME

Expand Down Expand Up @@ -113,7 +115,7 @@ def _receivers(dev_path=None):
if dev_path is not None and dev_path != dev_info.path:
continue
try:
r = Receiver.open(dev_info)
r = _receiver.Receiver.open(dev_info)
if logger.isEnabledFor(logging.DEBUG):
logger.debug('[%s] => %s', dev_info.path, r)
if r:
Expand All @@ -128,7 +130,7 @@ def _receivers_and_devices(dev_path=None):
if dev_path is not None and dev_path != dev_info.path:
continue
try:
d = Device.open(dev_info) if dev_info.isDevice else Receiver.open(dev_info)
d = _device.Device.open(dev_info) if dev_info.isDevice else _receiver.Receiver.open(dev_info)
if logger.isEnabledFor(logging.DEBUG):
logger.debug('[%s] => %s', dev_info.path, d)
if d is not None:
Expand Down
7 changes: 4 additions & 3 deletions lib/solaar/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
from collections import namedtuple

import gi
import logitech_receiver.device as _device
import logitech_receiver.receiver as _receiver

from logitech_receiver import Device, Receiver
from logitech_receiver import base as _base
from logitech_receiver import hidpp10 as _hidpp10
from logitech_receiver import listener as _listener
Expand Down Expand Up @@ -302,9 +303,9 @@ def _start(device_info):
assert _status_callback
isDevice = device_info.isDevice
if not isDevice:
receiver = Receiver.open(device_info)
receiver = _receiver.Receiver.open(device_info)
else:
receiver = Device.open(device_info)
receiver = _device.Device.open(device_info)
configuration.attach_to(receiver)

if receiver:
Expand Down
4 changes: 3 additions & 1 deletion lib/solaar/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import gi

from gi.repository import Gdk, GLib, Gtk
from gi.repository.GObject import TYPE_PYOBJECT
from logitech_receiver import hidpp10 as _hidpp10
from logitech_receiver.common import NamedInt as _NamedInt
Expand All @@ -38,6 +37,9 @@

# from solaar import __version__ as VERSION

gi.require_version('Gdk', '3.0')
from gi.repository import Gdk, GLib, Gtk # NOQA: E402

logger = logging.getLogger(__name__)

#
Expand Down

0 comments on commit 12de240

Please sign in to comment.