#!/usr/bin/env python3 """Badged tray icons: every base state with a failed, busy or unknown badge in its bottom-right corner. python3 badges.py proxy-suite-[-symbolic].svg -> proxy-suite--[-symbolic].svg, next to copies of the bases. The shield is cut away around the badge, so it reads on any panel color. """ import os import re import shutil import sys STATES = ("disabled", "zapret", "proxy", "active", "tunnel") CX, CY = 18.5, 18.5 CUT, DOT = 5.8, 4.8 # radius of the gap in the shield, and of the badge inside it # badge -> (fill, stroke, glyph drawn in the glyph color) GLYPHS = { "failed": ( "#D32F2F", "#7F0000", f'' f'', ), "busy": ( "#FFA000", "#8D5A00", "".join(f'' for dx in (-2.2, 0, 2.2)), ), "unknown": ( "#757575", "#424242", f'' f'', ), } def inner(svg): return re.search(r"]*>(.*)", svg, re.S).group(1) def badged(svg, badge, symbolic): fill, stroke, glyph = GLYPHS[badge] mask = ( f'' f'' ) if symbolic: # One color: the badge is a disc with its glyph knocked out. mask += ( f'' f'{glyph}' ) badge_svg = f'' else: badge_svg = ( f'' f'{glyph}' ) return ( '\n' f" {mask}\n" f' {inner(svg)}\n' f" {badge_svg}\n" "\n" ) def main(src, out): os.makedirs(out, exist_ok=True) for state in STATES: for suffix in ("", "-symbolic"): base = os.path.join(src, f"proxy-suite-{state}{suffix}.svg") shutil.copyfile(base, os.path.join(out, os.path.basename(base))) with open(base) as f: svg = f.read() for badge in GLYPHS: with open(os.path.join(out, f"proxy-suite-{state}-{badge}{suffix}.svg"), "w") as f: f.write(badged(svg, badge, bool(suffix))) if __name__ == "__main__": main(*sys.argv[1:3])