- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
Latest commit
104 lines (90 loc) · 4.03 KB
/
Copy pathmain.py
File metadata and controls
104 lines (90 loc) · 4.03 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
fromtkinterimport*
fromtkinterimportttk
frommatplotlib.figureimportFigure
frommatplotlib.backends.backend_tkaggimportFigureCanvasTkAgg
importnumpyasnp
importpsutil
importpygetwindowasgw
defbutton_action():
print("Button pressed!")
# Get all network connections
deflist_process_network_info(process_name):
connections=psutil.net_connections(kind='inet')
connection_details= []
# First, find the PIDs associated with the given process name
target_pids= {p.pidforpinpsutil.process_iter(['pid', 'name']) ifp.info['name'] ==process_name}
# Now filter and collect details of connections that belong to these PIDs
forconninconnections:
ifconn.pidintarget_pids:
local_address=f"{conn.laddr.ip}:{conn.laddr.port}"ifconn.laddrelse"N/A"
remote_address=f"{conn.raddr.ip}:{conn.raddr.port}"ifconn.raddrelse"N/A"
connection_details.append({
'Status': conn.status
})
returnconnection_detailsifconnection_detailselsef"N/A"
app_names=set()
deflist_background_processes():
forprocessinpsutil.process_iter(['pid', 'name', 'username']):
try:
withprocess.oneshot():
pid=process.pid
name=process.name()
#cpu_usage = process.cpu_percent(interval=1.0)
memory_info=process.memory_full_info()
memory_usage=memory_info.uss
memory_usage=memory_info.uss
memory_usage_final=memory_usage/1024**2
Network=list_process_network_info(name)
app_names.add((name,1,str(memory_usage_final) +" MB",str(Network)))
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
list_background_processes()
defsetup_treeview():
# Define columns
columns= ('Name', 'CPU', 'Disk','Network')
tree['columns'] =columns
tree.heading('#0', text='ID', anchor=W)
forcolincolumns:
tree.heading(col, text=col.capitalize(), anchor=W)
tree.column(col, width=100, anchor=W) # Column headers
# Define column widths and alignments
tree.column('#0', width=40, anchor=W) # The first column for IDs
tree.column('Name', width=100, anchor=W)
tree.column('CPU', width=100, anchor=W)
tree.column('Disk', width=100, anchor=W)
tree.column('Network', width=100, anchor=W)
# Insert data
data= []
forrowsinapp_names:
data.append(rows)
foridx, (Name, CPU, Disk, Network) inenumerate(data, 1):
tree.insert("", 'end', iid=str(idx), text=str(idx), values=(Name, CPU, Disk, Network))
window=Tk()
window.title("Python Task Manager")
window.geometry("700x700")
window.configure(bg="black")
side_panel=Frame(window, bg='gray', width=100, height=300, borderwidth=2, relief=SUNKEN)
side_panel.pack(side=LEFT, fill=Y)
Processes=Button(side_panel, text="Processes", command=button_action)
Processes.pack(pady=10, padx=10, fill=X)
Performance=Button(side_panel, text="Performance", command=button_action)
Performance.pack(pady=10, padx=10, fill=X)
History=Button(side_panel, text="App History", command=button_action)
History.pack(pady=10, padx=10, fill=X)
Startup=Button(side_panel, text="Startup Apps", command=button_action)
Startup.pack(pady=10, padx=10, fill=X)
Users=Button(side_panel, text="Users", command=button_action)
Users.pack(pady=10, padx=10, fill=X)
Details=Button(side_panel, text="Details", command=button_action)
Details.pack(pady=10, padx=10, fill=X)
Services=Button(side_panel, text="Services", command=button_action)
Services.pack(pady=10, padx=10, fill=X)
Font_tuple= ("Comic Sans", 10, "bold")
label=Label(window, text="Python Task Manager")
label.configure(font=Font_tuple, bg="black", fg="white")
label.pack()
tree=ttk.Treeview(window)
setup_treeview()
tree.pack(padx=10, pady=10, fill=BOTH, expand=True)
window.mainloop()
window.mainloop()