ui: implement setting_changed callback and pass in to new devices and receivers

This commit is contained in:
Peter F. Patel-Schneider 2024-02-18 13:53:03 -05:00
parent ed248c62b9
commit 6f633efac5
4 changed files with 17 additions and 8 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)