diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py index 32d11052..4dbb3db3 100644 --- a/lib/logitech_receiver/notifications.py +++ b/lib/logitech_receiver/notifications.py @@ -411,9 +411,7 @@ def _process_feature_notification(device, status, n, feature): if (n.address == 0x00): level = _unpack('!B', n.data[1:2])[0] from solaar.ui.config_panel import record_setting # prevent circular import - setting = next((s for s in device.settings if s.name == _st.Backlight2Level.name), None) - if setting: - record_setting(device, setting, [level]) + record_setting(device, _st.Backlight2Level, [level]) elif feature == _F.REPROG_CONTROLS_V4: if n.address == 0x00: @@ -443,9 +441,7 @@ def _process_feature_notification(device, status, n, feature): 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 - setting = next((s for s in device.settings if s.name == _st.ScrollRatchet.name), None) - if setting: - record_setting(device, setting, [2 if ratchet else 1]) + record_setting(device, _st.ScrollRatchet, [2 if ratchet else 1]) else: if logger.isEnabledFor(logging.INFO): logger.info('%s: unknown WHEEL %s', device, n) @@ -456,33 +452,28 @@ def _process_feature_notification(device, status, n, feature): logger.info('%s: unknown ONBOARD PROFILES %s', device, n) else: if (n.address == 0x00): - resolution_index = None profile_sector = _unpack('!H', n.data[:2])[0] + if profile_sector: + profile_change(device, profile_sector) elif (n.address == 0x10): resolution_index = _unpack('!B', n.data[:1])[0] profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0] - if profile_sector: - profile_change(device, profile_sector, resolution_index) + 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) return True # change UI to show result of onboard profile change -def profile_change(device, profile_sector, resolution_index=None): - from solaar.ui.config_panel import record_setting # prevent circular import - setting = next((s for s in device.settings if s.name == _st.OnboardProfiles.name), None) - if setting: - record_setting(device, setting, [profile_sector]) +def profile_change(device, profile_sector): from solaar.ui.config_panel import record_setting # prevent circular import + record_setting(device, _st.OnboardProfiles, [profile_sector]) for profile in device.profiles.profiles.values() if device.profiles else []: if profile.sector == profile_sector: - if resolution_index is None: - resolution_index = profile.resolution_default_index - setting = next((s for s in device.settings if s.name == _st.AdjustableDpi.name), None) - if setting: - record_setting(device, setting, [profile.resolutions[resolution_index]]) - setting = next((s for s in device.settings if s.name == _st.ReportRate.name), None) - if setting: - record_setting(device, setting, [profile.report_rate]) + resolution_index = profile.resolution_default_index + record_setting(device, _st.AdjustableDpi, [profile.resolutions[resolution_index]]) + record_setting(device, _st.ReportRate, [profile.report_rate]) break diff --git a/lib/solaar/ui/config_panel.py b/lib/solaar/ui/config_panel.py index 670c724d..e9fcad8b 100644 --- a/lib/solaar/ui/config_panel.py +++ b/lib/solaar/ui/config_panel.py @@ -819,22 +819,24 @@ def _change_setting(device, setting, values): def record_setting(device, setting, values): - """External interface to record a setting that has changed on the device and have the GUI show the change""" - assert device == setting._device + """External interface to have the GUI show a change to a setting. Doesn't write to the device""" GLib.idle_add(_record_setting, device, setting, values, priority=99) -def _record_setting(device, setting, values): +def _record_setting(device, setting_class, values): if logger.isEnabledFor(logging.DEBUG): - logger.debug('on %s changing setting %s to %s', device, setting, values) - if len(values) > 1: - setting.update_key_value(values[0], values[-1]) - value = {values[0]: values[-1]} - else: - setting.update(values[-1]) - value = values[-1] - device_path = device.receiver.path if device.receiver else device.path - if (device_path, device.number, setting.name) in _items: - sbox = _items[(device_path, device.number, setting.name)] - if sbox: - _update_setting_item(sbox, value) + logger.debug('on %s changing setting %s to %s', device, setting_class.name, values) + setting = next((s for s in device.settings if s.name == setting_class.name), None) + assert device == setting._device + if setting: + if len(values) > 1: + setting.update_key_value(values[0], values[-1]) + value = {values[0]: values[-1]} + else: + setting.update(values[-1]) + value = values[-1] + device_path = device.receiver.path if device.receiver else device.path + if (device_path, device.number, setting.name) in _items: + sbox = _items[(device_path, device.number, setting.name)] + if sbox: + _update_setting_item(sbox, value)