ui: add ability to ignore a Solaar setting
This commit is contained in:
parent
2ce8a3b249
commit
b34061c766
|
@ -37,6 +37,7 @@ del getLogger
|
|||
#
|
||||
#
|
||||
|
||||
SENSITIVITY_IGNORE = 'ignore'
|
||||
KIND = _NamedInts(toggle=0x01, choice=0x02, range=0x04, map_choice=0x0A, multiple_toggle=0x10, multiple_range=0x40)
|
||||
|
||||
|
||||
|
@ -1029,3 +1030,12 @@ class MultipleRangeValidator:
|
|||
raise ValueError(f'invalid choice for {item}.{sub_item}: {v} not in [{sub_item.minimum}..{sub_item.maximum}]')
|
||||
w += _int2bytes(v, sub_item.length)
|
||||
return w + b'\xFF'
|
||||
|
||||
|
||||
def apply_all_settings(device):
|
||||
persister = getattr(device, 'persister', None)
|
||||
sensitives = persister.get('_sensitive', {}) if persister else {}
|
||||
for s in device.settings:
|
||||
ignore = sensitives.get(s.name, False)
|
||||
if ignore != SENSITIVITY_IGNORE:
|
||||
s.apply()
|
||||
|
|
|
@ -26,6 +26,7 @@ from time import time as _timestamp
|
|||
|
||||
from . import hidpp10 as _hidpp10
|
||||
from . import hidpp20 as _hidpp20
|
||||
from . import settings as _settings
|
||||
from .common import BATTERY_APPROX as _BATTERY_APPROX
|
||||
from .common import NamedInt as _NamedInt
|
||||
from .common import NamedInts as _NamedInts
|
||||
|
@ -306,8 +307,7 @@ class DeviceStatus(dict):
|
|||
# make sure they're up-to-date.
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info('%s pushing device settings %s', d, d.settings)
|
||||
for s in d.settings:
|
||||
s.apply()
|
||||
_settings.apply_all_settings(d)
|
||||
|
||||
# battery information may have changed so try to read it now
|
||||
self.read_battery(timestamp)
|
||||
|
|
|
@ -127,8 +127,7 @@ def run(receivers, args, find_receiver, find_device):
|
|||
if not dev.settings:
|
||||
raise Exception('no settings for %s' % dev.name)
|
||||
_configuration.attach_to(dev)
|
||||
for s in dev.settings:
|
||||
s.apply()
|
||||
_settings.apply_all_settings(dev)
|
||||
print(dev.name, '(%s) [%s:%s]' % (dev.codename, dev.wpid, dev.serial))
|
||||
for s in dev.settings:
|
||||
print('')
|
||||
|
|
|
@ -23,6 +23,7 @@ from threading import Timer as _Timer
|
|||
|
||||
from gi.repository import Gdk, GLib, Gtk
|
||||
from logitech_receiver.settings import KIND as _SETTING_KIND
|
||||
from logitech_receiver.settings import SENSITIVITY_IGNORE as _SENSITIVITY_IGNORE
|
||||
from solaar.i18n import _, ngettext
|
||||
from solaar.ui import ui_async as _ui_async
|
||||
|
||||
|
@ -352,22 +353,34 @@ def _create_multiple_range_control(setting, change):
|
|||
#
|
||||
#
|
||||
|
||||
_allowables_icons = {True: 'changes-allow', False: 'changes-prevent', _SENSITIVITY_IGNORE: 'dialog-error'}
|
||||
_allowables_tooltips = {
|
||||
True: _('Changes allowed'),
|
||||
False: _('No changes allowed'),
|
||||
_SENSITIVITY_IGNORE: _('Ignore this setting')
|
||||
}
|
||||
_next_allowable = {True: False, False: _SENSITIVITY_IGNORE, _SENSITIVITY_IGNORE: True}
|
||||
_icons_allowables = {v: k for k, v in _allowables_icons.items()}
|
||||
|
||||
# clicking on the lock icon changes the sensitivity of the setting
|
||||
|
||||
# clicking on the lock icon changes from changeable to unchangeable to ignore
|
||||
def _change_click(eb, button, arg):
|
||||
control, device, name = arg
|
||||
sensitive = not control.get_sensitive()
|
||||
control.set_sensitive(sensitive)
|
||||
icon = eb.get_children()[0]
|
||||
_change_icon(sensitive, icon)
|
||||
icon_name, _ = icon.get_icon_name()
|
||||
allowed = _icons_allowables.get(icon_name, True)
|
||||
new_allowed = _next_allowable[allowed]
|
||||
control.set_sensitive(new_allowed is True)
|
||||
_change_icon(new_allowed, icon)
|
||||
if device.persister: # remember the new setting sensitivity
|
||||
device.persister.set_sensitivity(name, sensitive)
|
||||
device.persister.set_sensitivity(name, new_allowed)
|
||||
return True
|
||||
|
||||
|
||||
def _change_icon(allowed, icon):
|
||||
icon.set_from_icon_name('changes-allow' if allowed else 'changes-prevent', Gtk.IconSize.LARGE_TOOLBAR)
|
||||
icon.set_tooltip_text(_('Click to prevent changes.') if allowed else _('Click to allow changes.'))
|
||||
allowed = allowed if allowed in _allowables_icons else True
|
||||
icon.set_from_icon_name(_allowables_icons[allowed], Gtk.IconSize.LARGE_TOOLBAR)
|
||||
icon.set_tooltip_text(_allowables_tooltips[allowed])
|
||||
|
||||
|
||||
def _create_sbox(s, device):
|
||||
|
|
Loading…
Reference in New Issue