Lighting as a macropad subcommand; knobless pads start in the flat view
Running the backend module directly made runpy warn, since the package had already imported it. The lighting commands now sit with doctor, state and write. A pad without knobs lies flat on the desk, so it is drawn flat unless an orientation has been chosen. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,9 @@ The rest are for poking at the core from a terminal:
|
||||
python3 -m macropad_gui state
|
||||
python3 -m macropad_gui write key1 "ctrl+c"
|
||||
python3 -m macropad_gui write dial1-right --media volumeup
|
||||
python3 -m macropad_gui lighting show ITPROTECH pads only
|
||||
python3 -m macropad_gui lighting rgb "press: blue"
|
||||
python3 -m macropad_gui lighting colour ff8800
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -100,6 +103,46 @@ def cmd_write(a):
|
||||
return 0
|
||||
|
||||
|
||||
def cmd_lighting(a):
|
||||
"""Lighting mode and custom colour on pads whose backend has them."""
|
||||
d = core.diagnose(keyd=False)
|
||||
backend = core.backend_for(d.device) if d.device else None
|
||||
if not d.device or not hasattr(backend, "set_lighting"):
|
||||
print(f"{R}No pad with lighting control found.{O} "
|
||||
+ (d.headline if not d.device else f"{backend.name} has no lighting here."))
|
||||
return 1
|
||||
from .backends import itprotech_proto as wire
|
||||
modes = ", ".join(f"{i} {m}" for i, m in enumerate(wire.RGB_MODES))
|
||||
if a.what == "show":
|
||||
mode, colour = backend.lighting(d.device)
|
||||
name = wire.RGB_MODES[mode] if mode is not None and mode < len(wire.RGB_MODES) else "?"
|
||||
hexcol = "#%02x%02x%02x" % colour if colour else "?"
|
||||
print(f"lighting {mode} ({name}), custom colour {hexcol}")
|
||||
return 0
|
||||
if not d.ready:
|
||||
return cmd_doctor(None)
|
||||
if a.what == "rgb":
|
||||
want = (a.value or "").lower()
|
||||
if want.isdigit() and int(want) < len(wire.RGB_MODES):
|
||||
mode = int(want)
|
||||
elif want in wire.RGB_MODES:
|
||||
mode = wire.RGB_MODES.index(want)
|
||||
else:
|
||||
print(f"Pick a mode: {modes}")
|
||||
return 1
|
||||
backend.set_lighting(d.device, mode)
|
||||
print(f"{G}Lighting set to {mode} ({wire.RGB_MODES[mode]}).{O}")
|
||||
return 0
|
||||
hexcol = (a.value or "").lstrip("#")
|
||||
if len(hexcol) != 6 or any(c not in "0123456789abcdefABCDEF" for c in hexcol):
|
||||
print("Give the colour as RRGGBB, e.g. ff8800")
|
||||
return 1
|
||||
rgb = tuple(int(hexcol[i:i + 2], 16) for i in (0, 2, 4))
|
||||
backend.set_lighting(d.device, wire.RGB_CUSTOM, rgb)
|
||||
print(f"{G}Custom colour #{hexcol.lower()} set (mode {wire.RGB_CUSTOM}).{O}")
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(prog="python3 -m macropad_gui")
|
||||
sub = ap.add_subparsers(dest="cmd")
|
||||
@@ -114,6 +157,9 @@ def main():
|
||||
w.add_argument("keys", nargs="?", help="e.g. 'ctrl+c' or 'a,b,c'")
|
||||
w.add_argument("--media", help="e.g. volumeup")
|
||||
w.add_argument("--delay", type=int, default=0)
|
||||
li = sub.add_parser("lighting", help="lighting mode and colour (ITPROTECH pads)")
|
||||
li.add_argument("what", choices=("show", "rgb", "colour", "color"))
|
||||
li.add_argument("value", nargs="?", help="a mode number or name, or RRGGBB")
|
||||
a = ap.parse_args()
|
||||
if a.cmd is None:
|
||||
try:
|
||||
@@ -124,7 +170,8 @@ def main():
|
||||
return 1
|
||||
return run()
|
||||
return {"doctor": cmd_doctor, "state": cmd_state, "write": cmd_write,
|
||||
"detect": cmd_detect, "actions": cmd_actions}[a.cmd](a)
|
||||
"detect": cmd_detect, "actions": cmd_actions,
|
||||
"lighting": cmd_lighting}[a.cmd](a)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user