From f3b050df7f0ef55a4b9f0bdf8a0b98679b858a3b Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Tue, 8 Oct 2019 10:05:54 -0400 Subject: Now i3 theme can be generated from config files. --- src/config.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/config.py') diff --git a/src/config.py b/src/config.py index c8fa8bd..80e264f 100755 --- a/src/config.py +++ b/src/config.py @@ -1,4 +1,4 @@ -import re,tempfile,shutil +import re,tempfile,shutil,theme config_keys=["client.focused", "client.focused_inactive", @@ -66,7 +66,31 @@ def extract(config_file): f.close() tmp.close() return(tmp.name) - + + +def extract_theme(config_file): + """ + Return a ThemeBuilder object of the config_file file. + """ + f=open(config_file,"r") + build=theme.ThemeBuilder() + in_colors=False + for line_orig in f: + line=no_comment(line_orig) + is_theme_line=False + for key in config_keys: + if contains(".*"+key+"\s",line): + is_theme_line=True + if contains(".*colors",line): + in_colors=True + if is_theme_line or in_colors: + build.parse(line_orig) # Seems to by strange to have comment here + if contains(".*}",line) and in_colors: + in_colors=False + f.close() + return(build) + + def write_theme(tmp_config,theme): """ Write the theme in a temporary file -- cgit v1.2.3