mirror of
https://gitlab.com/manzerbredes/i3-colors.git
synced 2025-04-19 03:59:44 +00:00
Add theme manager
This commit is contained in:
parent
602c70c517
commit
71688839f0
22 changed files with 1077 additions and 10 deletions
|
@ -1,11 +1,15 @@
|
|||
#!/usr/bin/python
|
||||
import parser
|
||||
import parser, theme, os, argparse
|
||||
|
||||
|
||||
args_parser = argparse.ArgumentParser(description='Process some integers.')
|
||||
args_parser.add_argument('theme_path', metavar='theme', type=str, nargs='?',
|
||||
help='YAML i3 theme path')
|
||||
args = args_parser.parse_args()
|
||||
|
||||
|
||||
print("Starting app...")
|
||||
|
||||
parser.apply_theme("/home/loic/.config/i3/config",parser.theme)
|
||||
##### Apply Theme #####
|
||||
loaded_theme=theme.load(args.theme_path)
|
||||
parser.apply_theme(os.environ["HOME"]+"/.config/i3/config",loaded_theme)
|
||||
|
||||
|
||||
|
|
|
@ -32,12 +32,17 @@ def extract_config(config_file):
|
|||
tmp.close()
|
||||
return(tmp.name)
|
||||
|
||||
def safe_get(theme,key):
|
||||
if key in theme:
|
||||
return(theme[key])
|
||||
return("")
|
||||
|
||||
def apply_to_config(tmp_config,theme):
|
||||
f=open(tmp_config,mode="r")
|
||||
tmp=tempfile.NamedTemporaryFile(mode="w",delete=False)
|
||||
|
||||
##### Apply bar theme #####
|
||||
bar_theme=theme["bar"]
|
||||
bar_theme=theme["bar_colors"]
|
||||
for line in f:
|
||||
if contains(".*colors\s{",line):
|
||||
tmp.write(line)
|
||||
|
@ -53,18 +58,17 @@ def apply_to_config(tmp_config,theme):
|
|||
shutil.move(tmp.name,tmp_config)
|
||||
|
||||
##### Apply client theme #####
|
||||
client_theme=theme["client"]
|
||||
client_theme=theme["window_colors"]
|
||||
f=open(tmp_config,mode="a")
|
||||
for key,value in client_theme.items():
|
||||
f.write(key+" "+value["background"]+" "+value["text"]+" "+value["indicator"]+" "+value["child_border"]+"\n")
|
||||
f.write("client."+key+" "+value["border"]+" "+value["background"]+" "+value["text"]+" "+value["indicator"]+" "+safe_get(value,"child_border")+"\n")
|
||||
f.close()
|
||||
|
||||
def apply_theme(config_file,theme):
|
||||
print("Applying theme: "+theme["meta"]["description"])
|
||||
tmp=extract_config(config_file)
|
||||
apply_to_config(tmp,theme)
|
||||
shutil.move(tmp,"/home/loic/aa.theme")
|
||||
|
||||
|
||||
shutil.move(tmp,config_file)
|
||||
|
||||
theme={
|
||||
"bar":{
|
||||
|
|
30
src/theme.py
Normal file
30
src/theme.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import yaml,re
|
||||
|
||||
|
||||
def configure(theme):
|
||||
if "colors" in theme:
|
||||
colors=theme["colors"]
|
||||
window_colors=theme["window_colors"]
|
||||
for key1,value1 in window_colors.items():
|
||||
for key2,value2 in value1.items():
|
||||
if re.match("#.*",value2) == None:
|
||||
window_colors[key1][key2]=colors[value2]
|
||||
theme["window_colors"]=window_colors
|
||||
|
||||
bar_colors=theme["bar_colors"]
|
||||
for key1,value1 in bar_colors.items():
|
||||
if isinstance(value1,dict):
|
||||
for key2,value2 in value1.items():
|
||||
if re.match("#.*",value2) == None:
|
||||
bar_colors[key1][key2]=colors[value2]
|
||||
else:
|
||||
if re.match("#.*",value1) == None:
|
||||
bar_colors[key1]=colors[value1]
|
||||
theme["bar_colors"]=bar_colors
|
||||
return(theme)
|
||||
|
||||
def load(theme_file):
|
||||
f=open(theme_file,mode="r")
|
||||
theme=yaml.load(f,Loader=yaml.FullLoader)
|
||||
f.close()
|
||||
return(configure(theme))
|
Loading…
Add table
Add a link
Reference in a new issue