Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 72df290

Browse files
Add files via upload
1 parent 70ea0c1 commit 72df290

File tree

3 files changed

+105
-41
lines changed

3 files changed

+105
-41
lines changed

‎Pomodoro_GUI/Pomodoro_gui.py

Lines changed: 104 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,13 @@
77
pygame.mixer.init()
88
pomo_count = 0
99
break_count = 0
10+
enable = 0
1011

1112
# path of host file in windows
1213
host_path = r"C:\Windows\System32\drivers\etc\hosts"
1314

1415
# URL of websites to block
15-
block_list = [
16-
'www.facebook.com', 'facebook.com',
17-
'www.youtube.com', 'youtube.com',
18-
'www.gmail.com', 'gmail.com',
19-
'www.instagram.com', 'instagram.com',
20-
'www.twitter.com', 'twitter.com'
21-
]
16+
block_list = []
2217

2318
# redirecting above URLs to this localhost to ensure blocking
2419
redirect = "127.0.0.1"
@@ -29,7 +24,12 @@ def block_websites():
2924
the file if it is not already present and redirect it to the localhost
3025
for blocking
3126
"""
32-
27+
global web_var
28+
global enable
29+
global block_list
30+
global host_path
31+
url = web_var.get()
32+
block_list.append(url)
3333
try:
3434
# Opening the host file in reading and writing mode
3535
with open(host_path, 'r+') as h_file:
@@ -45,48 +45,103 @@ def block_websites():
4545
else:
4646
h_file.write(redirect + "\t" + website + "\n")
4747

48+
tk.messagebox.showinfo("Blocked", f"{url} successfully blocked!")
49+
enable = 1
50+
web_var.set("")
51+
4852
except PermissionError:
49-
tk.messagebox.showinfo("Error", "Run cmd in the admin mode and then try again!\nDeselect the option to prevent this popup to show again.")
53+
tk.messagebox.showinfo("Error", "Run cmd in the admin mode and then try again!")
54+
web_var.set("")
5055

5156
except (FileNotFoundError, NameError):
52-
tk.messagebox.showinfo("Error", "Functionality not supported in your OS!\nDeselect the option to prevent this popup to show again.")
57+
tk.messagebox.showinfo("Error", "Functionality not supported in your OS!")
58+
web_var.set("")
5359

5460

5561
def remove_websites():
5662
"""
5763
The function will unblock the block_list websites by opening the file
5864
and removing the changes we made before
5965
"""
66+
global block_list
67+
global host_path
6068
try:
61-
with open(host_path, "r+") as file:
62-
content = file.readlines()
63-
file.seek(0)
64-
for lines in content:
65-
if not any(website in lines for website in block_list):
66-
file.write(lines)
67-
file.truncate()
69+
if enable:
70+
# Opening the host file in reading and writing mode
71+
with open(host_path, "r+") as file:
72+
73+
# making each line of file into a list
74+
content = file.readlines()
75+
76+
# sets the file pointer at the beginning of the file
77+
file.seek(0)
78+
79+
# Traversing through each line of the host file and
80+
# checking for the websites to be blocked
81+
for lines in content:
82+
if not any(website in lines for website in block_list):
83+
file.write(lines)
84+
85+
# Truncating the file to its original size
86+
file.truncate()
87+
88+
block_list.clear()
89+
enable = 0
6890
except:
6991
pass
7092
finally:
7193
pass
7294

7395

74-
def high_focus():
96+
def blocker():
97+
"""
98+
The function asks input from user to block websites for high focus mode.
99+
"""
75100
global enable
76-
if enable.get() == 1:
77-
block_websites()
78-
else:
79-
remove_websites()
101+
global popup_4
102+
popup_4 = tk.Toplevel(root)
103+
popup_4.title("Website Blocker!")
104+
popup_4.geometry("360x220")
105+
popup_4.config( bg = 'DodgerBlue4')
106+
107+
global block_list
108+
global web_var
109+
web_var=tk.StringVar()
110+
111+
pass_label = tk.Label(popup_4, text = 'Enter URL to block:', font = ('Arial',12, 'bold'), bg = 'DodgerBlue4', fg = 'white')
112+
pass_entry = tk.Entry(popup_4, textvariable = web_var, font = ('Arial',12, 'bold'))
113+
114+
sub_btn = tk.Button(popup_4, text = 'Block', font = ('Arial',12, 'bold'), command = block_websites, bg='gold', activebackground='yellow')
115+
116+
text_to_put = '*Supported for windows ONLY\n*You can add multiple urls\n*Don\'t forget to unblock after'
117+
118+
instructions = tk.Label(popup_4, text = text_to_put, font = ('Arial',12, 'bold'), justify='left', bg = 'sky blue')
119+
120+
unblock_btn = tk.Button(popup_4, text = 'Unblock all', font = ('Arial',12, 'bold'), command = remove_websites, state='disabled', width = 23, height = 2, bg='gold', activebackground='yellow')
121+
122+
if enable:
123+
unblock_btn.config(state='normal')
124+
125+
pass_label.place(x=25, y=10)
126+
pass_entry.place(x=25, y=34)
127+
sub_btn.place(x=255, y=30)
128+
instructions.place(x=25, y=80)
129+
unblock_btn.place(x=50, y=150)
80130

81131

82132
def break_timer():
133+
"""
134+
5 min timer popup window acting as a callback function to the break timer button
135+
"""
136+
global enable
83137
global popup_2
84138
popup_2 = tk.Toplevel(root)
85139
popup_2.title("Break Timer!")
86140
popup_2.geometry("370x120")
87141
round = 0
88142

89143
try:
144+
# Creating a continous loop of text of time on the screen for 25 mins
90145
t = 5*60
91146
while t>-1:
92147
minute_count = t // 60
@@ -99,18 +154,22 @@ def break_timer():
99154
t -= 1
100155
except:
101156
pass
102-
103-
pygame.mixer.music.load("beep.wav")
104-
pygame.mixer.music.play(loops=0)
105-
157+
158+
# Setting up an alarm sound and popup window to let user know when the time is up
106159
if t == -1:
107160
tk.messagebox.showinfo("Time's up!", "Break is over!\nTime to get to work!")
108161
popup_2.destroy()
109162
global break_count
163+
pygame.mixer.music.load("./Pomodoro_GUI/beep.wav")
164+
pygame.mixer.music.play(loops=1)
110165
break_count += 1
111166

112167

113168
def show_report():
169+
"""
170+
The function acts as a callback for show report button and shows the report the hours
171+
of work they have put in.
172+
"""
114173
global popup_3
115174
popup_3 = tk.Toplevel(root)
116175
popup_3.title("Report")
@@ -126,13 +185,17 @@ def show_report():
126185

127186

128187
def pomodoro_timer():
188+
"""
189+
25 min timer popup window acting as a callback function to the work timer button
190+
"""
129191
global popup_1
130192
popup_1 = tk.Toplevel(root)
131193
popup_1.title("Work Timer!")
132194
popup_1.geometry("370x120")
133195
round = 0
134196

135197
try:
198+
# Creating a continous loop of text of time on the screen for 25 mins
136199
t = 25*60
137200
while t>-1:
138201
minute_count = t // 60
@@ -145,38 +208,39 @@ def pomodoro_timer():
145208
t -= 1
146209
except:
147210
pass
148-
149-
pygame.mixer.music.load("beep.wav")
150-
pygame.mixer.music.play(loops=1)
151-
211+
212+
# Setting up an alarm sound and popup window to let user know when the time is up
152213
if t == -1:
153214
tk.messagebox.showinfo("Time's up!", "Pomodoro completed successfully!\nYou deserve a break!")
154215
popup_1.destroy()
155216
global pomo_count
156217
pomo_count += 1
218+
pygame.mixer.music.load("./Pomodoro_GUI/beep.wav")
219+
pygame.mixer.music.play(loops=0)
157220

158221

159222
def main():
223+
"""
224+
This function produces the main screen of the Pomodoro timer with options to
225+
select the 25mins work timer, 5mins break timer, block websites for extra focus and
226+
another option to see the statistics of the time you've put in the work
227+
"""
228+
# Creating the root window (main screen)
160229
global root
161230
root = tk.Tk()
162231
root.title('Timer')
163232
root.geometry('470x608')
164233

165-
bg = tk.PhotoImage(file = "bg.png")
166-
167-
# Show image using label
234+
# Setting the screen background
235+
bg = tk.PhotoImage(file = "./Pomodoro_GUI/bg.png")
168236
label1 = tk.Label( root, image = bg)
169237
label1.place(x = 0, y = 0)
170238

171-
global count
172-
173239
intro1 = tk.Label(root, text = 'POMODORO TIMER', bg = 'snow', fg = 'maroon', font = ('Arial', 25, 'bold'))
174-
intro1.place(x=100, y=120)
240+
intro1.place(x=100, y=100)
175241

176-
global enable
177-
enable = tk.IntVar()
178-
check = tk.Checkbutton(root, text = 'Enable website blocker', variable = enable, font = ('Arial', 12, 'bold'), bg='gold', activebackground='yellow', height = 1, width = 25, onvalue=1, offvalue=0, command=high_focus)
179-
check.place(x=100, y=190)
242+
blocker_btn = tk.Button(root, text = 'WEBSITE BLOCKER', command = blocker, font = ('Arial', 12, 'bold'), bg='gold', activebackground='yellow', height = 3, width = 25)
243+
blocker_btn.place(x=100, y=150)
180244

181245
start_btn = tk.Button(root, text = 'START WORK TIMER', command = pomodoro_timer, font = ('Arial', 12, 'bold'), bg='gold', activebackground='yellow', height = 3, width = 25)
182246
start_btn.place(x=100, y=250)

‎Pomodoro_GUI/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
```
1717

1818
## Working:
19-
![GIF](https://media.giphy.com/media/Z8k8V5FRALLMLKsOpJ/giphy.gif)
19+
![GIF](https://media.giphy.com/media/rFugmcue93IERozmWw/giphy.gif)
2020

2121

2222
## Author:

‎Pomodoro_GUI/beep.wav

68.7 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /