"""Small XML helpers shared by the workspace writer.""" from __future__ import annotations from xml.sax.saxutils import escape, quoteattr def attr(value: object) -> str: return quoteattr(str(value)) def text(value: object) -> str: return escape(str(value)) def qlc_color(r: int, g: int, b: int) -> str: """QLC+ widget colour as a decimal ARGB word.""" return str((0xFF << 24) | ((int(r) & 255) << 16) | ((int(g) & 255) << 8) | (int(b) & 255)) def colour(value: object, default: str = "Default") -> str: if value is None: return default if isinstance(value, str): return value if isinstance(value, int) and not isinstance(value, bool): return str(value) if isinstance(value, (list, tuple)) and len(value) == 3: return qlc_color(int(value[0]), int(value[1]), int(value[2])) raise TypeError(f"colour must be 'Default', an ARGB decimal, or [r, g, b], not {value!r}") def appearance( fg: object = "Default", bg: object = "Default", frame: str = "Sunken", indent: str = " ", ) -> str: inner = indent + " " return ( f"{indent}\n" f"{inner}{text(frame)}\n" f"{inner}{text(colour(fg))}\n" f"{inner}{text(colour(bg))}\n" f"{inner}None\n" f"{inner}Default\n" f"{indent}" )