Files
Ken Sanislo d8422d78d1 Add per-key RGB color painter and replace MAP_CHOICE color validator
Replace the per-key dropdown UI (MapChoiceControl) with a Cairo-rendered
keyboard canvas where users can paint colors directly onto keys.

Editor (lib/solaar/ui/perkey/):
  - Cairo DrawingArea renders cells from a Layout dataclass; bound cells
    take their painted color, unset cells show a diagonal hash whose base
    color matches the device's rgb_zone_* setting.
  - Tools: brush, drag-rectangle, flood-fill (4-adjacent, Paint-style),
    and a directional gradient (line A->B projected across the matrix
    with cells past the endpoints clamped to the endpoint colors).
  - GradientSwatch is the single source of truth for the gradient's two
    colors; the canvas reads from it on each gradient stroke.
  - Palette: GTK ColorButton plus an unset toggle that paints the
    "no change" sentinel (-1).
  - PerKeyEditorDialog auto-sizes from the canvas's size_request, so a
    104-key keyboard opens wide and a 8-LED mouse opens compact.
  - Editor consumes only a narrow PerKeyColorSink protocol; never imports
    from lib/logitech_receiver, preserving the FE/BE seam.
  - Per-device palette state (active + previous color) persists via the
    existing persister under a _palette: prefixed key.

Layouts:
  - ANSI 104-key full-size and TKL keyboard layouts.
  - G502 X family mouse layout (zones 1-8 -> labels A-H).
  - Generic registry: register_layout(feature, matcher, layout). A
    _name_contains() helper builds case-insensitive substring matchers
    against device codename / name. Unknown devices fall back to a flat
    strip of all reported zones.

Validator (open value space):
  - New Range dataclass and MapRangeValidator extending Validator
    directly (kind=MAP_CHOICE for dispatch compatibility). Replaces the
    ChoicesMapValidator on PerKeyLighting -- the named-color universe
    (COLORSPLUS) was rejecting any picker color outside its ~20 entries.
    Other MAP_CHOICE settings are untouched.

Integration:
  - Setting base gains an editor_class string attribute. config_panel's
    _create_sbox resolves it via importlib before the kind dispatch, so
    PerKeyLighting routes to the new editor without a new Kind value.
  - CLI gains a hex/dec parser for open-value MAP_CHOICE settings:
      solaar config <dev> per-key-lighting A 0xFF00FF
  - Diversion rule editor skips Range-valued MAP_CHOICE settings'
    value-selector instead of crashing on the open value space.
  - pycairo declared in install_requires; transitively present on most
    systems but now explicit for pip-from-source installs.

Tests in test_setting_templates.py updated for the new validator.
2026-05-10 17:52:55 -04:00

99 lines
3.4 KiB
Python
Executable File

import subprocess
import textwrap
from glob import glob
from os.path import dirname
from pathlib import Path
from setuptools import find_packages
from setuptools import setup
NAME = "Solaar"
version = Path("lib/solaar/version").read_text().strip()
try: # get commit from git describe
commit = subprocess.check_output(["git", "describe", "--always"], stderr=subprocess.DEVNULL).strip().decode()
Path("lib/solaar/commit").write_text(f"{commit}\n")
except Exception: # get commit from Ubuntu dpkg-parsechangelog
try:
commit = (
subprocess.check_output(["dpkg-parsechangelog", "--show-field", "Version"], stderr=subprocess.DEVNULL)
.strip()
.decode()
)
commit = commit.split("~")
Path("lib/solaar/commit").write_text(f"{commit[0]}\n")
except Exception as e:
print("Exception using dpkg-parsechangelog", e)
def _data_files():
yield "share/icons/hicolor/scalable/apps", glob("share/solaar/icons/solaar*.svg")
yield "share/icons/hicolor/32x32/apps", glob("share/solaar/icons/solaar-light_*.png")
for mo in glob("share/locale/*/LC_MESSAGES/solaar.mo"):
yield dirname(mo), [mo]
yield "share/applications", ["share/applications/solaar.desktop"]
yield "lib/udev/rules.d", ["rules.d/42-logitech-unify-permissions.rules"]
yield "share/metainfo", ["share/solaar/io.github.pwr_solaar.solaar.metainfo.xml"]
setup(
name=NAME.lower(),
version=version,
description="Linux device manager for Logitech receivers, keyboards, mice, and tablets.",
long_description=textwrap.dedent(
"""
Solaar is a Linux device manager for many Logitech peripherals that connect through
Unifying and other receivers or via USB or Bluetooth.
Solaar is able to pair/unpair devices with receivers and show and modify some of the
modifiable features of devices.
For instructions on installing Solaar see https://pwr-solaar.github.io/Solaar/installation"""
),
author="Daniel Pavel",
license="GPLv2",
url="http://pwr-solaar.github.io/Solaar/",
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: X11 Applications :: GTK",
"Environment :: Console",
"Intended Audience :: End Users/Desktop",
"License :: DFSG approved",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Natural Language :: English",
"Programming Language :: Python :: 3 :: Only",
"Operating System :: POSIX :: Linux",
"Topic :: Utilities",
],
platforms=["linux"],
python_requires=">=3.8",
install_requires=[
'evdev (>= 1.1.2) ; platform_system=="Linux"',
"pyudev (>= 0.13)",
"PyYAML (>= 3.12)",
"python-xlib (>= 0.27)",
"psutil (>= 5.4.3)",
'dbus-python ; platform_system=="Linux"',
"PyGObject",
"pycairo",
"typing_extensions",
],
extras_require={
"report-descriptor": ["hid-parser"],
"desktop-notifications": ["Notify (>= 0.7)"],
"git-commit": ["python-git-info"],
"test": ["pytest", "pytest-mock", "pytest-cov"],
"dev": ["ruff"],
},
package_dir={"": "lib"},
packages=find_packages(where="lib"),
data_files=list(_data_files()),
include_package_data=True,
entry_points={
"console_scripts": [
"solaar = solaar.gtk:main",
],
},
)