diff --git a/lib/logitech_receiver/settings.py b/lib/logitech_receiver/settings.py index f0f5442b..25257910 100644 --- a/lib/logitech_receiver/settings.py +++ b/lib/logitech_receiver/settings.py @@ -45,6 +45,7 @@ class Kind(IntEnum): MULTIPLE_RANGE = 0x40 HETERO = 0x80 MAP_RANGE = 0x102 + COLOR = 0x200 class Setting: diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py index 44ad57a4..e9d26955 100644 --- a/lib/logitech_receiver/settings_templates.py +++ b/lib/logitech_receiver/settings_templates.py @@ -1644,7 +1644,7 @@ class LEDZoneSetting(settings.Setting): label = _("LED Zone Effects") description = _("Set effect for LED Zone") + "\n" + _("LED Control needs to be set to Solaar to be effective.") feature = _F.COLOR_LED_EFFECTS - color_field = {"name": _LEDP.color, "kind": settings.Kind.CHOICE, "label": None, "choices": colors} + color_field = {"name": _LEDP.color, "kind": settings.Kind.COLOR, "label": _("Color")} speed_field = {"name": _LEDP.speed, "kind": settings.Kind.RANGE, "label": _("Speed"), "min": 0, "max": 255} period_field = {"name": _LEDP.period, "kind": settings.Kind.RANGE, "label": _("Period"), "min": 100, "max": 5000} intensity_field = {"name": _LEDP.intensity, "kind": settings.Kind.RANGE, "label": _("Intensity"), "min": 0, "max": 100} diff --git a/lib/solaar/ui/config_panel.py b/lib/solaar/ui/config_panel.py index bdc5946b..4c6e1a51 100644 --- a/lib/solaar/ui/config_panel.py +++ b/lib/solaar/ui/config_panel.py @@ -46,6 +46,7 @@ class GtkSignal(Enum): NOTIFY_ACTIVE = "notify::active" TOGGLED = "toggled" VALUE_CHANGED = "value-changed" + COLOR_SET = "color-set" def _read_async(setting, force_read, sbox, device_is_online, sensitive): @@ -565,6 +566,10 @@ class HeteroKeyControl(Gtk.HBox, Control): item_box.set_active(0) item_box.connect(GtkSignal.CHANGED.value, self.changed) self.pack_start(item_box, False, False, 0) + elif item["kind"] == settings.Kind.COLOR: + item_box = Gtk.ColorButton() + item_box.connect(GtkSignal.COLOR_SET.value, self.changed) + self.pack_start(item_box, False, False, 0) elif item["kind"] == settings.Kind.RANGE: item_box = Scale() item_box.set_range(item["min"], item["max"]) @@ -579,7 +584,14 @@ class HeteroKeyControl(Gtk.HBox, Control): def get_value(self): result = {} for k, (_lblbox, box) in self._items.items(): - result[str(k)] = box.get_value() + if isinstance(box, Gtk.ColorButton): + rgba = box.get_rgba() + r = int(rgba.red * 255) + g = int(rgba.green * 255) + b = int(rgba.blue * 255) + result[str(k)] = (r << 16) | (g << 8) | b + else: + result[str(k)] = box.get_value() result = hidpp20.LEDEffectSetting(**result) return result @@ -589,7 +601,13 @@ class HeteroKeyControl(Gtk.HBox, Control): for k, v in value.__dict__.items(): if k in self._items: (lblbox, box) = self._items[k] - box.set_value(v) + if isinstance(box, Gtk.ColorButton): + rgba = Gdk.RGBA() + color_string = f"#{v:06X}" # e.g. "#FF0000" + rgba.parse(color_string) + box.set_rgba(rgba) + else: + box.set_value(v) else: self.sbox._failed.set_visible(True) self.setup_visibles(value.ID if value is not None else 0)