-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.pyw
More file actions
109 lines (89 loc) · 2.62 KB
/
main.pyw
File metadata and controls
109 lines (89 loc) · 2.62 KB
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
# Modules:
import pygame, time, sys
# Classes:
from bar import Bar
from text import Text
# Preferences
window_title = "Progress Bar Counter"
window_size = width, height = (600, 200)
window_icon = pygame.image.load('./icons/countdown1.png')
window_color = (64,45,65, 50)
# Aplying preferences:
window = pygame.display.set_mode(window_size, pygame.SRCALPHA)
pygame.display.set_caption(window_title)
pygame.display.set_icon(window_icon)
# Creating new objects:
bar = Bar(window)
text = Text(window)
# Input of time:
hours_required = 0
minutes_required = 0
seconds_required = 45
# If has any argument in the CLI
if len(sys.argv) > 1:
# If the CLI argument was like:
# `progbar.py 25`, it is the seconds
if len(sys.argv) == 2:
hours_required = 0
minutes_required = 0
seconds_required = int(sys.argv[1])
# If the CLI argument was like:
# `progbar.py 1 25`, it is the minutes
# followed by the seconds
if len(sys.argv) == 3:
hours_required = 0
minutes_required = int(sys.argv[1])
seconds_required = int(sys.argv[2])
# If the CLI argument was like:
# `progbar.py 1 25 30`, it is the hours
# followed by the minutes, followed by
# the seconds
if len(sys.argv) == 4:
hours_required = int(sys.argv[1])
minutes_required = int(sys.argv[2])
seconds_required = int(sys.argv[3])
# Calc of total minutes:
minutes_in_total = (
(hours_required*60) +
(minutes_required) +
(seconds_required/60)
)
# Calc of seconds:
seconds_in_total = (
((hours_required*60)*60) +
(minutes_required*60) +
(seconds_required)
)
# Seting a while loop counter var:
c = 0
# Runtime:
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
# Fill the window:
window.fill(window_color)
# Divide the bar in pieces:
piece_of_the_bar = (
(width / (
(minutes_in_total * 60)) / bar.smoothness_of_bar
)
)
# Add that piece to the bar:
bar.draw(add_value=piece_of_the_bar)
# Define and draw the actual time to the screen:
text.define_what_to_write(
time.gmtime(seconds_in_total)[3:6]
)
text.draw()
# Down the seconds if one second has passed:
# case the smoothnes of bar == 1, add every loop
# and wait 1 second:
if c % bar.smoothness_of_bar == 0 and seconds_in_total > 0:
seconds_in_total -= 1
# If the smoothnes of bar == 1, the program waits 1 second,
# and the bar go second per second:
time.sleep(1/bar.smoothness_of_bar)
c += 1
pygame.display.update()