diff --git a/settings/campuses.py b/settings/campuses.py index 136bcdb..3700153 100644 --- a/settings/campuses.py +++ b/settings/campuses.py @@ -118,14 +118,18 @@ def build_view(local_cfg, page, overview_page): "options": {"stepProgression": "auto", "stepExpression": "", "rotaryActions": False, "canModifyStyleInApis": True, "notes": "STATUS tile 'campus view %d/%d' - the tapped campus's key here, view only (hold it on that campus's own deck)." % (r, c)}, "feedbacks": [], "steps": {"0": {"action_sets": {"down": [], "up": []}, "options": {"runWhileHeld": []}}}, "localVariables": []}) - make_page.place(controls, (3, 0), make_page.static_button("campus_back", "ALL\\nCAMPUSES", 0x37474F, 0xFFFFFF, overview_page, - "Tap: back to the CAMPUSES page (page %d)." % overview_page, "STATUS jump key")) + back = make_page.static_button("campus_back", "ALL\\nSITES", 0x37474F, 0xFFFFFF, overview_page, + "Tap: back to the CAMPUSES page (page %d)." % overview_page, "STATUS jump key") + for layer in back["style"]["layers"]: + if layer["type"] == "text": # which campus this page shows, then the way back + layer["text"] = make_page.prop("`${$(custom:%s)}\\nALL SITES`" % SELECT, True) + make_page.place(controls, (3, 0), back) return make_page.page_export("%d\\nCampus" % page, page, controls, local_cfg) def select_action(cid): return {"type": "action", "id": make_page.stable_id("campus_" + cid, "select"), "definitionId": "custom_variable_set_value", - "connectionId": "internal", "options": {"name": make_page.prop(SELECT), "value": make_page.prop(cid)}, "children": {}} + "connectionId": "internal", "options": {"name": make_page.prop(SELECT), "value": make_page.prop(cid.upper())}, "children": {}} def campus_key(cid, name, names, actions, note, local_cfg): @@ -325,7 +329,11 @@ class Mirror: for t in threads: t.join(2) # The CAMPUS page shows the tapped campus: its keys moved onto their cells. - pick = (self.site.comp.get_custom(SELECT) or "").strip() + pick = (self.site.comp.get_custom(SELECT) or "").strip().lower() # held as "WS": the back key shows it + if pick not in others and others: + # Nothing tapped yet (or a campus that left): show the first one rather than a purple page. + pick = sorted(others)[0] + self.site.comp.set_custom(SELECT, pick.upper()) st = self.remote.get(pick) if st and pick in self.keys and (data.get("pages") or {}).get("view"): try: diff --git a/tests/test_campus.py b/tests/test_campus.py index 37bc59c..02ec0ba 100644 --- a/tests/test_campus.py +++ b/tests/test_campus.py @@ -258,6 +258,7 @@ class TestCampusesView(unittest.TestCase): ctrls = export["page"]["controls"] self.assertEqual(export["page"]["name"], "99\\nCampus") self.assertIn("CAMPUSES", json.dumps(ctrls["3"]["0"])) # where ALARMS sits on every status page + self.assertIn("$(custom:sp_view)", json.dumps(ctrls["3"]["0"]["style"])) # it says which campus is shown cells = [ctl for row in ctrls.values() for ctl in row.values() if "campus view" in (ctl.get("options") or {}).get("notes", "")] self.assertEqual(len(cells), 28) self.assertTrue(all(c["steps"]["0"]["action_sets"] == {"down": [], "up": []} for c in cells)) # no press, no hold @@ -286,7 +287,7 @@ class TestCampusesView(unittest.TestCase): ws_key = next(k for _, _, k in keys if "'campus ws'" in k["options"]["notes"]) acts = ws_key["steps"]["0"]["action_sets"]["up"] self.assertEqual([a["definitionId"] for a in acts], ["custom_variable_set_value", "set_page"]) - self.assertEqual((acts[0]["options"]["value"]["value"], acts[1]["options"]["page"]["value"]), ("ws", 99)) + self.assertEqual((acts[0]["options"]["value"]["value"], acts[1]["options"]["page"]["value"]), ("WS", 99)) def test_a_campus_tells_the_hub_and_learns_nothing_back(self): from settings import campuses as cv