aboutsummaryrefslogtreecommitdiff
path: root/cusmodules/colors.py
blob: 295fbd4007f8ab9a10e9850fc824ca06f85d4b68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python
import os
import sys
import json
import wallpaper
from pathlib import Path
from random import randint
from subprocess import run

def random(colors):
    colorcount = len(colors) - 1
    ranint = randint(0, colorcount)
    rancol = colors[ranint]

    return rancol

def setColor(home, color_dir, choice, **kwargs):
    os.system(f'wal --theme {color_dir}/{choice}')

    with open(f"{home}/.cache/wal/colors.json", 'r') as f:
        data = json.load(f)

        top_color = data["colors"].get('color8')

        bottom_color = data["colors"].get('color6')

    wallpaper.gen_pylogo(top_color, bottom_color)

    try:
        if kwargs["norestart"] == True:
            return 0

    except:
        pass

    #run(['qtile', 'shell', '-c', 'restart()'])
    #run(['kill', '-SIGUSR1', os.popen('pidof qtile').read().strip('\n')])
    run(['qtile', 'shell', '-c', 'reload_config()'])
    run([f'{home}/.local/bin/pywalfox', 'update'])

    return 0

def main(argc, argv):
    home = str(Path.home())
    color_dir = f'{home}/.config/qtile/colors'

    try:
        if argv[0] == '-c':
            choice = argv[1]

        else:
            choice = os.popen(f'ls {color_dir} | dmenu -p "Color:"').read().strip("\n")

    except:
        choice = os.popen(f'ls {color_dir} | dmenu -p "Color:"').read().strip("\n")


    if "" == choice:
        return 0
    
    elif "random" in choice:
        colors = os.popen(f'ls {color_dir}').read().strip('\n').split('\n')
        choice = random(colors)

    else:
        pass

    setColor(home, color_dir, choice)

    return 0

if __name__ == '__main__': 
    sys.argv.pop(0)
    argc = int(len(sys.argv))

    try:
        argv = sys.argv

    except:
        argv = []

    main(argc, argv)