9
9
import tkinter as tk
10
10
from tkinter import simpledialog
11
11
12
- # تنظیم فونت پیشفرض برای matplotlib به Tahoma
13
12
rcParams ['font.family' ] = 'Tahoma'
14
13
rcParams ['font.size' ] = 12
15
14
16
- # تابع برای دریافت IPها از کاربر با استفاده از یک پنجره گرافیکی
17
15
def get_ips ():
18
16
root = tk .Tk ()
19
17
root .withdraw () # مخفی کردن پنجره اصلی
@@ -23,13 +21,11 @@ def get_ips():
23
21
else :
24
22
return []
25
23
26
- # دریافت IPها از کاربر
27
24
ips = get_ips ()
28
25
if not ips :
29
26
print ("هیچ IP وارد نشد. برنامه خاتمه یافت." )
30
27
exit (1 )
31
28
32
- # تابع برای پینگ کردن IPها
33
29
def ping_ips ():
34
30
while True :
35
31
responses = []
@@ -44,12 +40,10 @@ def ping_ips():
44
40
ping_results .pop (0 )
45
41
time .sleep (1 )
46
42
47
- # تنظیمات اولیه برای نمودار
48
43
fig , ax = plt .subplots ()
49
44
ping_results = []
50
45
max_display_time = 100 # حداکثر تعداد نقاط زمانی که در نمودار نمایش داده میشود
51
46
52
- # تابع برای بهروزرسانی نمودار
53
47
def update_graph (i ):
54
48
ax .clear ()
55
49
# استفاده از arabic_reshaper و bidi برای پشتیبانی از حروف فارسی و عربی
@@ -69,17 +63,13 @@ def update_graph(i):
69
63
ax .set_xlim (left = max (0 , len (ping_results ) - max_display_time ), right = len (ping_results ))
70
64
ax .set_ylim (- 0.1 , 1.1 )
71
65
72
- # تنظیم فونت و استفاده از arabic_reshaper و bidi برای برچسبها
73
66
labels = [get_display (arabic_reshaper .reshape (ip )) for ip in ips ]
74
67
ax .legend (labels = labels , prop = {'family' : 'Tahoma' }, loc = 'upper right' )
75
68
76
- # شروع پینگ کردن IPها در یک ترد جداگانه
77
69
ping_thread = threading .Thread (target = ping_ips )
78
70
ping_thread .daemon = True
79
71
ping_thread .start ()
80
72
81
- # شروع رسم نمودار به صورت پویا
82
73
ani = animation .FuncAnimation (fig , update_graph , interval = 500 , save_count = 100 , cache_frame_data = False )
83
74
84
- # نمایش نمودار به صورت زنده
85
75
plt .show ()
0 commit comments