diff options
Diffstat (limited to 'scripts/theme-studio')
| -rw-r--r-- | scripts/theme-studio/default_faces.py | 32 | ||||
| -rw-r--r-- | scripts/theme-studio/generate.py | 22 |
2 files changed, 25 insertions, 29 deletions
diff --git a/scripts/theme-studio/default_faces.py b/scripts/theme-studio/default_faces.py index 70ceb39e6..b9633cfa7 100644 --- a/scripts/theme-studio/default_faces.py +++ b/scripts/theme-studio/default_faces.py @@ -141,32 +141,30 @@ class DefaultFaces: "packageInherits": package_inherits, } - def _build_color_hex(self) -> dict[str, str]: - out: dict[str, str] = {} + def _iter_color_pairs(self): + """Yield (name, hexValue) over every face's chosen/effective color attrs. + Both color maps walk this same nested structure; they differ only in which + of the pair is the key and how each filters.""" if not self.data: - return out + return for data in self.data.get("faces", {}).values(): for block in ("chosenGuiLight", "effectiveGuiLight"): face_data = data.get(block, {}) or {} for attr in ("foreground", "background", "distantForeground"): - name = face_data.get(attr) - hex_value = face_data.get(attr + "Hex") - if name and hex_value: - out[str(name).lower().replace(" ", "")] = hex_value + yield face_data.get(attr), face_data.get(attr + "Hex") + + def _build_color_hex(self) -> dict[str, str]: + out: dict[str, str] = {} + for name, hex_value in self._iter_color_pairs(): + if name and hex_value: + out[str(name).lower().replace(" ", "")] = hex_value return out def _build_color_names(self) -> dict[str, str]: out: dict[str, str] = {} - if not self.data: - return out - for data in self.data.get("faces", {}).values(): - for block in ("chosenGuiLight", "effectiveGuiLight"): - face_data = data.get(block, {}) or {} - for attr in ("foreground", "background", "distantForeground"): - hex_value = face_data.get(attr + "Hex") - name = face_data.get(attr) - if hex_value and name and not str(name).startswith("#"): - out.setdefault(hex_value.lower(), str(name).lower().replace(" ", "-")) + for name, hex_value in self._iter_color_pairs(): + if hex_value and name and not str(name).startswith("#"): + out.setdefault(hex_value.lower(), str(name).lower().replace(" ", "-")) return out diff --git a/scripts/theme-studio/generate.py b/scripts/theme-studio/generate.py index d774a6061..43ebf02c6 100644 --- a/scripts/theme-studio/generate.py +++ b/scripts/theme-studio/generate.py @@ -177,25 +177,23 @@ def add_palette_color(palette,defaults,value,label=None): name=base+'-'+str(n); n+=1 palette.append([value,name,column_id(name)]) +def _harvest_spec_colors(palette,defaults,spec): + """Add a face spec's fg, bg, and box color (if any) to the palette, in order.""" + add_palette_color(palette,defaults,spec.get('fg')) + add_palette_color(palette,defaults,spec.get('bg')) + if spec.get('box'): + add_palette_color(palette,defaults,spec['box'].get('color')) + def add_default_palette_colors(palette,map_,syntax,uimap,apps,defaults): for key,value in map_.items(): add_palette_color(palette,defaults,value,'bg' if key=='bg' else 'fg' if key=='p' else None) for spec in syntax.values(): - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) for _face,spec in uimap.items(): - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) for app in apps.values(): for _face,_label,spec in app['faces']: - add_palette_color(palette,defaults,spec.get('fg')) - add_palette_color(palette,defaults,spec.get('bg')) - if spec.get('box'): - add_palette_color(palette,defaults,spec['box'].get('color')) + _harvest_spec_colors(palette,defaults,spec) def apply_seed_packages(apps,data,seed): if seed: |
