aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2019-10-06 21:57:32 -0400
committerLoic Guegan <manzerbredes@mailbox.org>2019-10-06 21:57:32 -0400
commit602c70c5174b2c73600aa06fce915eaf8a1d8a26 (patch)
treee3b48b5a03cd57f0ff7c69d934b7ab9c335fb26e
parent3c72b332891c97e476e0f7470ac0262df20acc55 (diff)
First source files
-rwxr-xr-xsrc/i3-theme.py11
-rwxr-xr-xsrc/parser.py104
2 files changed, 115 insertions, 0 deletions
diff --git a/src/i3-theme.py b/src/i3-theme.py
new file mode 100755
index 0000000..2982726
--- /dev/null
+++ b/src/i3-theme.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+import parser
+
+
+
+
+print("Starting app...")
+
+parser.apply_theme("/home/loic/.config/i3/config",parser.theme)
+
+
diff --git a/src/parser.py b/src/parser.py
new file mode 100755
index 0000000..2ec8da3
--- /dev/null
+++ b/src/parser.py
@@ -0,0 +1,104 @@
+#!/usr/bin/python
+
+import re,tempfile,shutil
+
+theme_keys=["client.focused",
+ "client.focused_inactive",
+ "client.unfocused",
+ "client.urgent",
+ "separator",
+ "background",
+ "statusline",
+ "focused_workspace",
+ "active_workspace",
+ "inactive_workspace",
+ "urgent_workspace"]
+
+def contains(r,line):
+ return(re.match(r,line)!=None)
+
+def extract_config(config_file):
+ f=open(config_file,"r")
+ tmp=tempfile.NamedTemporaryFile(mode="w",delete=False)
+ for line in f:
+ is_theme_line=False
+ for key in theme_keys:
+ if contains(".*"+key+"\s",line):
+ is_theme_line=True
+ if not(is_theme_line):
+ tmp.write(line)
+
+ f.close()
+ tmp.close()
+ return(tmp.name)
+
+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"]
+ for line in f:
+ if contains(".*colors\s{",line):
+ tmp.write(line)
+ for key,value in bar_theme.items():
+ if not(isinstance(value,dict)):
+ tmp.write("\t"+key+" "+value+"\n")
+ else:
+ tmp.write("\t"+key+" "+value["border"]+" "+value["background"]+" "+value["text"]+"\n")
+ else:
+ tmp.write(line)
+ tmp.close()
+ f.close()
+ shutil.move(tmp.name,tmp_config)
+
+ ##### Apply client theme #####
+ client_theme=theme["client"]
+ 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.close()
+
+def apply_theme(config_file,theme):
+ tmp=extract_config(config_file)
+ apply_to_config(tmp,theme)
+ shutil.move(tmp,"/home/loic/aa.theme")
+
+
+
+theme={
+ "bar":{
+ "separator": "#666666",
+ "background": "#333333",
+ "statusline": "#bbbbbb",
+ "focused_workspace": { "border":"#888888",
+ "background": "#dddddd",
+ "text": "#222222"},
+ "active_workspace": { "border": "#333333",
+ "background": "#555555",
+ "text": "#bbbbbb"},
+ "inactive_workspace": { "border": "#333333",
+ "background": "#555555",
+ "text": "#bbbbbb"},
+ "urgent_workspace": { "border": "#2f343a",
+ "background": "#900000",
+ "text": "#ffffff"}},
+ "client": {
+ "client.focused": { "background": "#888888",
+ "text": "#dddddd",
+ "indicator": "#222222",
+ "child_border": "#2e9ef4"},
+ "client.focused_inactive": { "background": "#333333",
+ "text": "#555555",
+ "indicator": "#bbbbbb",
+ "child_border": "#484e50"},
+ "client.unfocused": { "background": "#333333",
+ "text": "#333333",
+ "indicator": "#888888",
+ "child_border": "#292d2e"},
+ "client.urgent": { "background": "#2f343a",
+ "text": "#900000",
+ "indicator": "#ffffff",
+ "child_border": "#900000"}}
+}
+