#!/usr/bin/env python3 """Make the Colour 1 and Colour 2 buttons in shows/test.qxw square. They were 90 wide and 60 high on a 96 by 66 grid. Now they are 75 square on an 81 grid, which keeps the 4 by 4 layout and makes each frame 338 wide and 338 high. The collapsed Chase runs frame, which sat just under Colour 2, moves down to stay under it, and the Pads layer frame under that moves down to clear it; the rest of the console stays where it is. python3 scripts/shows/square_colours.py It stops if the buttons are already square. QLC+ has to reopen the show to see it. """ from __future__ import annotations import re from mover_bank import ROOT SHOW = ROOT / "shows" / "test.qxw" FRAMES = ('', '') SIZE, PITCH, MARGIN = 75, 81, 10 BOTTOM = 10 # below the last row GAP = 5 COLLAPSED = 60 # room a collapsed frame takes, as the saved layout left it # Below Colour 2, top to bottom: (caption, ID) of each frame pushed down to clear the one above BELOW = (("Chase runs", 83), ("Pads layer", 129)) def main() -> None: xml = SHOW.read_text() for head in FRAMES: start = xml.index(head) end = xml.index("", start) frame = xml[start:end] spots = re.findall(r'( )', frame) if len(spots) != 16: raise SystemExit(f"{head} doesn't have its 16 buttons") if all(w == h for _, _, _, w, h in spots): raise SystemExit(f"The buttons in {head} are already square") cols = sorted({int(x) for _, x, _, _, _ in spots}) rows = sorted({int(y) for _, _, y, _, _ in spots}) for line, x, y, _, _ in spots: nx, ny = MARGIN + cols.index(int(x)) * PITCH, MARGIN + rows.index(int(y)) * PITCH frame = frame.replace(line, f' ', 1) right = MARGIN + (len(cols) - 1) * PITCH + SIZE + MARGIN bottom = MARGIN + (len(rows) - 1) * PITCH + SIZE + BOTTOM frame = re.sub(r'( ', rf'\1 Width="{right}" Height="{bottom}"/>', frame, count=1) xml = xml[:start] + frame + xml[end:] # Push the frames under Colour 2 down to clear it, each under the last. colour_2 = re.search(r'.*?', xml, re.S) top = int(colour_2.group(1)) + int(colour_2.group(2)) + GAP for caption, wid in BELOW: m = re.search(rf'(.*?)(\w+)', xml, re.S) if m is None: raise SystemExit(f"Couldn't find the {caption} frame") y = max(int(m.group(2)), top) xml = xml[:m.start(2)] + str(y) + xml[m.end(2):] top = y + (COLLAPSED if m.group(6) == "True" else int(m.group(4))) + GAP SHOW.write_text(xml) print(f"Made the colour buttons in {SHOW.relative_to(ROOT)} square") if __name__ == "__main__": main()