From 6f633efac58e480fc54b4a06e61a0c6d449de94c Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Sun, 18 Feb 2024 13:53:03 -0500 Subject: [PATCH] ui: implement setting_changed callback and pass in to new devices and receivers --- lib/logitech_receiver/status.py | 5 ++++- lib/solaar/gtk.py | 2 +- lib/solaar/listener.py | 12 +++++++----- lib/solaar/ui/__init__.py | 6 +++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/logitech_receiver/status.py b/lib/logitech_receiver/status.py index 4fd9f137..dd293f82 100644 --- a/lib/logitech_receiver/status.py +++ b/lib/logitech_receiver/status.py @@ -94,7 +94,7 @@ class ReceiverStatus(dict): self[KEYS.ERROR] = None - def __str__(self): + def to_string(self): count = len(self._receiver) return ( _('No paired devices.') @@ -103,6 +103,9 @@ class ReceiverStatus(dict): } ) + def __str__(self): + self.to_string() + def changed(self, alert=ALERT.NOTIFICATION, reason=None): self._changed_callback(self._receiver, alert=alert, reason=reason) diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index 0bb54660..21b4732d 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -168,7 +168,7 @@ def main(): logger.warning('Solaar udev file not found in expected location') logger.warning('See https://pwr-solaar.github.io/Solaar/installation for more information') try: - _listener.setup_scanner(_ui.status_changed, _common.error_dialog) + _listener.setup_scanner(_ui.status_changed, _ui.setting_changed, _common.error_dialog) if args.restart_on_wake_up: _upower.watch(_listener.start_all, _listener.stop_all) diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 717dc385..eabf0f8d 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -301,12 +301,12 @@ _all_listeners = {} def _start(device_info): - assert _status_callback + assert _status_callback and _setting_callback isDevice = device_info.isDevice if not isDevice: - receiver = _receiver.Receiver.open(device_info) + receiver = _receiver.Receiver.open(device_info, _setting_callback) else: - receiver = _device.Device.open(device_info) + receiver = _device.Device.open(device_info, _setting_callback) configuration.attach_to(receiver) if receiver: @@ -374,14 +374,16 @@ def ping_all(resuming=False): _status_callback = None +_setting_callback = None _error_callback = None -def setup_scanner(status_changed_callback, error_callback): - global _status_callback, _error_callback +def setup_scanner(status_changed_callback, setting_changed_callback, error_callback): + global _status_callback, _error_callback, _setting_callback assert _status_callback is None, 'scanner was already set-up' _status_callback = status_changed_callback + _setting_callback = setting_changed_callback _error_callback = error_callback _base.notify_on_receivers_glib(_process_receiver_event) diff --git a/lib/solaar/ui/__init__.py b/lib/solaar/ui/__init__.py index ed96a067..67cf3624 100644 --- a/lib/solaar/ui/__init__.py +++ b/lib/solaar/ui/__init__.py @@ -23,7 +23,7 @@ import yaml as _yaml from logitech_receiver.status import ALERT from solaar.i18n import _ -from solaar.ui.config_panel import change_setting +from solaar.ui.config_panel import change_setting, record_setting from solaar.ui.window import find_device from . import common, diversion_rules, notify, tray, window @@ -131,3 +131,7 @@ def _status_changed(device, alert, reason, refresh=False): def status_changed(device, alert=ALERT.NONE, reason=None, refresh=False): GLib.idle_add(_status_changed, device, alert, reason, refresh) + + +def setting_changed(device, setting_class, vals): + record_setting(device, setting_class, vals)