From 4e2f2aae10b7d3d7f5c1a9298b3443dcc3597e0f Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sun, 11 Feb 2024 00:34:29 -0500 Subject: [PATCH] device: improve imports in logitech_receiver device: move imports of ui modules to beginning of files logitech_receiver: remove imports from __init__.py --- lib/logitech_receiver/__init__.py | 7 ------- lib/logitech_receiver/notifications.py | 5 ++--- lib/solaar/cli/__init__.py | 8 +++++--- lib/solaar/listener.py | 7 ++++--- lib/solaar/ui/window.py | 4 +++- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/logitech_receiver/__init__.py b/lib/logitech_receiver/__init__.py index e31407edac..46aa1f0a20 100644 --- a/lib/logitech_receiver/__init__.py +++ b/lib/logitech_receiver/__init__.py @@ -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: diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py index 9586aacd6a..1d23c1fa6c 100644 --- a/lib/logitech_receiver/notifications.py +++ b/lib/logitech_receiver/notifications.py @@ -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 @@ -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: @@ -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): @@ -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) diff --git a/lib/solaar/cli/__init__.py b/lib/solaar/cli/__init__.py index e77e179d09..5fc68f0dae 100644 --- a/lib/solaar/cli/__init__.py +++ b/lib/solaar/cli/__init__.py @@ -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 @@ -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: @@ -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: diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 94b39605f9..0e4c027c6a 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -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 @@ -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: diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index 99800cc0b0..5728e23444 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -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 @@ -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__) #