import re from pathlib import Path # Mapping regex -> replacement # Note: we use theme.get_color("semantic", alpha=...) REPLACEMENTS = [ # status_error (r'imgui\.ImVec4\(1\.0, 0\.0, 0\.0, 0\.2\)', 'theme.get_color("status_error", alpha=0.2)'), (r'imgui\.ImVec4\(1, 0, 0, 1\)', 'theme.get_color("status_error")'), (r'imgui\.ImVec4\(1, 0\.3, 0\.3, ([\d\.]+)\)', r'theme.get_color("status_error", alpha=\1)'), (r'imgui\.ImVec4\(1, 0\.3, 0\.3, 1\)', 'theme.get_color("status_error")'), (r'imgui\.ImVec4\(1, 0\.4, 0\.4, 1\)', 'theme.get_color("status_error")'), (r'vec4\(255, 100, 100\)', 'theme.get_color("status_error")'), (r'vec4\(255, 72, 64, ([\d\.]+)\)', r'theme.get_color("status_error", alpha=\1)'), (r'vec4\(255, 72, 64\)', 'theme.get_color("status_error")'), (r'vec4\(255, 77, 77\)', 'theme.get_color("status_error")'), (r'vec4\(230, 51, 51\)', 'theme.get_color("status_error")'), (r'vec4\(240, 80, 80\)', 'theme.get_color("status_error")'), (r'vec4\(255, 120, 120\)', 'theme.get_color("status_error")'), (r'vec4\(255, 50, 50, ([\d\.]+)\)', r'theme.get_color("status_error", alpha=\1)'), (r'vec4\(255, 100, 100, ([\d\.]+)\)', r'theme.get_color("status_error", alpha=\1)'), # status_warning (r'imgui\.ImVec4\(1\.0, 0\.85, 0\.2, 0\.15\)', 'theme.get_color("status_warning", alpha=0.15)'), (r'imgui\.ImVec4\(1\.0, 0\.85, 0\.2, 1\.0\)', 'theme.get_color("status_warning")'), (r'imgui\.ImVec4\(1, 0\.5, 0, 1\)', 'theme.get_color("status_warning")'), (r'imgui\.ImVec4\(1, 1, 0, 1\)', 'theme.get_color("status_warning")'), (r'imgui\.ImVec4\(1\.0, 1\.0, 0\.0, 1\.0\)', 'theme.get_color("status_warning")'), (r'imgui\.ImVec4\(1\.0, 0\.5, 0\.0, 1\.0\)', 'theme.get_color("status_warning")'), (r'imgui\.ImVec4\(1\.0, 0\.3, 0\.0, 1\.0\)', 'theme.get_color("status_warning")'), (r'vec4\(255, 152, 48\)', 'theme.get_color("status_warning")'), (r'vec4\(255, 200, 100\)', 'theme.get_color("status_warning")'), (r'vec4\(200, 200, 100\)', 'theme.get_color("status_warning")'), (r'vec4\(255, 230, 77\)', 'theme.get_color("status_warning")'), (r'vec4\(255, 255, 100\)', 'theme.get_color("status_warning")'), (r'vec4\(240, 200, 80\)', 'theme.get_color("status_warning")'), (r'vec4\(255, 150, 50\)', 'theme.get_color("status_warning")'), (r'vec4\(200, 180, 100\)', 'theme.get_color("status_warning")'), # status_success (r'vec4\(80, 255, 80\)', 'theme.get_color("status_success")'), (r'vec4\(80, 255, 80, ([\d\.]+)\)', r'theme.get_color("status_success", alpha=\1)'), (r'imgui\.ImVec4\(0, 1, 0, 1\)', 'theme.get_color("status_success")'), (r'imgui\.ImVec4\(0\.2, 0\.9, 0\.2, 1\)', 'theme.get_color("status_success")'), (r'imgui\.ImVec4\(0\.2, 0\.8, 0\.2, 1\.0\)', 'theme.get_color("status_success")'), (r'imgui\.ImVec4\(0\.39, 1\.0, 0\.39, ([\d\.]+)\)', r'theme.get_color("status_success", alpha=\1)'), (r'imgui\.ImVec4\(0\.3, 0\.8, 0\.3, 1\)', 'theme.get_color("status_success")'), (r'vec4\(100, 255, 100\)', 'theme.get_color("status_success")'), (r'vec4\(120, 220, 120\)', 'theme.get_color("status_success")'), (r'vec4\(0, 255, 0, ([\d\.]+)\)', r'theme.get_color("status_success", alpha=\1)'), (r'vec4\(51, 230, 51\)', 'theme.get_color("status_success")'), # status_info (r'imgui\.ImVec4\(0, 1, 1, 1\)', 'theme.get_color("status_info")'), (r'imgui\.ImVec4\(0\.3, 0\.8, 1, 1\)', 'theme.get_color("status_info")'), (r'imgui\.ImVec4\(0\.4, 0\.6, 0\.7, 1\.0\)', 'theme.get_color("status_info")'), (r'vec4\(77, 178, 255\)', 'theme.get_color("status_info")'), (r'vec4\(100, 150, 180\)', 'theme.get_color("status_info")'), # text_disabled (r'imgui\.ImVec4\(0\.7, 0\.7, 0\.7, 1\)', 'theme.get_color("text_disabled")'), (r'vec4\(180, 180, 180\)', 'theme.get_color("text_disabled")'), (r'vec4\(160, 160, 160\)', 'theme.get_color("text_disabled")'), (r'vec4\(200, 220, 160\)', 'theme.get_color("text_disabled")'), # bubble backgrounds (r'imgui\.ImVec4\(0\.15, 0\.14, 0\.10, 0\.7\)', 'theme.get_color("bubble_vendor", alpha=0.7)'), (r'vec4\(50, 40, 20\)', 'theme.get_color("bubble_vendor")'), # Slices (r'vec4\(255, 165, 0, 0\.2\)', 'theme.get_color("slice_manual", alpha=0.2)'), (r'vec4\(0, 255, 0, 0\.15\)', 'theme.get_color("slice_auto", alpha=0.15)'), (r'vec4\(100, 100, 255, 0\.3\)', 'theme.get_color("slice_selection", alpha=0.3)'), (r'imgui\.ImVec4\(1\.0, 0\.65, 0, 0\.2\)', 'theme.get_color("slice_manual", alpha=0.2)'), (r'imgui\.ImVec4\(0, 1\.0, 0, 0\.1\)', 'theme.get_color("slice_auto", alpha=0.1)'), (r'imgui\.ImVec4\(0\.4, 0\.4, 1\.0, 0\.3\)', 'theme.get_color("slice_selection", alpha=0.3)'), (r'imgui\.ImVec4\(0, 1\.0, 0, 0\.15\)', 'theme.get_color("slice_auto", alpha=0.15)'), (r'imgui\.ImVec4\(0, 0, 1\.0, 0\.15\)', 'theme.get_color("slice_selection", alpha=0.15)'), (r'imgui\.ImVec4\(1\.0, 1\.0, 0, 0\.2\)', 'theme.get_color("status_warning", alpha=0.2)'), ] def apply_lift(path: Path): content = path.read_text(encoding="utf-8") original = content for pattern, replacement in REPLACEMENTS: content = re.sub(pattern, replacement, content) # Specialized replacements # MMA status block content = re.sub(r'if app\.mma_status == "idle": status_col = imgui\.ImVec4\(0\.7, 0\.7, 0\.7, 1\)', 'if app.mma_status == "idle": status_col = theme.get_color("text_disabled")', content) content = re.sub(r'elif app\.mma_status == "running": status_col = vec4\(80, 255, 80\) if is_nerv else imgui\.ImVec4\(1, 1, 0, 1\)', 'elif app.mma_status == "running": status_col = theme.get_color("status_warning")', content) content = re.sub(r'elif app\.mma_status == "done": status_col = imgui\.ImVec4\(0, 1, 0, 1\)', 'elif app.mma_status == "done": status_col = theme.get_color("status_success")', content) content = re.sub(r'elif app\.mma_status == "error": status_col = vec4\(255, 72, 64\) if is_nerv else imgui\.ImVec4\(1, 0, 0, 1\)', 'elif app.mma_status == "error": status_col = theme.get_color("status_error")', content) content = re.sub(r'elif app\.mma_status == "paused": status_col = imgui\.ImVec4\(1, 0\.5, 0, 1\)', 'elif app.mma_status == "paused": status_col = theme.get_color("status_warning")', content) if content != original: path.write_text(content, encoding="utf-8") print(f"Lifted colors in {path}") if __name__ == "__main__": apply_lift(Path("src/gui_2.py"))