-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorize.py
executable file
·308 lines (281 loc) · 9.13 KB
/
colorize.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#!/usr/bin/env python3
import json
import argparse
import sys
import os
#############
# functions #
#############
def data_sub_link(dictio, key, value):
"""
return type: void
description:
replace the "@key_name" links
with the color string value of
the refferenced key
"""
if value.find("@") > -1:
index_str = value[1:]
dictio[key] = dictio[index_str]
if args.debug:
print("{k}: {v}".format(k=key, v=dictio[key]))
def data_rgb_to_hex(dictio, key, value):
"""
return type: void
description:
replace the "rgba()" values
with the corresponding rgb hex string
"""
if value.find("rgb") > -1:
oparen = value.find("(")
cparen = value.find(")")
# index_str = value[1:]
vallist = value[oparen + 1: cparen].split(",")
r = int(vallist[0])
g = int(vallist[1])
b = int(vallist[2])
res = "#{0:02x}{1:02x}{2:02x}".format(r, g, b)
dictio[key] = res
if args.debug:
print("{k}: {v}".format(k=key, v=dictio[key]))
def colorize_gtk2(gtkrc_file, target_rc, search_dict):
"""
return type: void
Description:
replace the colors on the gtk rc file specified
in "gtkrc_file" using the provided "search_dict"
with the colors from the global "replace" dict,
write the file to the "target_rc" gtkrc file
"""
with open(gtkrc_file, "r") as file:
data = file.read()
for keys, values in search_dict.items():
# print("{}: {}".format(keys, values))
data = data.replace(search_dict[keys], replace[keys])
if args.debug:
print(data)
with open(target_rc, "w") as file:
file.write(data)
########
# Main #
########
# Initialize parser
parser = argparse.ArgumentParser()
# Adding optional argument
parser.add_argument("-f", "--file", required="true", help="JSON file to use")
parser.add_argument(
"-r", "--resources", dest="res", required="true", help="adw-gtk2 dir"
)
parser.add_argument(
"-t",
"--target",
dest="targ",
help="should be the PARENT dir "
"containing the 'adw-gtk3' and 'adw-gtk3-dark' dirs",
)
parser.add_argument(
"-d", "--debug", action="store_true", help="Show Debug Output"
)
# Read arguments from command line
args = parser.parse_args()
if args.debug:
print("Displaying Debug Output of % s" % parser.prog)
print("File '{}' selected".format(args.file))
with open(args.file) as json_file:
data = json.load(json_file)
if args.debug:
print("Data read from file:", args.file)
print("Name:", data["name"])
# print("Vars:", data["variables"])
for keys, values in data["variables"].items():
print("{key: >24}: {value}".format(key=keys, value=values))
# correct data
for keys, values in data["variables"].items():
data_sub_link(data["variables"], keys, values)
for keys, values in data["variables"].items():
data_rgb_to_hex(data["variables"], keys, values)
if args.debug:
print("Corrected Data:")
print("Name:", data["name"])
# print("Vars:", data["variables"])
for keys, values in data["variables"].items():
print("{key: >24}: {value}".format(key=keys, value=values))
search_dark = {
# Text/base
"text_color": "white",
"base_color": "#232729",
# Foreground/background
"fg_color": "#eeeeec",
"bg_color": "#33393b",
# Tooltips
"tooltip_fg_color": "#ffffff",
"tooltip_bg_color": "#343434",
# Selected foreground/background
"selected_fg_color": "#ffffff",
"selected_bg_color": "#215d9c",
# Insensitive foreground/background
"insensitive_fg_color": "#919494",
"insensitive_bg_color": "#2d3234",
# Menubar
"menubar_bg_color": "#262b2d",
"menubar_fg_color": "#ffffff",
# Toolbar
"toolbar_bg_color": "#262b2d",
"toolbar_fg_color": "#ffffff",
# Menus
"menu_color": "#262b2d",
"menu_bg_color": "#262b2d",
"menu_fg_color": "#ffffff",
# Panel
"panel_bg_color": "#262b2d",
"panel_fg_color": "#ffffff",
# Links
"link_color": "#4a90d9",
"visited_link_color": "#2a76c6",
# button
"btn_bg_color": "#343434",
"btn_fg_color": "#eeeeec",
# titlebar
"titlebar_bg_color": "#262b2d",
"titlebar_fg_color": "#ffffff",
# caret
"primary_caret_color": "#eeeeec",
"secondary_caret_color": "#ffffff",
# accent
"accent_bg_color": "#4a90d9",
# Treeview headers
"column_header_color": "#898b8b",
"hover_column_header_color": "#bcbdbc",
# Window decoration
"window_color": "#2c3133",
}
search_light = {
# Text/base
"text_color": "black",
"base_color": "white",
# Foreground/background
"fg_color": "#2e3436",
"bg_color": "#fafafa",
# Tooltips
"tooltip_fg_color": "#ffffff",
"tooltip_bg_color": "#343434",
# Selected foreground/background
"selected_fg_color": "#ffffff",
"selected_bg_color": "#3584e4",
# Insensitive foreground/background
"insensitive_fg_color": "#8b8e8f",
"insensitive_bg_color": "#f0f0f0",
# Menubar
"menubar_bg_color": "#eeeeee",
"menubar_fg_color": "black",
# Toolbar
"toolbar_bg_color": "#eeeeee",
"toolbar_fg_color": "black",
# Menus
"menu_color": "white",
"menu_bg_color": "#eeeeee",
"menu_fg_color": "black",
# Panel
"panel_bg_color": "#fafafa",
"panel_fg_color": "black",
# Links
"link_color": "#2a76c6",
"visited_link_color": "#215d9c",
# button
"btn_bg_color": "#eeeeee",
"btn_fg_color": "black",
# titlebar
"titlebar_bg_color": "#fafafa",
"titlebar_fg_color": "black",
# caret
"primary_caret_color": "#2e3436",
"secondary_caret_color": "#000000",
# accent
"accent_bg_color": "#2a76c6",
# Treeview headers
"column_header_color": "#979a9b",
"hover_column_header_color": "#636769",
# Window decoration
"window_color": "#f4f4f4",
}
replace = {
# Text/base
"text_color": data["variables"]["window_fg_color"],
"base_color": data["variables"]["view_bg_color"],
# Foreground/background
"fg_color": data["variables"]["view_fg_color"],
"bg_color": data["variables"]["window_bg_color"],
# Selected foreground/background
"selected_fg_color": data["variables"]["card_bg_color"],
"selected_bg_color": data["variables"]["accent_color"],
# Insensitive foreground/background
"insensitive_fg_color": data["variables"]["accent_fg_color"],
"insensitive_bg_color": data["variables"]["shade_color"],
# Menus
"menu_color": data["variables"]["window_bg_color"],
"menu_bg_color": data["variables"]["window_bg_color"],
"menu_fg_color": data["variables"]["view_fg_color"],
# Menubar
"menubar_bg_color": data["variables"]["view_bg_color"],
"menubar_fg_color": data["variables"]["view_fg_color"],
# Panel
"panel_bg_color": data["variables"]["window_bg_color"],
"panel_fg_color": data["variables"]["view_fg_color"],
# Toolbar
"toolbar_bg_color": data["variables"]["card_bg_color"],
"toolbar_fg_color": data["variables"]["view_fg_color"],
# Links
"link_color": data["variables"]["accent_color"],
"visited_link_color": data["variables"]["accent_fg_color"],
# accent
"accent_bg_color": data["variables"]["accent_color"],
# Treeview headers
"column_header_color": data["variables"]["headerbar_shade_color"],
"hover_column_header_color": data["variables"]["shade_color"],
# Window decoration
"window_color": data["variables"]["card_bg_color"],
# Tooltips
"tooltip_bg_color": data["variables"]["window_bg_color"],
"tooltip_fg_color": data["variables"]["window_fg_color"],
# button
"btn_bg_color": data["variables"]["shade_color"],
"btn_fg_color": data["variables"]["view_fg_color"],
# titlebar
"titlebar_bg_color": data["variables"]["window_bg_color"],
"titlebar_fg_color": data["variables"]["view_fg_color"],
# caret
"primary_caret_color": data["variables"]["view_fg_color"],
"secondary_caret_color": data["variables"]["window_fg_color"],
}
gtk_rc = "{}/adw-gtk3/gtk-2.0/gtkrc".format(args.res)
gtk_dark_rc = "{}/adw-gtk3-dark/gtk-2.0/gtkrc".format(args.res)
if args.targ:
target_dir = "{}".format(args.targ)
else:
"""
i will assume that the command to install adw-gtk2 was:
make install INSTALL_DIR=~/.local/share/themes
"""
username = os.environ["USER"]
home_dir = os.environ.get("HOME", "/home/{}".format(username))
target_dir = "{}/.local/share/themes".format(home_dir)
target_light = "{}/adw-gtk3/gtk-2.0/gtkrc".format(target_dir)
target_dark = "{}/adw-gtk3-dark/gtk-2.0/gtkrc".format(target_dir)
if os.path.exists(args.res):
if args.debug:
print("dir exists")
if os.path.isfile(gtk_rc) and os.path.isfile(gtk_dark_rc):
if args.debug:
print("rc files exist")
# colorize light
colorize_gtk2(gtk_rc, target_light, search_light)
# colorize dark
colorize_gtk2(gtk_dark_rc, target_dark, search_dark)
if args.debug:
print("rc files written")
else:
print("rc files don't exist")
sys.exit()
else:
print("invalid dir: {}".format(args.res))
sys.exit()