aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2019-10-08 17:46:51 -0400
committerLoic Guegan <manzerbredes@mailbox.org>2019-10-08 17:46:51 -0400
commit7a50d7debab9ceda6d695670c7c0ea9bfc54cfff (patch)
treecc634d69f9736a28f283509dd1f186e33a4a4dd9
parent22494da413765d40a5c4ef4985024572307d22bc (diff)
Add support for random colors themes
-rwxr-xr-xsrc/i3-colors.py25
-rw-r--r--src/theme.py26
2 files changed, 41 insertions, 10 deletions
diff --git a/src/i3-colors.py b/src/i3-colors.py
index 0afafcd..f3e5834 100755
--- a/src/i3-colors.py
+++ b/src/i3-colors.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import config, theme, os, argparse, subprocess
+import config, theme, os, argparse, subprocess,sys
##### Utils Functions #####
def log(msg,title=""):
@@ -18,11 +18,15 @@ def apply(args):
if args.restart:
subprocess.Popen("i3-msg restart".split(),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#######################
-
+def aleatory(args):
+ t=theme.random_theme().as_dict()
+ config.apply(os.environ["HOME"]+"/.config/i3/config",t)
+ if args.restart:
+ subprocess.Popen("i3-msg restart".split(),stdout=subprocess.PIPE, stderr=subprocess.PIPE)
##### Extract Theme #####
def extract(args):
- theme=config.extract_theme(args.config_path)
- theme.dump()
+ t=config.extract_theme(args.config_path)
+ print(t.as_yaml())
#######################
##### Parse Arguments #####
@@ -39,6 +43,15 @@ argsExtractParser.add_argument('config_path', type=str, nargs='?',
help='Extract theme from config file.')
argsExtractParser.set_defaults(func=extract)
-args = argsMainParser.parse_args()
-args.func(args)
+argsAleatoryParser = argsSubParsers.add_parser("aleatory")
+argsAleatoryParser.add_argument('-r', '--restart' ,action='store_true', help='Restart i3 after applying theme.')
+argsAleatoryParser.set_defaults(func=aleatory)
+
+
+if __name__ == "__main__":
+ args = argsMainParser.parse_args()
+ if len(sys.argv)>1:
+ args.func(args)
+ else:
+ argsMainParser.print_help()
###########################
diff --git a/src/theme.py b/src/theme.py
index f18df35..30a9e34 100644
--- a/src/theme.py
+++ b/src/theme.py
@@ -1,4 +1,4 @@
-import yaml,re, sys
+import yaml,re, sys,random
def configure(theme):
"""
@@ -72,6 +72,7 @@ def load(theme_file):
validate(theme)
return(theme)
+
class ThemeBuilder:
def __init__(self):
self.theme={"meta": {"description": "Generated From i3-colors"},
@@ -80,9 +81,13 @@ class ThemeBuilder:
self.vars=list()
self.vars_values=dict()
- def dump(self):
- print(yaml.dump(self.theme))
+ def as_yaml(self):
+ return(yaml.dump(self.theme))
+
+ def as_dict(self):
+ return(self.theme)
+
def get(self,key):
if key in self.vars:
return(self.vars_values[key])
@@ -119,4 +124,17 @@ class ThemeBuilder:
self.vars.append(name)
self.vars_values[name]=value
-
+def random_theme():
+ r= lambda: "#"+hex(random.randint(0,16777214))[2:]
+ t=ThemeBuilder()
+ t.parse("client.focused {} {} {} {} {}".format(r(),r(),r(),r(),r()))
+ t.parse("client.unfocused {} {} {} {} {}".format(r(),r(),r(),r(),r()))
+ t.parse("client.urgent {} {} {} {} {}".format(r(),r(),r(),r(),r()))
+ t.parse("background {}".format(r()))
+ t.parse("statusline {}".format(r()))
+ t.parse("separator {}".format(r()))
+ t.parse("focused_workspace {} {} {}".format(r(),r(),r()))
+ t.parse("active_workspace {} {} {}".format(r(),r(),r()))
+ t.parse("inactive_workspace {} {} {}".format(r(),r(),r()))
+ t.parse("urgent_workspace {} {} {}".format(r(),r(),r()))
+ return(t)