-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyrice
executable file
·176 lines (151 loc) · 5.23 KB
/
pyrice
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env python
import subprocess
import argparse
import random
import os
from pathlib import Path
import psutil
import shutil
import time
import json
# Set up the argument parser
parser = argparse.ArgumentParser(
prog = "pyrice",
description = "Wrapper of pywal and wpgtk"
)
parser.add_argument(
"--backend",
nargs = "?",
default = "haishoku",
help = "Backend to use (default: haishoku)"
)
parser.add_argument(
"-t",
"--time",
action = "store_false",
help = "Disable time based theme checking"
)
parser.add_argument(
"-l",
"--light",
action = "store_true",
help = "Use light theme"
)
parser.add_argument(
"wallpaper_path",
nargs = "?",
help = "Path to the wallpaper image"
)
parser.add_argument(
"--old",
action = "store_true",
help = "Use the current/old wallpaper"
)
args = parser.parse_args()
if args.time:
current_hour = time.localtime()[3]
if current_hour >= 8 and current_hour < 16:
args.light = True
def get_recursive_files(directory):
"Returns a list of all files names from a directory recursively."
files = []
for root, dirs, filenames in os.walk(directory):
for filename in filenames:
files.append(os.path.join(root, filename))
return files
def wallpaper_path_get(path = args.wallpaper_path):
if Path(str(path)).is_dir() is True:
return random.choice(get_recursive_files(path))
elif path is not None:
return os.path.realpath(path)
else:
return random.choice(get_recursive_files(os.environ["HOME"] + "/Pictures/bg"))
if args.old:
path = open(os.environ["XDG_CACHE_HOME"] + "/wal/wal").read()
else:
path = wallpaper_path_get()
def pywal_run():
wpg_args = ["wpg", "--noreload", "--backend", args.backend, "-ns", path]
wal_args = ["wal", "--cols16", "--backend", args.backend, "-nei", path]
if args.light:
wpg_args += ["-L"]
wal_args += ["-l"]
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.interface", "icon-theme",
"Papirus-Light"])
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme",
"prefer-light"])
else:
wal_args += ["-b", "#000000"]
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.interface", "icon-theme",
"Papirus-Dark"])
subprocess.Popen(["gsettings", "set", "org.gnome.desktop.interface", "color-scheme",
"prefer-dark"])
subprocess.run(wpg_args)
subprocess.run(wal_args)
def gradience_wrap():
path_exists = os.path.exists(os.environ["XDG_CONFIG_HOME"] + "/presets/user")
if path_exists == False:
os.mkdir(os.environ["XDG_CONFIG_HOME"] + "/presets/user")
shutil.copyfile(os.environ["XDG_CACHE_HOME"] + "/wal/pywal.json",
os.environ["XDG_CONFIG_HOME"] + "/presets/user/pywal.json")
subprocess.Popen(["gradience-cli", "apply", "-n", "pywal", "--gtk", "gtk4"])
def afterwards():
# swaybg setup and waybar
waybarp = False
emacsp = False
swaybgp = False
for proc in psutil.process_iter(attrs=["pid", "name"]):
if proc.info["name"] == "swaybg":
if args.old != True:
pid = proc.info["pid"]
psutil.Process(pid).terminate() # Terminate the process
else:
swaybgp = True
elif proc.info["name"] == "waybar":
waybarp = True
elif proc.info["name"] == "emacs":
emacsp = True
elif proc.info["name"] == "sway":
swayp = True
# sway
if swayp:
colors = json.loads(open(os.environ["XDG_CACHE_HOME"] + "/wal/colors.json").read())
background = colors["special"]["background"]
foreground = colors["special"]["foreground"]
subprocess.Popen(["swaymsg", "client.focused", background,
colors["colors"]["color11"], foreground])
subprocess.Popen(["swaymsg", "client.focused_inactive",
background, background, foreground])
subprocess.Popen(["swaymsg", "client.unfocused", background,
background, foreground])
subprocess.Popen(["swaymsg", "client.urgent", background,
background, foreground])
subprocess.Popen(["swaymsg", "client.placeholder", background,
background, foreground])
# subprocess.run(["swaymsg", "output", "*", "bg", background, "solid_color"])
if args.old == False or swaybgp == False:
subprocess.Popen(["swaybg", "-m", "fit", "-i", path]) # Popen is async
if waybarp == False:
subprocess.Popen(["waybar"])
# reloading waybar css
# touch isn't enough for waybar to reload css, so
# I add new line to the css file and delete it
waybar_file = os.environ["XDG_CONFIG_HOME"] + "/waybar/style.css"
subprocess.run(["sed", "-i", "1i\\\\", waybar_file])
subprocess.run(["sed", "-i", "1d", waybar_file])
# swaync
subprocess.Popen(["swaync-client", "-rs"])
# emacs
if emacsp:
if args.light == True:
subprocess.run(["emacsclient", "-e",
"(setq ewal-doom-one-brighter-comments t " +
"ewal-doom-one-comment-bg nil)"])
else:
subprocess.run(["emacsclient", "-e",
"(setq ewal-doom-one-brighter-comments nil)"])
subprocess.Popen(["emacsclient", "-e", "(load-theme 'ewal-doom-one t)"])
subprocess.Popen(["notify-send", "New rice applied"])
gradience_wrap()
pywal_run()
afterwards()