-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWifi_Speedtest.py
221 lines (161 loc) · 6.38 KB
/
Wifi_Speedtest.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
import win10toast
import speedtest
from tkinter import *
from tkinter.ttk import *
from PIL import Image, ImageTk
import urllib.request
global anim
anim = None
global window
window = None
global connected
connected = None
global result
result = None
st = speedtest.Speedtest()
global download
download = st.download()/1048576
global upload
upload = st.upload()/1048576
global ping
servernames =[]
names = st.get_servers(servernames)
ping = st.results.ping
data = [download,upload,ping]
formated_data = ['%.2f' % elem for elem in data]
global message
message = 'Download Speed: {}Mbps, \nUpload Speed: {}Mbps,\n Ping: {}ms'.format(*formated_data)
global flag
flag = 0
def network():
global flag
flag = 0
st = speedtest.Speedtest()
global download
download = st.download()/1048576
global upload
upload = st.upload()/1048576
global ping
servernames =[]
names = st.get_servers(servernames)
ping = st.results.ping
data = [download,upload,ping]
formated_data = ['%.2f' % elem for elem in data]
global message
message = 'Download Speed: {}Mbps, \nUpload Speed: {}Mbps,\n Ping: {}ms'.format(*formated_data)
try:
urllib.request.urlopen('https://google.com')
return True
except:
return False
class gif(Label):
def __init__(self, master, filename):
im = Image.open(filename)
seq = []
try:
while 1:
seq.append(im.copy())
im.seek(len(seq)) # skip to next frame
except EOFError:
pass # we're done
try:
self.delay = im.info['duration']
if self.delay > 2000:
self.delay = self.delay-2500
except KeyError:
self.delay = 100
first = seq[0].convert('RGBA')
self.frames = [ImageTk.PhotoImage(first)]
Label.__init__(self, master, image=self.frames[0])
temp = seq[0]
for image in seq[1:]:
temp.paste(image)
frame = temp.convert('RGBA')
self.frames.append(ImageTk.PhotoImage(frame))
self.idx = 0
self.cancel = self.after(self.delay, self.play)
def play(self):
self.config(image=self.frames[self.idx])
self.idx += 1
if self.idx == len(self.frames):
global flag
flag = 1
self.cancel = self.after(self.delay, self.play)
def restart():
global window
window = Tk()
window.title('SpeedTest')
window.wm_iconbitmap('speedtest_icon.ico')
window.geometry("600x400")
style = Style()
style.configure('TButton', font = ('calibri', 20, 'bold'), borderwidth = '4', background = 'deep sky blue')
style.map('TButton', foreground = [('active', '!disabled', 'green')], background = [('active', 'blue')])
def connect():
window.destroy()
global connected
connected = Tk()
connected.title('SpeedTest-Connected')
connected.wm_iconbitmap('speedtest_icon.ico')
connected.geometry("800x720")
style = Style()
style.configure('TButton', font = ('calibri', 20, 'bold'), borderwidth = '4', background = 'deep sky blue')
style.map('TButton', foreground = [('active', '!disabled', 'green')], background = [('active', 'blue')])
def resume():
global connected
connected.destroy()
global result
result = Tk()
result.title('SpeedTest-Connected-Results')
result.wm_iconbitmap('speedtest_icon.ico')
result.geometry("200x250")
global anim
anim = gif(result, 'pillow_imagedraw.gif')
anim.pack()
def results():
global download
global upload
global ping
global message
global result
result.destroy()
final = Tk()
final.title('SpeedTest-Connected-Results')
final.wm_iconbitmap('speedtest_icon.ico')
final.geometry("400x400")
L1 = Label(final, text="Download Speed:")
L1.grid(row=0,column=0,padx=10,pady=10)
L2 = Label(final, text="Upload Speed:")
L2.grid(row=1,column=0,padx=10,pady=10)
L3 = Label(final, text="Ping:")
L3.grid(row=2,column=0,padx=10,pady=10)
download_label= Label(final, text=download).grid(row=0,column=1,padx=10,pady=10)
upload_label = Label(final,text=upload).grid(row=1,column=1,padx=10,pady=10)
ping_label = Label(final,text=ping).grid(row=2,column=1,padx=10,pady=10)
if network():
toaster = win10toast.ToastNotifier()
toaster.show_toast('Wifi Speedtest Successfull!', message, icon_path = 'speedtest_icon.ico', duration=60)
else:
toaster = win10toast.ToastNotifier()
toaster.show_toast('Wifi Speedtest Failed!', 'Cannot connect to the internet\nPlease check your Internet Connection!!!', icon_2path = 'speedtest_icon.ico', duration=60)
button_click = Button(result, text='√ RESULTS √', command=results).pack(side=BOTTOM)
def disconnect():
def quit():
connected.destroy()
anim.after_cancel(anim.cancel)
button_quit = Button(connected, text='Quit', command=quit).pack()
button_res = Button(connected, text='Resume', command=resume).pack()
button_d = Button(connected, text='Disconnect', command=disconnect).pack()
button_r = Button(connected, text='Refresh', command=refresh).pack()
button_re = Button(connected, text='Result', command=resume).pack()
global anim
anim = gif(connected, 'connect_btn.gif')
anim.pack(side=TOP)
anim = gif(window, 'speedtest_start.gif')
anim.pack(side = TOP)
button_c = Button(window, text="Connect", command=connect).pack(side=BOTTOM)
window.mainloop()
if __name__ == '__main__':
def refresh():
connected.destroy()
restart()
restart()