#!/usr/bin/env python3
"""Merge Patterns + Movers into one SoloFrame and one Speed dial in xchc.qxw."""
from __future__ import annotations
import re
from pathlib import Path
def btn(
widget_id: int,
caption: str,
func_id: int,
x: int,
y: int,
w: int,
h: int,
bg: str,
fg: str = "4294967295",
) -> str:
return f""" """
ROOT = Path(__file__).resolve().parents[1]
def main():
path = ROOT / "shows" / "xchc.qxw"
text = path.read_text()
# Combined looks: can colour chase + figure-of-8 movement
combos = [
(101, "Colour + F8", 9, 77),
(102, "Rainbow + F8", 18, 77),
(103, "OddEven + F8", 22, 77),
(104, "Center + F8", 55, 77),
(105, "Theater + F8", 67, 77),
]
combo_xml = []
for fid, name, a, b in combos:
block = f"""
{a}
{b}
"""
if f'Function ID="{fid}"' in text:
text = re.sub(
rf' \n',
block,
text,
count=1,
)
else:
combo_xml.append(block.rstrip())
if combo_xml:
text = text.replace(
'
Sunken
Default
Default
None
Default
True
True
True
False
{chr(10).join(buttons)}
"""
# Replace Patterns SoloFrame
text = re.sub(
r' [\s\S]*?',
show_frame,
text,
count=1,
)
# Remove Movers SoloFrame (buttons now in Show)
text = re.sub(
r' [\s\S]*?\n',
"",
text,
count=1,
)
# Merge mover speed targets into main Speed dial; drop Mover Speed dial
text = re.sub(
r' [\s\S]*?\n',
"",
text,
count=1,
)
speed_extra = """ 74
76
101
102
103
104
105
"""
if 'Function FadeIn="6" FadeOut="0" Duration="6">74' not in text:
text = text.replace(
' 69\n ',
' 69\n'
+ speed_extra
+ " ",
1,
)
# Make Speed dial visible next to Show
text = text.replace(
'\n ',
f'\n ',
1,
)
# All Dim also drives mover dimmers
if "8" not in text.split('Caption="All Dim"', 1)[1][:800]:
text = text.replace(
"""
0
0
0
0
0
0
0
0
4294967295
0
0
0
0
0
0
0
0
8
8
4294967295
\n ',
f'\n ',
1,
)
# Shift mover sliders under Show, right of XY pad
slider_y = frame_h + 20
old_xs = [1050 + i * 46 for i in range(10)]
new_xs = [340 + i * 46 for i in range(10)]
for ox, nx in zip(old_xs, new_xs):
text = text.replace(
f'Visible="True" X="{ox}" Y="180" Width="44" Height="320"',
f'Visible="True" X="{nx}" Y="{slider_y}" Width="44" Height="300"',
1,
)
path.write_text(text)
print(f"Unified Show controls in {path}")
print(f" SoloFrame {frame_w}x{frame_h} with pattern + F8 combos + exits")
print(" One Speed dial; Position pad + mover sliders below")
if __name__ == "__main__":
main()