-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStyle.py
313 lines (233 loc) · 9.59 KB
/
Style.py
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
"""
This Program is used for making loadingbars,
and it can also make diffrent colors
like FAIL (red) or BLUE (blue)
mabye you have a part where the user waits a
specific amount of sek and to make it look
more alive you can use this as new output:
Loading: [####### ] 60%
or this:
50% [working]
"""
#imports:
import time
#extras:
#this part is googled becuse colors is complicated
Colors = {
"HEADER": '\033[95m',
"BLUE": '\033[94m',
"CYAN": '\033[96m',
"GREEN": '\033[92m',
"WARNING": '\033[93m',
"FAIL": '\033[91m',
"ENDC": '\033[0m',
"BOLD": '\033[1m',
"UNDERLINE": '\033[96m'
}
#defs:
#this is a spinning loadingbar
def loadingbar_spinning(sleep=float(0.1), times=int(3), text=str("Loading: ")):
"""
This is a loadingbar animation of a spinnign wheel
sleep: time delay before next character is printed
times: how many times the circle should spin around
text: set the text before loading
ends with two new lines, and the default color
"""
print(Colors["BOLD"] + text + " ", sep="", end="", flush=True)
for x in range(times):
for x in r"-\|/-\|/":
print("\b", Colors["FAIL"] + x, sep="", end="", flush=True)
time.sleep(sleep)
print("\b|", Colors["ENDC"] + "\n\n")
#this is a loadingbar line
def loadingbar_line(sleep=float(0.1), times=int(51), text=str("Loading: ")):
"""
This is a animation of a loadingbar line: ############
sleep: time delay before next character is printed
times: how many times to print "#"
text: set the text before loading
ends with two new lines, and the default color
"""
print(Colors["BOLD"] + text + " ", sep="", end="", flush=True)
for x in range(times):
print(Colors["FAIL"] + "#", sep="", end="", flush=True)
time.sleep(sleep)
print(Colors["ENDC"] + "\n\n")
#this is a other loadingbar line
def loadLineDL(sleep=float(0.1), text=str("Loading:")):
"""
This loadingbar will look something like this:
Loading: [##### ] 50%
this one will only count: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
sleep: time delay before next character is printed
text: set the text before loading, by default it has not space
this time you can not change amount of characters to print
it will always print "##" 10 times: ####################
ends with two new lines, and the default color
the name DL is for Download Line
"""
t = ""
space = " "
for x in range(10):
procent = x * 10
t = t + "##"
space = (space + "\b\b")
line = (t + space)
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + f"{procent}%", end="\r")
time.sleep(sleep)
#at the end print the hole line
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + "100%\n\n")
#this is a loadingbar line with download style, but this one can count 1 and 10
def loadLineDSE(sleep=float(0.1), text=str("Loading:")):
"""
This is almost like styles.loadingLineDL but this one can count with 1
sleep: time delay before next character is printed
text: text before loading, default look: Loading: [###### ] 60%
this loadingbar will load from 1 - 100%, it will have [##### ]
and a text displaying what "text" is set to
this function will exit with two new lines
"DSE" is for "Download Style Enter", dont really know what E is for yet
"""
#extras:
t = ""
space = " "
procent = 1
prev = 0
#loadingbar loop
for x in range(100):
#setting everything
procent = x
#this is set only when to aply more "###" to loadingbar line
if prev == 0:
prev = x
elif (x - prev) == 5:
t = t + "#"
space = (space + "\b")
prev = x
line = (t + space)
#printing the line and waiting for "sleep" amount of seconds
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + f"{procent}%", end="\r")
time.sleep(sleep)
#end
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + "100%\n\n")
#this is a loadingbar line with download style, but this one can count 1 and 10, and it uses "-"
def loadLineDSEL(sleep=float(0.1), text=str("Loading:")):
"""
This is almost like styles.loadLineDSE but this one uses "-" and not "#"
sleep: time delay before next character is printed
text: text before loading, default look: Loading: [------ ] 60%
this loadingbar will load from 1 - 100%, it will have [---- ]
and a text displaying what "text" is set to
this function will exit with two new lines
in case you wonder loadLineDSEL is not for Disel, it is for
"Loadingbar Line Download Style Enter Line" dont really know what E is for yet
"""
#extras:
t = ""
space = " "
procent = 1
prev = 0
#loadingbar loop
for x in range(100):
#setting everything
procent = x
#this is set only when to aply more "###" to loadingbar line
if prev == 0:
prev = x
elif (x - prev) == 5:
t = t + "-"
space = (space + "\b")
prev = x
line = (t + space)
#printing the line and waiting for "sleep" amount of seconds
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + f"{procent}%", end="\r")
time.sleep(sleep)
#end
print(Colors["BOLD"] + text, Colors["FAIL"] + f"[{line}]", Colors["ENDC"] + "100%\n\n")
#this will make a line with a spinningwheel
def lineSpinning(sleep=float(0.1), text=str("Loading:"), times=int(10)):
"""
This loadingbar will look like this-- Loading: ----------/
sleep: delay between next printing figure
text: the text that displays before loadingbar
times: the amount of times we gona print ---- and make a spinning animation
this will exit with two new lines, and will use colors that is not changeble
"""
print(Colors["BOLD"] + text + " ", sep="", end="", flush=True)
#start a loop
for x in range(times):
print("\b" + Colors["FAIL"] + "--", sep="", end="", flush=True)
for x in r"/-\|/-\|":
print("\b" + Colors["FAIL"] + x, sep="", end="", flush=True)
time.sleep(sleep)
time.sleep(sleep)
#end
print(Colors["ENDC"] + "\n\n")
#this will make a spinning wheel with % at the end
def lineSpinningP(sleep=float(0.1), text=str("Loading:")):
"""
This loadingbar will look like this-- Loading: ----------/ 100%
the P is for procent in lineSpinningP()
sleep: delay between next printing figure
text: the text that displays before loadingbar
Note: text don't need to end with space, this program add space
and sleep for the spinningwheel is 5 times faster than sleep time
so it is (sleep / 5)
this time you can't set time.
this will exit with two new lines, and will use colors that is not changeble
"""
#extras
lf = ""
prev = 0
#start a loop
procent = 0
for i in range(100):
#here we do some default things
procent = i
#make the end loading loop animation |/-\|/-\
for x in r"/-\|/-\|":
if prev == 0:
prev = i
elif(i - prev) == 5:
prev = i
lf = ("-" + (lf))
print(Colors["BOLD"] + text + " ", Colors["FAIL"] + lf + x + " ", Colors["ENDC"] + str(procent) + "%", "\r", sep="", end="", flush=True)
time.sleep(sleep / 5)
time.sleep(sleep)
#end
print(Colors["BOLD"] + text + " ", Colors["FAIL"] + lf + x, Colors["ENDC"] + "100%\n\n")
#this is a loadingbar that will let you pick colors and will look like this: 50% [working]
def loadingbarPFT(sleep=float(0.1), text=str("working"), loading_color=Colors["FAIL"], end_color=Colors["ENDC"], text_color=Colors["FAIL"]):
"""
This will be a custom loadingbar,
PFT = Procent First with Text
sleep: amount of delay before next procent
text: the display text, will be inside [ ]
loading_color: This will be the loadingbar color, default "FAIL"
end_color: This will be the exit color, default "ENDC"
text_color: This color will be the color of the text, default "FAIL"
Note: The Colors are recomended to be styles.Colors[color], if you have other
colors you can try, but it may give an error
and recomended color combines are:
text = BLUE
loading = FAIL (default) or WARNING
end = ENDC (default)
this one will print from 1% - 100%
it will look something like this: 50% [working]
this will end with 2 new lines
"""
for x in range(100):
if x < 10:
#here we set the space to 3
line = (str(x) + "%" + " " + text_color + f"[{text}]")
print(loading_color + line, "\r", sep="", end="", flush=True)
else:
#this will set the space from 3 to 2
line = (str(x) + "%" + " " + text_color + f"[{text}]")
print(loading_color + line, "\r", sep="", end="", flush=True)
#delay
time.sleep(sleep)
#end, it will end with space
print(loading_color + str(100) + "%", text_color + f" [{text}]")
print(end_color + "\n")