ini2desc.py: work with new format
This commit is contained in:
parent
64eb46b032
commit
91cf60e02a
|
@ -3,38 +3,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
import configparser
|
import configparser
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Convert INI colorschemes to EET description files.')
|
|
||||||
parser.add_argument('input_file',
|
|
||||||
type=argparse.FileType('r'),
|
|
||||||
help='INI File to convert')
|
|
||||||
parser.add_argument('output_file',
|
|
||||||
type=argparse.FileType('w'),
|
|
||||||
help='EET description to write')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
cfg = configparser.ConfigParser()
|
|
||||||
cfg.read_file(args.input_file)
|
|
||||||
|
|
||||||
out = args.output_file
|
|
||||||
|
|
||||||
assert(int(cfg['Main']['version']) == 1)
|
|
||||||
out.write('group "Color_Scheme" struct {\n')
|
|
||||||
|
|
||||||
|
|
||||||
out.write(' value "version" int: {};\n'
|
|
||||||
.format(cfg.get('Main', 'version', fallback='1')))
|
|
||||||
|
|
||||||
out.write(' value "md.version" int: {};\n'
|
|
||||||
.format(cfg.get('Metadata', 'version', fallback='1')))
|
|
||||||
out.write(' value "md.name" string: "{}";\n'
|
|
||||||
.format(cfg['Metadata']['name']))
|
|
||||||
out.write(' value "md.author" string: "{}";\n'
|
|
||||||
.format(cfg['Metadata']['author']))
|
|
||||||
out.write(' value "md.website" string: "{}";\n'
|
|
||||||
.format(cfg.get('Metadata', 'website', fallback='')))
|
|
||||||
out.write(' value "md.license" string: "{}";\n'
|
|
||||||
.format(cfg['Metadata']['license']))
|
|
||||||
|
|
||||||
def parse_color(color_string):
|
def parse_color(color_string):
|
||||||
h = color_string.lstrip('#')
|
h = color_string.lstrip('#')
|
||||||
if len(h) == 6:
|
if len(h) == 6:
|
||||||
|
@ -46,7 +14,7 @@ def parse_color(color_string):
|
||||||
elif len(h) == 4:
|
elif len(h) == 4:
|
||||||
return tuple(int(h[i]+h[i], 16) for i in (0, 1, 2, 3))
|
return tuple(int(h[i]+h[i], 16) for i in (0, 1, 2, 3))
|
||||||
|
|
||||||
def write_color(color_string):
|
def write_color(out, color_string):
|
||||||
(r, g, b, a) = parse_color(color_string)
|
(r, g, b, a) = parse_color(color_string)
|
||||||
out.write(' group "Color" struct {\n')
|
out.write(' group "Color" struct {\n')
|
||||||
out.write(' value "r" uchar: {};\n'.format(r))
|
out.write(' value "r" uchar: {};\n'.format(r))
|
||||||
|
@ -55,49 +23,81 @@ def write_color(color_string):
|
||||||
out.write(' value "a" uchar: {};\n'.format(a))
|
out.write(' value "a" uchar: {};\n'.format(a))
|
||||||
out.write(' }\n')
|
out.write(' }\n')
|
||||||
|
|
||||||
def write_name_color(color_name, default):
|
def write_md(out, cfg):
|
||||||
|
out.write(' value "version" int: {};\n'
|
||||||
|
.format(cfg.get('Main', 'version', fallback='1')))
|
||||||
|
|
||||||
|
out.write(' value "md.version" int: {};\n'
|
||||||
|
.format(cfg.get('Metadata', 'version', fallback='1')))
|
||||||
|
out.write(' value "md.name" string: "{}";\n'
|
||||||
|
.format(cfg['Metadata']['name']))
|
||||||
|
out.write(' value "md.author" string: "{}";\n'
|
||||||
|
.format(cfg['Metadata']['author']))
|
||||||
|
out.write(' value "md.website" string: "{}";\n'
|
||||||
|
.format(cfg.get('Metadata', 'website', fallback='')))
|
||||||
|
out.write(' value "md.license" string: "{}";\n'
|
||||||
|
.format(cfg['Metadata']['license']))
|
||||||
|
|
||||||
|
def write_named_color(out, cfg, section, color_name, default=None):
|
||||||
out.write(' group "{}" struct {{\n'.format(color_name))
|
out.write(' group "{}" struct {{\n'.format(color_name))
|
||||||
write_color(cfg.get('Colors', color_name, fallback=default))
|
write_color(out, cfg.get(section, color_name, fallback=default))
|
||||||
out.write(' }\n')
|
out.write(' }\n')
|
||||||
|
|
||||||
write_name_color('def', '#aaaaaa')
|
def write_ui_colors(out, cfg):
|
||||||
write_name_color('bg', '#202020')
|
write_named_color(out, cfg, 'Colors', 'def', '#aaaaaa')
|
||||||
write_name_color('fg', '#aaaaaa')
|
write_named_color(out, cfg, 'Colors', 'bg', '#202020')
|
||||||
write_name_color('main', '#3599ff')
|
write_named_color(out, cfg, 'Colors', 'fg', '#aaaaaa')
|
||||||
write_name_color('hl', '#ffffff')
|
write_named_color(out, cfg, 'Colors', 'main', '#3599ff')
|
||||||
write_name_color('end_sel', '#ff3300')
|
write_named_color(out, cfg, 'Colors', 'hl', '#ffffff')
|
||||||
write_name_color('tab_missed_1', '#ff9933')
|
write_named_color(out, cfg, 'Colors', 'end_sel', '#ff3300')
|
||||||
write_name_color('tab_missed_2', '#ff3300')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_1', '#ff9933')
|
||||||
write_name_color('tab_missed_3', '#ff0000')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_2', '#ff3300')
|
||||||
write_name_color('tab_missed_over_1', '#ffff40')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_3', '#ff0000')
|
||||||
write_name_color('tab_missed_over_2', '#ff9933')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_over_1', '#ffff40')
|
||||||
write_name_color('tab_missed_over_3', '#ff0000')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_over_2', '#ff9933')
|
||||||
write_name_color('tab_title_2', '#000000')
|
write_named_color(out, cfg, 'Colors', 'tab_missed_over_3', '#ff0000')
|
||||||
|
write_named_color(out, cfg, 'Colors', 'tab_title_2', '#000000')
|
||||||
|
|
||||||
def write_ansi():
|
def write_color_block(out, cfg, block):
|
||||||
out.write(' group "ansi" array {\n')
|
out.write(' group "{}" struct {{\n'.format(block))
|
||||||
out.write(' count 16;\n')
|
out.write(' group "Color_Block" struct {\n')
|
||||||
default = ['#000000',
|
write_named_color(out, cfg, block, 'def')
|
||||||
'#cc3333',
|
write_named_color(out, cfg, block, 'black')
|
||||||
'#33cc33',
|
write_named_color(out, cfg, block, 'red')
|
||||||
'#cc8833',
|
write_named_color(out, cfg, block, 'green')
|
||||||
'#3333cc',
|
write_named_color(out, cfg, block, 'yellow')
|
||||||
'#cc33cc',
|
write_named_color(out, cfg, block, 'blue')
|
||||||
'#33cccc',
|
write_named_color(out, cfg, block, 'magenta')
|
||||||
'#cccccc',
|
write_named_color(out, cfg, block, 'cyan')
|
||||||
'#666666',
|
write_named_color(out, cfg, block, 'white')
|
||||||
'#ff6666',
|
write_named_color(out, cfg, block, 'inverse_fg')
|
||||||
'#66ff66',
|
write_named_color(out, cfg, block, 'inverse_bg')
|
||||||
'#ffff66',
|
out.write(' }\n')
|
||||||
'#6666ff',
|
|
||||||
'#ff66ff',
|
|
||||||
'#66ffff',
|
|
||||||
'#ffffff']
|
|
||||||
|
|
||||||
for c in range(15):
|
|
||||||
write_color(cfg.get('Ansi', 'ansi{0:02d}'.format(c),
|
|
||||||
fallback=default[c]))
|
|
||||||
out.write(' }\n')
|
out.write(' }\n')
|
||||||
|
|
||||||
write_ansi()
|
def main():
|
||||||
out.write('}\n')
|
parser = argparse.ArgumentParser(description='Convert INI colorschemes to EET description files.')
|
||||||
|
parser.add_argument('input_file',
|
||||||
|
type=argparse.FileType('r'),
|
||||||
|
help='INI File to convert')
|
||||||
|
parser.add_argument('output_file',
|
||||||
|
type=argparse.FileType('w'),
|
||||||
|
help='EET description to write')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
cfg = configparser.ConfigParser()
|
||||||
|
cfg.read_file(args.input_file)
|
||||||
|
|
||||||
|
out = args.output_file
|
||||||
|
|
||||||
|
assert(int(cfg['Main']['version']) == 1)
|
||||||
|
out.write('group "Color_Scheme" struct {\n')
|
||||||
|
write_md(out, cfg)
|
||||||
|
write_ui_colors(out, cfg)
|
||||||
|
write_color_block(out, cfg, 'Normal')
|
||||||
|
write_color_block(out, cfg, 'Bright')
|
||||||
|
write_color_block(out, cfg, 'Faint')
|
||||||
|
out.write('}\n')
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue