From a90daf94a63ed27d9cb398e2a917492b810bd335 Mon Sep 17 00:00:00 2001 From: Belfagor2005 <72314956+Belfagor2005@users.noreply.github.com> Date: Sun, 29 Nov 2026 10:36:10 +0000 Subject: [PATCH] Collect skin attributes read by Python widgets Add components.widgetAttributes to each catalog: the attribute names that applySkin() methods in components, addons and plugins compare with, including the dispatch style with one nested function per attribute (GraphMultiEPG). Without them a skin checker reports false warnings for attributes such as pixmaps (MultiPixmap), foregroundColors (MultiColorLabel) or EntryBackgroundColor (GraphMultiEPG). Checking the default skins of OpenPLi against the OpenPLi catalog drops from 47 warnings to 8, all of them real (zposition written in lower case). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EVc11N8zrA7gm5kdSWgpH9 --- catalogs/e2catalog.py | 71 ++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 18 deletions(-) diff --git a/catalogs/e2catalog.py b/catalogs/e2catalog.py index 3f13294..22da389 100644 --- a/catalogs/e2catalog.py +++ b/catalogs/e2catalog.py @@ -207,6 +207,55 @@ def code_expectations(roots): {k: sorted(v) for k, v in sorted(fonts.items(), key=lambda i: i[0].lower())}) +def apply_skin_attributes(func): + """Attribute names an applySkin() method compares its (attrib, value) pairs with.""" + attrs = set() + names = {"attrib"} + for loop in ast.walk(func): + if isinstance(loop, ast.For) and isinstance(loop.target, ast.Tuple) and loop.target.elts \ + and isinstance(loop.target.elts[0], ast.Name): + names.add(loop.target.elts[0].id) + for sub in ast.walk(func): + if isinstance(sub, ast.Compare) and isinstance(sub.left, ast.Name) and sub.left.id in names: + for op, comp in zip(sub.ops, sub.comparators): + if isinstance(op, ast.Eq) and isinstance(comp, ast.Constant) and isinstance(comp.value, str): + attrs.add(comp.value) + elif isinstance(op, ast.In) and isinstance(comp, (ast.Tuple, ast.List, ast.Set)): + attrs.update(e.value for e in comp.elts if isinstance(e, ast.Constant) + and isinstance(e.value, str)) + elif isinstance(sub, ast.Match) and isinstance(sub.subject, ast.Name) and sub.subject.id in names: + for case in sub.cases: + attrs |= {p.value.value for p in ast.walk(case.pattern) + if isinstance(p, ast.MatchValue) and isinstance(p.value, ast.Constant) + and isinstance(p.value.value, str)} + # Dispatch style: one nested function per attribute, def EntryBackgroundColor(value): ... + for sub in ast.walk(func): + if isinstance(sub, ast.FunctionDef) and sub is not func and len(sub.args.args) == 1 \ + and not sub.name.startswith("_"): + attrs.add(sub.name) + return {a for a in attrs if VALUE_RE.match(a)} + + +def widget_attributes(roots): + """Skin attributes read by Python widgets (applySkin in components, addons, plugins), + on top of the ones skin.py handles. Converters are skipped: they take arguments, not attributes.""" + found = set() + for root, _label in roots: + for dirpath, dirnames, filenames in os.walk(root): + dirnames[:] = [d for d in dirnames if not d.startswith(".") and d != "Converter"] + for fn in filenames: + if not fn.endswith(".py"): + continue + try: + tree = ast.parse(open(os.path.join(dirpath, fn), encoding="utf-8", errors="replace").read()) + except (SyntaxError, ValueError): + continue + for node in ast.walk(tree): + if isinstance(node, ast.FunctionDef) and node.name == "applySkin": + found |= apply_skin_attributes(node) + return sorted(found, key=str.lower) + + def renderer_info(path): """GUI widget, base class and the extra skin attributes a renderer reads in applySkin.""" info = {} @@ -223,24 +272,7 @@ def renderer_info(path): if isinstance(item, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "GUI_WIDGET" for t in item.targets): info["guiWidget"] = attr_name(item.value) if isinstance(item, ast.FunctionDef) and item.name == "applySkin": - names = {"attrib"} - for loop in ast.walk(item): - if isinstance(loop, ast.For) and isinstance(loop.target, ast.Tuple) and loop.target.elts \ - and isinstance(loop.target.elts[0], ast.Name): - names.add(loop.target.elts[0].id) - for sub in ast.walk(item): - if isinstance(sub, ast.Compare) and isinstance(sub.left, ast.Name) and sub.left.id in names: - for op, comp in zip(sub.ops, sub.comparators): - if isinstance(op, ast.Eq) and isinstance(comp, ast.Constant) and isinstance(comp.value, str): - attrs.add(comp.value) - elif isinstance(op, ast.In) and isinstance(comp, (ast.Tuple, ast.List, ast.Set)): - attrs.update(e.value for e in comp.elts if isinstance(e, ast.Constant) - and isinstance(e.value, str)) - elif isinstance(sub, ast.Match) and isinstance(sub.subject, ast.Name) and sub.subject.id in names: - for case in sub.cases: - attrs |= {p.value.value for p in ast.walk(case.pattern) - if isinstance(p, ast.MatchValue) and isinstance(p.value, ast.Constant) - and isinstance(p.value.value, str)} + attrs |= apply_skin_attributes(item) if "guiWidget" in info or attrs or "Renderer" in bases: info["class"] = cls.name info["bases"] = bases @@ -536,6 +568,7 @@ def build(root, name, plugin_dirs): s["hasDefaultSkin"] = any(n in covered for n in s["skinNames"]) colours = parse_colors(root, os.path.join(py, "skin.py"), screens, parameters) + components["widgetAttributes"] = widget_attributes(roots) return { "image": name, @@ -600,6 +633,8 @@ def to_markdown(cat): f"- Color parameters: {', '.join(cat['colors'].get('colorParameters', []))}", f"- Screens with color buttons: {cat['colors'].get('screensWithColorButtons')}, widget types: {cat['colors'].get('colorButtonWidgetTypes')}", "", + f"## Attributes read by Python widgets ({len(cat['components'].get('widgetAttributes', []))})", "", + ", ".join(f"`{a}`" for a in cat["components"].get("widgetAttributes", [])), "", "## Renderer", "", "| Renderer | GUI widget | Own attributes |", "|---|---|---|", *[f"| {k} | {v.get('guiWidget', '')} | {', '.join(v.get('skinAttributes', []))} |" for k, v in cat["components"]["renderers"].items()],