2020-09-24 14:52:46 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
2020-10-07 14:48:04 -07:00
|
|
|
import configparser
|
2020-09-24 14:52:46 -07:00
|
|
|
|
2020-10-07 14:48:04 -07:00
|
|
|
parser = argparse.ArgumentParser(description='Convert INI colorschemes to EET description files.')
|
2020-09-24 14:52:46 -07:00
|
|
|
parser.add_argument('input_file',
|
|
|
|
type=argparse.FileType('r'),
|
2020-10-07 14:48:04 -07:00
|
|
|
help='INI File to convert')
|
2020-09-24 14:52:46 -07:00
|
|
|
parser.add_argument('output_file',
|
|
|
|
type=argparse.FileType('w'),
|
|
|
|
help='EET description to write')
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-10-07 14:48:04 -07:00
|
|
|
cfg = configparser.ConfigParser()
|
|
|
|
cfg.read_file(args.input_file)
|
|
|
|
|
2020-09-24 14:52:46 -07:00
|
|
|
out = args.output_file
|
|
|
|
|
2020-10-07 14:48:04 -07:00
|
|
|
assert(int(cfg['Main']['version']) == 1)
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write('group "Color_Scheme" struct {\n')
|
2020-10-07 14:48:04 -07:00
|
|
|
|
|
|
|
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "version" int: {};\n'
|
2020-10-07 15:07:17 -07:00
|
|
|
.format(cfg.get('Main', 'version', fallback='1')))
|
2020-10-07 14:48:04 -07:00
|
|
|
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "md.version" int: {};\n'
|
2020-10-07 15:07:17 -07:00
|
|
|
.format(cfg.get('Metadata', 'version', fallback='1')))
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "md.name" string: "{}";\n'
|
2020-10-07 14:48:04 -07:00
|
|
|
.format(cfg['Metadata']['name']))
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "md.author" string: "{}";\n'
|
2020-10-07 14:48:04 -07:00
|
|
|
.format(cfg['Metadata']['author']))
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "md.website" string: "{}";\n'
|
2020-10-07 15:07:17 -07:00
|
|
|
.format(cfg.get('Metadata', 'website', fallback='')))
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' value "md.license" string: "{}";\n'
|
2020-10-07 14:48:04 -07:00
|
|
|
.format(cfg['Metadata']['license']))
|
2020-09-24 14:52:46 -07:00
|
|
|
|
|
|
|
def parse_color(color_string):
|
|
|
|
h = color_string.lstrip('#')
|
|
|
|
if len(h) == 6:
|
|
|
|
return tuple(int(h[i:i+2], 16) for i in (0, 2, 4)) + (255,)
|
|
|
|
elif len(h) == 3:
|
|
|
|
return tuple(int(h[i]+h[i], 16) for i in (0, 1, 2)) + (255,)
|
|
|
|
elif len(h) == 8:
|
|
|
|
return tuple(int(h[i:i+2], 16) for i in (0, 2, 4, 6))
|
|
|
|
elif len(h) == 4:
|
|
|
|
return tuple(int(h[i]+h[i], 16) for i in (0, 1, 2, 3))
|
|
|
|
|
|
|
|
def write_color(color_string):
|
|
|
|
(r, g, b, a) = parse_color(color_string)
|
|
|
|
out.write(' group "Color" struct {\n')
|
|
|
|
out.write(' value "r" uchar: {};\n'.format(r))
|
|
|
|
out.write(' value "g" uchar: {};\n'.format(g))
|
|
|
|
out.write(' value "b" uchar: {};\n'.format(b))
|
|
|
|
out.write(' value "a" uchar: {};\n'.format(a))
|
|
|
|
out.write(' }\n')
|
|
|
|
|
2020-10-07 15:07:17 -07:00
|
|
|
def write_name_color(color_name, default):
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' group "{}" struct {{\n'.format(color_name))
|
2020-10-07 15:07:17 -07:00
|
|
|
write_color(cfg.get('Colors', color_name, fallback=default))
|
2020-09-24 14:52:46 -07:00
|
|
|
out.write(' }\n')
|
|
|
|
|
2020-10-07 15:07:17 -07:00
|
|
|
write_name_color('def', '#aaaaaa')
|
|
|
|
write_name_color('bg', '#202020')
|
|
|
|
write_name_color('fg', '#aaaaaa')
|
|
|
|
write_name_color('main', '#3599ff')
|
|
|
|
write_name_color('hl', '#ffffff')
|
|
|
|
write_name_color('end_sel', '#ff3300')
|
|
|
|
write_name_color('tab_missed_1', '#ff9933')
|
|
|
|
write_name_color('tab_missed_2', '#ff3300')
|
|
|
|
write_name_color('tab_missed_3', '#ff0000')
|
|
|
|
write_name_color('tab_missed_over_1', '#ffff40')
|
|
|
|
write_name_color('tab_missed_over_2', '#ff9933')
|
|
|
|
write_name_color('tab_missed_over_3', '#ff0000')
|
|
|
|
write_name_color('tab_title_2', '#000000')
|
2020-09-24 14:52:46 -07:00
|
|
|
|
|
|
|
def write_ansi():
|
|
|
|
out.write(' group "ansi" array {\n')
|
|
|
|
out.write(' count 16;\n')
|
2020-10-07 15:07:17 -07:00
|
|
|
default = ['#000000',
|
|
|
|
'#cc3333',
|
|
|
|
'#33cc33',
|
|
|
|
'#cc8833',
|
|
|
|
'#3333cc',
|
|
|
|
'#cc33cc',
|
|
|
|
'#33cccc',
|
|
|
|
'#cccccc',
|
|
|
|
'#666666',
|
|
|
|
'#ff6666',
|
|
|
|
'#66ff66',
|
|
|
|
'#ffff66',
|
|
|
|
'#6666ff',
|
|
|
|
'#ff66ff',
|
|
|
|
'#66ffff',
|
|
|
|
'#ffffff']
|
|
|
|
|
2020-10-07 14:48:04 -07:00
|
|
|
for c in range(15):
|
2020-10-07 15:07:17 -07:00
|
|
|
write_color(cfg.get('Ansi', 'ansi{0:02d}'.format(c),
|
|
|
|
fallback=default[c]))
|
2020-10-07 14:48:04 -07:00
|
|
|
out.write(' }\n')
|
2020-09-24 14:52:46 -07:00
|
|
|
|
|
|
|
write_ansi()
|
|
|
|
out.write('}\n')
|