Add multipage frames and Playback sliders to the show builder.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Sonnet 5.5 committed 2026-10-22 11:44:19 +13:00
1 parent 82e75e69de
commit b8e6b5f24b
3 files changed
+52 -15

No files matched your search

+12 -1
View File
@@ -132,6 +132,9 @@ def show_schema() -> dict[str, Any]:
"y": {"type": "integer"},
"w": {"type": "integer"},
"h": {"type": "integer"},
"pages": {"type": "integer", "minimum": 1, "description": "Frame only. More than 1 makes it a multipage frame."},
"loop": {"type": "boolean", "description": "Frame only. Next page after the last wraps to the first."},
"page": {"type": "integer", "minimum": 0, "description": "Frame inside a multipage frame: which page it is on, from 0."},
"fg": {"$ref": "#/$defs/colour"},
"bg": {"$ref": "#/$defs/colour"},
"function": {"type": "string", "description": "Function key for a button."},
@@ -352,6 +355,7 @@ def _add_widgets(show: Show, frame: Any, widgets: list[dict[str, Any]]) -> None:
cng=str(widget.get("cng", "None")),
inverted=bool(widget.get("inverted", False)),
input=binding,
function=widget.get("function"),
**box,
)
elif kind == "button":
@@ -380,6 +384,9 @@ def _add_widgets(show: Show, frame: Any, widgets: list[dict[str, Any]]) -> None:
widget["caption"],
solo=kind == "solo" or bool(widget.get("solo", False)),
header=bool(widget.get("header", True)),
pages=int(widget.get("pages", 1)),
loop=bool(widget.get("loop", False)),
page=int(widget.get("page", 0)),
**box,
)
_add_widgets(show, child, widget.get("children") or [])
@@ -784,7 +791,11 @@ def _check_widgets(
_err(errors, f"{here}.{field}", "must be an integer")
if kind == "slider":
channels = widget.get("channels")
if not isinstance(channels, list) or not channels:
if "function" in widget:
if widget["function"] not in functions:
_err(errors, f"{here}.function", f"unknown function {widget['function']!r}")
channels = []
elif not isinstance(channels, list) or not channels:
_err(errors, f"{here}.channels", "must list [fixture, channel] pairs")
else:
for pair in channels:
+31 -5
View File
@@ -26,6 +26,7 @@ class Slider:
cng: str = "None"
inverted: bool = False
binding: MidiBinding | None = None
function_id: int | None = None # set for a Playback slider, which has no channels
type_name: str = "Slider"
def render(self, indent: str = " ") -> str:
@@ -42,13 +43,13 @@ class Slider:
f'Width="{self.w}" Height="{self.h}"/>\n'
f"{appearance(fg=self.fg, indent=inner)}\n"
f'{inner}<SliderMode ValueDisplayStyle="Exact" ClickAndGoType={attr(self.cng)} '
f'Monitor="true">Level</SliderMode>\n'
f'Monitor="true">{"Playback" if self.function_id is not None else "Level"}</SliderMode>\n'
f"{inner}<Reset/>\n"
f'{inner}<Level LowLimit="0" HighLimit="255" Value="{self.value}">\n'
f"{channels}\n"
f"{inner}</Level>\n"
f"{inner}<Playback>\n"
f"{inner} <Function>{INVALID_FUNCTION}</Function>\n"
f"{inner} <Function>{INVALID_FUNCTION if self.function_id is None else self.function_id}</Function>\n"
f"{inner}</Playback>{extra}\n"
f"{indent}</Slider>"
)
@@ -132,6 +133,9 @@ class Frame:
solo: bool = False
root: bool = False
show_header: bool = True
pages: int = 1
loop: bool = False
page: int = 0
children: list[Any] = field(default_factory=list)
id: int | None = None
type_name: str = "Frame"
@@ -155,7 +159,10 @@ class Frame:
cng: str = "None",
inverted: bool = False,
input: MidiBinding | None = None,
function: Any = None,
) -> Slider:
if isinstance(function, str):
function = self.show.functions_by_key[function].id
widget = Slider(
id=self.show.alloc_widget(),
caption=caption,
@@ -169,6 +176,7 @@ class Frame:
cng=cng,
inverted=inverted,
binding=input,
function_id=function,
)
self.children.append(widget)
return widget
@@ -251,8 +259,11 @@ class Frame:
h: int,
solo: bool = False,
header: bool = True,
pages: int = 1,
loop: bool = False,
page: int = 0,
) -> Frame:
child = Frame(self.show, caption, x, y, w, h, solo=solo, show_header=header)
child = Frame(self.show, caption, x, y, w, h, solo=solo, show_header=header, pages=pages, loop=loop, page=page)
self.children.append(child)
return child
@@ -281,9 +292,14 @@ class Frame:
if not self.solo:
flags.append(f"{inner}<ShowIntensityButton>False</ShowIntensityButton>")
flags.append(f"{inner}<Mixing>False</Mixing>")
nested = "\n".join(child.render(inner) for child in self.children)
if self.pages > 1:
flags.append(
f'{inner}<Multipage PagesNum="{self.pages}" CurrentPage="0" PagesLoop="{"True" if self.loop else "False"}"/>'
)
nested = "\n".join(_on_page(child, inner) for child in self.children)
page_attr = f' Page="{self.page}"' if self.page else ""
parts = [
f"{indent}<{tag} Caption={attr(self.caption)} ID=\"{self.id}\">",
f"{indent}<{tag} Caption={attr(self.caption)} ID=\"{self.id}\"{page_attr}>",
appearance(indent=inner),
f'{inner}<WindowState Visible="True" X="{self.x}" Y="{self.y}" Width="{self.w}" Height="{self.h}"/>',
*flags,
@@ -294,6 +310,16 @@ class Frame:
return "\n".join(parts)
def _on_page(child: Any, indent: str) -> str:
"""Render a child, tagging its opening element with the frame page it is on."""
text = child.render(indent)
page = getattr(child, "page", 0)
if not page or isinstance(child, Frame):
return text
head, sep, rest = text.partition(">")
return f'{head} Page="{page}"{sep}{rest}'
def _input_xml(binding: MidiBinding | None, indent: str) -> str:
if binding is None:
return ""