-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallpaper
executable file
·153 lines (124 loc) · 4.49 KB
/
wallpaper
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
#!/usr/bin/env python3
import os
import glob
import locale
from time import sleep
WALLPAPERDIR = "/home/mitch/Pictures/bg"
ENABLEDDIR = "/home/mitch/Pictures/bg/__current"
# Ensure consistant sorting
locale.setlocale(locale.LC_COLLATE, "C")
class bcolors:
BOLD = '\033[1m'
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
ENDC = '\033[0m'
class Wallpaper:
path = ""
basename = ""
enabled = False
hidden = False
upgrade = False
old = False
def __init__(self, path):
self.path = path
self.dir = os.path.dirname(path)
self.basename = os.path.basename(path)
self.filename, self.fileext = os.path.splitext(self.basename)
if os.path.isfile(os.path.join(ENABLEDDIR, self.basename)):
self.enabled = True
if glob.glob(os.path.join(self.dir, self.filename + "_1080.*")) and not self.enabled:
self.hidden = True
if glob.glob(os.path.join(self.dir, self.filename + "_1440.*")) and not self.enabled:
self.hidden = True
if ("_1080" in self.filename) and glob.glob(os.path.join(self.dir, self.filename.replace("_1080", "_1440.*"))):
if self.enabled:
self.upgrade = True
else:
self.hidden = True
if ("_orig" in self.filename) and not self.enabled:
self.hidden = True
if ("_hide" in self.filename):
self.hidden = True
if ("old" in self.dir):
print(self.dir)
self.old = True
if not self.enabled:
self.hidden = True
def toggle(self):
target = os.path.join(ENABLEDDIR, self.basename)
if os.path.isfile(target):
os.remove(target)
self.enabled = False
print("Disabled", self.path)
else:
os.symlink(os.path.join("..", self.path), target)
self.enabled = True
print("Enabled", self.path)
sleep(0.25)
def print_line(self, number, pad):
print(bcolors.BOLD,
"{0: >{1}}. ".format(number, pad),
bcolors.GREEN if self.enabled else bcolors.BLUE,
bcolors.MAGENTA if self.upgrade else "",
"✓./" if self.enabled else " ./",
self.path, bcolors.ENDC, sep="")
def __lt__(self, other):
return locale.strcoll(self.path, other.path) < 0
def find_files(path):
out = []
os.chdir(path)
for file in glob.iglob("**/*.*", recursive=True):
if "__current" not in file and ".svg" not in file and ".tar" not in file:
out.append(Wallpaper(file))
return out
def make_display_list(wallpapers, mode="all"):
out = []
for w in wallpapers:
if mode == "eo" and not w.hidden and w.enabled:
out.append(w)
elif mode == "do" and not w.hidden and not w.enabled:
out.append(w)
elif mode == "all" and not w.hidden:
out.append(w)
elif mode == "old" and w.old and not w.hidden:
out.append(w)
return sorted(out)
def preview(wallpaper):
if isinstance(wallpaper, Wallpaper):
os.system("feh -. \"{}\"".format(wallpaper.path))
else:
os.system("feh -. " + " ".join(map(lambda x: "\"" + x.path + "\"", wallpaper)))
wallpapers = find_files(WALLPAPERDIR)
disp_list = make_display_list(wallpapers)
if __name__ == "__main__":
while True:
for i in range(0, len(disp_list)):
disp_list[i].print_line(i + 1, 3)
try:
selection = input("> ")
if selection == "all":
disp_list = make_display_list(wallpapers, mode="all")
elif selection == "eo":
disp_list = make_display_list(wallpapers, mode="eo")
elif selection == "do":
disp_list = make_display_list(wallpapers, mode="do")
elif selection == "old":
disp_list = make_display_list(wallpapers, mode="old")
elif selection == "q":
exit(0)
elif selection == "pa":
preview(disp_list)
elif selection[0] == 'p':
preview(disp_list[int(selection[1:]) - 1])
elif selection.isdigit():
disp_list[int(selection) - 1].toggle()
except KeyboardInterrupt:
exit(0)
except IndexError:
pass