This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
forked from linuxmint/mint-themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-themes.py
executable file
·171 lines (143 loc) · 8 KB
/
generate-themes.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/python3
import os, sys
from constants import Y_HEX_ACCENT1, Y_HEX_ACCENT2, Y_HEX_ACCENT3, Y_HEX_ACCENT4
from constants import y_hex_colors1, y_hex_colors2, y_hex_colors3, y_hex_colors4
def change_value (key, value, file):
if value is not None:
command = "sed -i '/%(key)s=/c\%(key)s=%(value)s' %(file)s" % {'key':key, 'value':value, 'file':file}
else:
command = "sed -i '/%(key)s=/d' %(file)s" % {'key':key, 'file':file}
os.system(command)
def usage ():
print ("Usage: generate-themes.py [color]")
print ("color can be 'Aqua', 'Blue', 'Brown', 'Grey', 'Orange', 'Pink', 'Purple', 'Red', 'Sand', 'Teal', 'Yellow' or 'All'.")
sys.exit(1)
def y_colorize_directory (path, variation):
for accent in Y_HEX_ACCENT1:
os.system("find %s -name '*.*' -type f -exec sed -i 's/%s/%s/gI' {} \\;" % (path, accent, y_hex_colors1[variation]))
for accent in Y_HEX_ACCENT2:
os.system("find %s -name '*.*' -type f -exec sed -i 's/%s/%s/gI' {} \\;" % (path, accent, y_hex_colors2[variation]))
for accent in Y_HEX_ACCENT3:
os.system("find %s -name '*.*' -type f -exec sed -i 's/%s/%s/gI' {} \\;" % (path, accent, y_hex_colors3[variation]))
for accent in Y_HEX_ACCENT4:
os.system("find %s -name '*.*' -type f -exec sed -i 's/%s/%s/gI' {} \\;" % (path, accent, y_hex_colors4[variation]))
def generate_theme(color):
# build Sucharu color variations
# for color in y_hex_colors1.keys():
for variant in ["", "-Dark", "-Darker"]:
original_name = "Sucharu%s" % variant
path = os.path.join("src/Mint-Y/variations/%s" % color)
if os.path.isdir(path):
print("Derivating %s-%s" % (original_name, color))
# Copy theme
theme = "usr/share/themes/%s-%s" % (original_name, color)
theme_index = os.path.join(theme, "index.theme")
os.system("cp -R usr/share/themes/%s %s" % (original_name, theme))
# Theme name
for key in ["Name", "GtkTheme"]:
change_value(key, "%s-%s" % (original_name, color), theme_index)
for key in ["MetacityTheme"]:
metacity_variant = original_name.replace("Darker", "Dark")
change_value(key, "%s-%s" % (metacity_variant, color), theme_index)
for key in ["IconTheme"]:
change_value(key, "%s-%s" % (original_name, color), theme_index)
for key in ["CursorTheme"]:
change_value(key, "Sucharu-%s" % color, theme_index)
# Regenerate GTK4 sass
os.system("cp -R src/Mint-Y/gtk-4.0/sass %s/gtk-4.0/" % theme)
y_colorize_directory("%s/gtk-4.0/sass" % theme, color)
os.chdir("%s/gtk-4.0" % theme)
if (variant == "-Dark"):
os.system("cp sass/gtk-dark.scss sass/gtk.scss")
os.system("sassc ./sass/gtk.scss gtk.css")
elif (variant == "-Darker"):
os.system("cp sass/gtk-darker.scss sass/gtk.scss")
else:
os.system("sassc ./sass/gtk-dark.scss gtk-dark.css")
os.system("sassc ./sass/gtk.scss gtk.css")
os.system("rm -rf sass .sass-cache")
os.chdir(curdir)
# Regenerate GTK3 sass
os.system("cp -R src/Mint-Y/gtk-3.0/sass %s/gtk-3.0/" % theme)
y_colorize_directory("%s/gtk-3.0/sass" % theme, color)
os.chdir("%s/gtk-3.0" % theme)
# os.system("sed -i 's/no-tint/tint/gI' ./sass/gtk.scss")
# os.system("sed -i 's/no-tint/tint/gI' ./sass/gtk-dark.scss")
if (variant == "-Dark"):
os.system("cp sass/gtk-dark.scss sass/gtk.scss")
elif (variant == "-Darker"):
os.system("cp sass/gtk-darker.scss sass/gtk.scss")
else:
os.system("rm sass/gtk-dark.scss sass/gtk-darker.scss")
os.system("sassc ./sass/gtk.scss gtk.css")
os.system("rm -rf sass .sass-cache")
os.chdir(curdir)
# Regenerate Cinnamon sass
if (variant != "-Darker"):
# Darker variants have no cinnamon style
os.system("cp -R src/Mint-Y/cinnamon/sass %s/cinnamon/" % theme)
y_colorize_directory("%s/cinnamon/sass" % theme, color)
os.chdir("%s/cinnamon" % theme)
if (variant == "-Dark"):
os.system("cp sass/cinnamon-dark.scss sass/cinnamon.scss")
os.system("sassc ./sass/cinnamon.scss cinnamon.css")
os.system("rm -rf sass .sass-cache")
os.chdir(curdir)
# Accent color
files = []
files.append(os.path.join(theme, "gtk-2.0", "gtkrc"))
files.append(os.path.join(theme, "gtk-2.0", "main.rc"))
files.append(os.path.join(theme, "gtk-2.0", "panel.rc"))
files.append(os.path.join(theme, "gtk-2.0", "apps.rc"))
files.append(os.path.join(theme, "gtk-2.0", "menubar-toolbar.rc"))
for file in files:
if os.path.exists(file):
for accent in Y_HEX_ACCENT1:
os.system("sed -i s'/%(accent)s/%(color_accent)s/gI' %(file)s" % {'accent': accent, 'color_accent': y_hex_colors1[color], 'file': file})
for accent in Y_HEX_ACCENT2:
os.system("sed -i s'/%(accent)s/%(color_accent)s/gI' %(file)s" % {'accent': accent, 'color_accent': y_hex_colors2[color], 'file': file})
for accent in Y_HEX_ACCENT3:
os.system("sed -i s'/%(accent)s/%(color_accent)s/gI' %(file)s" % {'accent': accent, 'color_accent': y_hex_colors3[color], 'file': file})
for accent in Y_HEX_ACCENT4:
os.system("sed -i s'/%(accent)s/%(color_accent)s/gI' %(file)s" % {'accent': accent, 'color_accent': y_hex_colors4[color], 'file': file})
# Remove metacity-theme-3.xml (it doesn't need to be derived since it's using GTK colors, and Cinnamon doesn't want to list it)
os.system("rm -rf %s" % os.path.join(theme, "metacity-1"))
directories = []
directories.append(os.path.join(theme, "cinnamon/common-assets"))
directories.append(os.path.join(theme, "cinnamon/light-assets"))
directories.append(os.path.join(theme, "cinnamon/dark-assets"))
for directory in directories:
if os.path.exists(directory):
y_colorize_directory(directory, color)
# Assets
os.system("rm -rf %s/gtk-4.0/assets" % theme)
os.system("rm -rf %s/gtk-3.0/assets" % theme)
os.system("rm -rf %s/gtk-2.0/assets" % theme)
if variant == "-Dark":
os.system("cp -R %s/gtk-2.0/assets-dark %s/gtk-2.0/assets" % (path, theme))
os.system("cp -R %s/xfwm4-dark/*.png %s/xfwm4/" % (path, theme))
else:
os.system("cp -R %s/gtk-2.0/assets %s/gtk-2.0/assets" % (path, theme))
os.system("cp -R %s/xfwm4/*.png %s/xfwm4/" % (path, theme))
os.system("cp -R %s/gtk-3.0/assets %s/gtk-3.0/assets" % (path, theme))
os.system("cp -R %s/gtk-4.0/assets %s/gtk-4.0/assets" % (path, theme))
os.system("cp -R files/%s ./usr/share/themes" % theme)
if len(sys.argv) < 2:
usage()
else:
color_variation = sys.argv[1]
if not color_variation in ["Aqua", "Blue", "Brown", "Grey", "Orange", "Pink", "Purple", "Red", "Sand", "Teal", 'Yellow', "All"]:
usage()
curdir = os.getcwd()
# if os.path.exists("usr"):
# os.system("rm -rf usr/")
os.system("mkdir -p usr/share/themes")
# Build Sucharu Base themes (light, dark, darker)
os.chdir("src/Mint-Y")
os.system("./build-themes.py")
os.chdir(curdir)
if color_variation == "All":
for color in y_hex_colors1.keys():
generate_theme(color)
else:
generate_theme(color_variation)