Only the page number key follows the ALL button; UP and DOWN are normal again.
New config setting nav_keys (now ["pagenum"]) picks which nav keys are coloured; nav_keys.py restores the built-in key for any kind not listed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+24
-14
@@ -1,10 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Make the UP / page number / DOWN keys on every page follow the status page's ALL button.
|
||||
"""Make the page nav keys on every page follow the status page's ALL button.
|
||||
|
||||
Which keys follow it is "nav_keys" in config.json (now just the page number).
|
||||
The status page (page 19) carries coloured copies of Companion's own nav keys
|
||||
(see make_page.py and nav_templates.json). This copies them over the built-in
|
||||
nav keys on every other page, wherever those sit, using the same "copy button"
|
||||
call as the Companion UI. Each key keeps its normal press action.
|
||||
(see make_page.py and nav_templates.json). This copies those over the built-in
|
||||
keys on every other page, using the same "copy button" call as the Companion UI,
|
||||
and puts back the built-in key for any kind no longer listed. Each key keeps
|
||||
its normal press action.
|
||||
|
||||
python3 nav_keys.py --dry-run list what would change
|
||||
python3 nav_keys.py apply (also refreshes keys already converted)
|
||||
@@ -52,8 +54,12 @@ def nav_kind(control):
|
||||
return None
|
||||
|
||||
|
||||
def is_ours(control):
|
||||
return (control.get("options", {}).get("notes", "") or "").startswith(NAV_MARKER)
|
||||
|
||||
|
||||
def find_nav_keys(host, port, status_page):
|
||||
"""[(page, row, column, kind)] for every nav key outside the status page."""
|
||||
"""[(page, row, column, kind, ours)] for every nav key outside the status page."""
|
||||
found, page = [], 1
|
||||
while True:
|
||||
export = page_export(host, port, page)
|
||||
@@ -64,7 +70,7 @@ def find_nav_keys(host, port, status_page):
|
||||
for c, control in cols.items():
|
||||
kind = nav_kind(control or {})
|
||||
if kind:
|
||||
found.append((page, int(r), int(c), kind))
|
||||
found.append((page, int(r), int(c), kind, is_ours(control)))
|
||||
page += 1
|
||||
return found
|
||||
|
||||
@@ -79,24 +85,28 @@ def main():
|
||||
args = ap.parse_args()
|
||||
status_page = cfg["page"]
|
||||
|
||||
coloured = cfg.get("nav_keys", list(NAV_LOCATIONS))
|
||||
record = json.load(open(RECORD)) if os.path.exists(RECORD) else {}
|
||||
found = find_nav_keys(args.host, args.port, status_page)
|
||||
if args.revert:
|
||||
targets = [(int(k.split("/")[0]), int(k.split("/")[1]), int(k.split("/")[2]), v) for k, v in record.items()]
|
||||
work = [(p, r, c, k, "restore") for p, r, c, k, ours in found if ours]
|
||||
else:
|
||||
targets = find_nav_keys(args.host, args.port, status_page)
|
||||
print("%d nav keys on %d pages" % (len(targets), len({t[0] for t in targets})))
|
||||
work = [(p, r, c, k, "colour") for p, r, c, k, ours in found if k in coloured]
|
||||
work += [(p, r, c, k, "restore") for p, r, c, k, ours in found if ours and k not in coloured]
|
||||
print("%d nav keys to colour, %d to restore, on %d pages" % (
|
||||
sum(1 for w in work if w[4] == "colour"), sum(1 for w in work if w[4] == "restore"), len({w[0] for w in work})))
|
||||
if args.dry_run:
|
||||
for t in targets:
|
||||
print(" page %d row %d col %d: %s" % t)
|
||||
for w in work:
|
||||
print(" page %d row %d col %d: %s -> %s" % w)
|
||||
return
|
||||
|
||||
ws = WebSocket(args.host, args.port, "/trpc")
|
||||
done = 0
|
||||
try:
|
||||
api = Trpc(ws)
|
||||
for page, row, col, kind in targets:
|
||||
for page, row, col, kind, what in work:
|
||||
location = {"pageNumber": page, "row": row, "column": col}
|
||||
if args.revert:
|
||||
if what == "restore":
|
||||
api.mutation("controls.resetControl", {"location": location, "newType": kind})
|
||||
record.pop("%d/%d/%d" % (page, row, col), None)
|
||||
else:
|
||||
@@ -109,7 +119,7 @@ def main():
|
||||
finally:
|
||||
ws.close()
|
||||
json.dump(record, open(RECORD, "w"), indent=1, sort_keys=True)
|
||||
print("%s %d nav keys" % ("restored" if args.revert else "coloured", done))
|
||||
print("done: %d nav keys changed" % done)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user