-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
executable file
·145 lines (113 loc) · 4.96 KB
/
update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/python3
#
# A script to import the original icons and patch them by removing the
# recolouring logic for a static version of the Breeze Dark icon theme.
#
import glob
import os
import re
import shutil
COLOUR_MAPPING = {
# <class>: <colour>
"ColorScheme-Text": "#fcfcfc",
"ColorScheme-Accent": "#3daee9",
"ColorScheme-Highlight": "#3daee9",
"ColorScheme-Background": "#2a2e32",
"ColorScheme-ButtonText": "#7B7C7E",
"ColorScheme-NegativeText": "#da4453",
"ColorScheme-NeutralText": "#f67400",
"ColorScheme-PositiveText": "#27ae60",
}
# Fix for BUG 448169
COLOUR_FOLDER_FIX = "#31363b"
SYSTEM_ICONS = "/usr/share/icons/breeze-dark"
FOLDERS = [
"actions",
"animations",
"applets",
"apps",
"categories",
"devices",
"emblems",
"emotes",
"mimetypes",
"places",
"preferences",
"status"
]
for folder in FOLDERS:
print("Processing:", folder.ljust(70))
# Update with system icons
os.system(f"cp -r '{SYSTEM_ICONS}/{folder}' ./")
# Gather file list
files = glob.glob(folder + "/**/*.svg", recursive=True)
for path in files:
print("->", path[:70].ljust(70), end="\r")
# Skip symlinks
if os.path.islink(path):
continue
with open(path, "r", encoding="utf-8") as f:
svg = f.read()
# Use regex to remove <style> and <defs> tags
svg = re.sub(r'<style[^>]*>.*?</style>', '', svg, flags=re.DOTALL)
# svg = re.sub(r'<defs[^>]*>.*?</defs>', '', svg, flags=re.DOTALL)
# Make sure everything between "<path>" and the end tag "/>" are on the same line
while re.search(r'<path[^>]*\n[^>]*>', svg):
svg = re.sub(r'(<path[^>]*?)\s*\n\s*([^>]*>)', r'\1 \2', svg, flags=re.DOTALL)
# Patch "currentColor" fill with the appropriate colour
new_lines = []
for line in svg.splitlines():
if "currentColor" in line:
for class_name, colour in COLOUR_MAPPING.items():
if class_name in line:
# Remove class attribute
line = line.replace(f"class=\"{class_name}\"", "")
line = line.replace("currentColor", colour)
# Fix inner icon for folders (BUG 448169)
if class_name == "ColorScheme-Text" and "fill-opacity:0.6" in line:
line = line.replace(colour, COLOUR_FOLDER_FIX)
# Not an inline class? Likely defined in the <g> tag
if "fill:currentColor" in line and not "class=" in line:
line = line.replace("currentColor", COLOUR_MAPPING["ColorScheme-Text"])
# Some files have a class attribute, but no fill style. Add it in, I guess?
if "class=" in line:
class_name = line.split("class=\"")[1].split("\"")[0].strip()
colour = COLOUR_MAPPING["ColorScheme-Text"]
if "style=" in line:
line = line.replace("style=\"", f"style=\"fill:{colour};color:{colour}")
line = line.replace(f"class=\"{class_name}\"", "")
else:
line = line.replace(f"class=\"{class_name}\"", f"fill=\"{colour}\" color=\"{colour}\"")
# Weather applets use "color" in the group or "stroke" instead
# if "applets/48/weather-" in path:
# colour = COLOUR_MAPPING["ColorScheme-Text"]
# if "<g" in line and "fill=" in line:
# line = line.replace("fill=", f"color=\"{colour}\" fill=")
# if "<g" in line and "class=" in line:
# line = line.replace("class=", f"fill=\"{colour}\" class=")
new_lines.append(line)
# Write patched file
with open(path, "w", encoding="utf-8") as f:
for line in new_lines:
f.write(line.strip() + "\n")
print(" " * 70, end="\r")
# ====== Restore personal preferences ======
# Prefer 64px version instead of 96px places icons
if os.path.exists("places/96/"):
shutil.rmtree("places/96/")
# Git folder too thin at 64px; prefer 32px version
os.remove("places/64/folder-git.svg")
# Prefer classic dialog icons
os.system("git checkout status/64/dialog-*.svg")
# Prefer older, lighter black folder icon
os.system("git checkout places/{16,22,24,32,48,64}/folder-black.svg")
# Prefer older list remove icon
os.system("git checkout actions/{16,22}/list-remove.svg actions/{16,22}/list-remove-symbolic.svg")
# Prefer older x-trash icon
os.system("git checkout mimetypes/{16,22,32,64}/application-x-trash.svg")
# Overlay icons larger in Dolphin 24.12.0? (BUG: 497372)
# https://bugs.kde.org/show_bug.cgi?id=497372
os.system("git checkout emblems/22/{emblem-symbolic-link,emblem-readonly}.svg")
# Symbolic weather icons broken; use non-symbolic versions
for file in glob.glob("applets/48/weather-*-symbolic.svg"):
os.remove(file)