diff --git a/README.md b/README.md index 757604d..bb91855 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,10 @@ Row 0 holds the group buttons. Each one shows the first problem in its group, pl ## Page keys on every page -The **page number key** on every page follows the ALL button. It's green when everything is fine, flashes red when something is wrong, and turns purple if the watchdog stops. UP and DOWN stay normal. Which keys follow ALL is `"nav_keys"` in `config.json` (`["pagenum"]`; add `"pageup"` / `"pagedown"` to colour those too). The coloured key is Companion's own key converted to a regular button (`nav_templates.json`), so a press works exactly as before. +The **page number key** on every page follows the ALL button. It's green when everything is fine, flashes red when something is wrong, and turns purple if the watchdog stops. UP and DOWN stay normal. Which keys follow ALL is `"nav_keys"` in `config.json` (`["pagenum"]`; add `"pageup"` / `"pagedown"` to colour those too). The coloured key is Companion's own key converted to a regular button (`nav_templates.json`). + +- **Tap the page number:** go to the start page (page 1), as before. It now acts when you let go, not when you press. +- **Hold the page number for 1 second:** jump to the status page (page 19). The hold time is `"nav_hold_ms"` in `config.json`. - `python3 nav_keys.py` applies them to every page. Run it again after adding pages. - `python3 nav_keys.py --revert` puts Companion's built-in nav keys back. diff --git a/config.json b/config.json index bdd5a8e..98fbddd 100644 --- a/config.json +++ b/config.json @@ -3,6 +3,7 @@ "page": 19, "page_name": "19\\nStatus", "nav_keys": ["pagenum"], + "nav_hold_ms": 1000, "variables": { "state": "sp_state", "heartbeat": "sp_hb", "command": "sp_cmd" }, "service_windows": [ diff --git a/make_page.py b/make_page.py index b458607..afb1a3b 100644 --- a/make_page.py +++ b/make_page.py @@ -136,8 +136,13 @@ NAV_LOCATIONS = {"pageup": ("0", "0"), "pagenum": ("1", "0"), "pagedown": ("2", NAV_MARKER = "STATUS nav key" -def nav_key(kind, names): - """Companion's own UP / page number / DOWN key, coloured like the ALL button.""" +def nav_key(kind, names, status_page=None, hold_ms=1000): + """Companion's own UP / page number / DOWN key, coloured like the ALL button. + + For the page number key, status_page adds: tap = Companion's usual "go to the + start page" (moved to release, so a hold does not flash through it first), + hold for hold_ms = go to the status page. + """ templates = json.load(open(os.path.join(HERE, "nav_templates.json"))) key = json.loads(json.dumps(templates[kind])) stale = "$(internal:time_unix) - $(custom:%s) > %d" % (names["heartbeat"], STALE_SECONDS) @@ -155,6 +160,14 @@ def nav_key(kind, names): layer["borderColor"] = prop(fg, True) paint(layer.get("children", [])) paint(key["style"]["layers"]) + if kind == "pagenum" and status_page: + step = key["steps"]["0"] + tap = step["action_sets"]["down"] + hold = [{"type": "action", "id": stable_id("nav", "hold"), "definitionId": "set_page", + "connectionId": "internal", + "options": {"surfaceId": prop("self"), "page": prop(status_page)}, "children": {}}] + step["action_sets"] = {"down": [], "up": tap, str(hold_ms): hold} + step["options"]["runWhileHeld"] = [hold_ms] key["options"]["notes"] = ("%s (%s): colour follows the ALL button on the status page. " "Undo on every page with: python3 nav_keys.py --revert" % (NAV_MARKER, kind)) return key @@ -164,7 +177,8 @@ def build(cfg): controls = {} coloured = cfg.get("nav_keys", list(NAV_LOCATIONS)) # which nav keys follow the ALL button for kind, (r, c) in NAV_LOCATIONS.items(): - controls.setdefault(r, {})[c] = nav_key(kind, cfg["variables"]) if kind in coloured else {"type": kind} + controls.setdefault(r, {})[c] = (nav_key(kind, cfg["variables"], cfg["page"], cfg.get("nav_hold_ms", 1000)) + if kind in coloured else {"type": kind}) for tile in cfg["tiles"]: if "pos" not in tile: continue diff --git a/status-page.companionconfig b/status-page.companionconfig index 09bc048..fd30f6d 100644 Binary files a/status-page.companionconfig and b/status-page.companionconfig differ diff --git a/tests/test_status_panel.py b/tests/test_status_panel.py index 62c7952..0aecce4 100644 --- a/tests/test_status_panel.py +++ b/tests/test_status_panel.py @@ -561,7 +561,12 @@ class TestPage(unittest.TestCase): key = self.controls[r]["0"] self.assertEqual(key["type"], "button-layered") self.assertTrue(key["options"]["notes"].startswith("STATUS nav key (%s)" % kind)) - self.assertEqual(key["steps"]["0"]["action_sets"]["down"][0]["definitionId"], action) + step = key["steps"]["0"] + self.assertEqual(step["action_sets"]["down"], []) + tap, hold = step["action_sets"]["up"][0], step["action_sets"]["1000"][0] + self.assertEqual((tap["definitionId"], tap["options"]["page"]["value"]), (action, "startup")) + self.assertEqual((hold["definitionId"], hold["options"]["page"]["value"]), ("set_page", 19)) + self.assertEqual(step["options"]["runWhileHeld"], [1000]) box = [l for l in key["style"]["layers"] if l["type"] == "box"][0] self.assertTrue(box["color"]["isExpression"]) self.assertIn("'$.all.b'", box["color"]["value"]) # follows the ALL button