ui: refactor code to record change to setting
This commit is contained in:
parent
059ebecf84
commit
468fad1358
|
@ -411,9 +411,7 @@ def _process_feature_notification(device, status, n, feature):
|
||||||
if (n.address == 0x00):
|
if (n.address == 0x00):
|
||||||
level = _unpack('!B', n.data[1:2])[0]
|
level = _unpack('!B', n.data[1:2])[0]
|
||||||
from solaar.ui.config_panel import record_setting # prevent circular import
|
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)
|
record_setting(device, _st.Backlight2Level, [level])
|
||||||
if setting:
|
|
||||||
record_setting(device, setting, [level])
|
|
||||||
|
|
||||||
elif feature == _F.REPROG_CONTROLS_V4:
|
elif feature == _F.REPROG_CONTROLS_V4:
|
||||||
if n.address == 0x00:
|
if n.address == 0x00:
|
||||||
|
@ -443,9 +441,7 @@ def _process_feature_notification(device, status, n, feature):
|
||||||
logger.info('%s: WHEEL: ratchet: %d', device, ratchet)
|
logger.info('%s: WHEEL: ratchet: %d', device, ratchet)
|
||||||
if ratchet < 2: # don't process messages with unusual ratchet values
|
if ratchet < 2: # don't process messages with unusual ratchet values
|
||||||
from solaar.ui.config_panel import record_setting # prevent circular import
|
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)
|
record_setting(device, _st.ScrollRatchet, [2 if ratchet else 1])
|
||||||
if setting:
|
|
||||||
record_setting(device, setting, [2 if ratchet else 1])
|
|
||||||
else:
|
else:
|
||||||
if logger.isEnabledFor(logging.INFO):
|
if logger.isEnabledFor(logging.INFO):
|
||||||
logger.info('%s: unknown WHEEL %s', device, n)
|
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)
|
logger.info('%s: unknown ONBOARD PROFILES %s', device, n)
|
||||||
else:
|
else:
|
||||||
if (n.address == 0x00):
|
if (n.address == 0x00):
|
||||||
resolution_index = None
|
|
||||||
profile_sector = _unpack('!H', n.data[:2])[0]
|
profile_sector = _unpack('!H', n.data[:2])[0]
|
||||||
|
if profile_sector:
|
||||||
|
profile_change(device, profile_sector)
|
||||||
elif (n.address == 0x10):
|
elif (n.address == 0x10):
|
||||||
resolution_index = _unpack('!B', n.data[:1])[0]
|
resolution_index = _unpack('!B', n.data[:1])[0]
|
||||||
profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0]
|
profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0]
|
||||||
if profile_sector:
|
for profile in device.profiles.profiles.values() if device.profiles else []:
|
||||||
profile_change(device, profile_sector, resolution_index)
|
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)
|
_diversion.process_notification(device, status, n, feature)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# change UI to show result of onboard profile change
|
# change UI to show result of onboard profile change
|
||||||
def profile_change(device, profile_sector, resolution_index=None):
|
def profile_change(device, profile_sector):
|
||||||
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])
|
|
||||||
from solaar.ui.config_panel import record_setting # prevent circular import
|
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 []:
|
for profile in device.profiles.profiles.values() if device.profiles else []:
|
||||||
if profile.sector == profile_sector:
|
if profile.sector == profile_sector:
|
||||||
if resolution_index is None:
|
resolution_index = profile.resolution_default_index
|
||||||
resolution_index = profile.resolution_default_index
|
record_setting(device, _st.AdjustableDpi, [profile.resolutions[resolution_index]])
|
||||||
setting = next((s for s in device.settings if s.name == _st.AdjustableDpi.name), None)
|
record_setting(device, _st.ReportRate, [profile.report_rate])
|
||||||
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])
|
|
||||||
break
|
break
|
||||||
|
|
|
@ -819,22 +819,24 @@ def _change_setting(device, setting, values):
|
||||||
|
|
||||||
|
|
||||||
def record_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"""
|
"""External interface to have the GUI show a change to a setting. Doesn't write to the device"""
|
||||||
assert device == setting._device
|
|
||||||
GLib.idle_add(_record_setting, device, setting, values, priority=99)
|
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):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug('on %s changing setting %s to %s', device, setting, values)
|
logger.debug('on %s changing setting %s to %s', device, setting_class.name, values)
|
||||||
if len(values) > 1:
|
setting = next((s for s in device.settings if s.name == setting_class.name), None)
|
||||||
setting.update_key_value(values[0], values[-1])
|
assert device == setting._device
|
||||||
value = {values[0]: values[-1]}
|
if setting:
|
||||||
else:
|
if len(values) > 1:
|
||||||
setting.update(values[-1])
|
setting.update_key_value(values[0], values[-1])
|
||||||
value = values[-1]
|
value = {values[0]: values[-1]}
|
||||||
device_path = device.receiver.path if device.receiver else device.path
|
else:
|
||||||
if (device_path, device.number, setting.name) in _items:
|
setting.update(values[-1])
|
||||||
sbox = _items[(device_path, device.number, setting.name)]
|
value = values[-1]
|
||||||
if sbox:
|
device_path = device.receiver.path if device.receiver else device.path
|
||||||
_update_setting_item(sbox, value)
|
if (device_path, device.number, setting.name) in _items:
|
||||||
|
sbox = _items[(device_path, device.number, setting.name)]
|
||||||
|
if sbox:
|
||||||
|
_update_setting_item(sbox, value)
|
||||||
|
|
Loading…
Reference in New Issue