diff --git a/TODO.org b/TODO.org index aecc969..7af7a04 100644 --- a/TODO.org +++ b/TODO.org @@ -6,12 +6,15 @@ - [ ] Change src/theme.py name - [ ] Improve function/variables names -- YAML Theme Parser [0/1]: +- YAML Theme Parser [0/2]: - [ ] Improve yaml theme loader reliability + - [ ] Allow several metadata -- Theme applying algorithm [0/2]: +- Theme applying algorithm [0/3]: - [ ] Improve efficiency - [ ] Assume that theme to apply is well formated (checked in YAML Theme Parser) + - [ ] If there is no "colors" field in "bar" section, we still need to apply theme -- General [0/1]: +- General [1/2]: - [ ] Improve user API + - [X] Allow -r option (restart i3) diff --git a/src/i3-theme.py b/src/i3-theme.py index 2fae302..fa31b1d 100755 --- a/src/i3-theme.py +++ b/src/i3-theme.py @@ -1,15 +1,26 @@ #!/usr/bin/python -import parser, theme, os, argparse +import parser, theme, os, argparse, subprocess -args_parser = argparse.ArgumentParser(description='Process some integers.') -args_parser.add_argument('theme_path', metavar='theme', type=str, nargs='?', - help='YAML i3 theme path') +##### Utils Functions ##### +def log(title, content): print("\033[92m{}\033[00m: {}" .format(title,content)) +########################### + + +##### Parse Arguments ##### +args_parser = argparse.ArgumentParser(description='I3 Window Manager Colors Themer.') +args_parser.add_argument('theme_path', type=str, nargs='?', + help='I3 YAML theme path.') +args_parser.add_argument('-r', '--restart' ,action='store_true', help='Restart i3 after applying theme.') args = args_parser.parse_args() - +########################### ##### Apply Theme ##### loaded_theme=theme.load(args.theme_path) +for meta_key,meta_value in loaded_theme["meta"].items(): + log(meta_key.title(),meta_value) parser.apply_theme(os.environ["HOME"]+"/.config/i3/config",loaded_theme) - +if args.restart: + subprocess.Popen("i3-msg restart".split()) +####################### diff --git a/src/parser.py b/src/parser.py index 9a4f4b0..fdee9fc 100755 --- a/src/parser.py +++ b/src/parser.py @@ -65,7 +65,6 @@ def apply_to_config(tmp_config,theme): 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,config_file)