-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui10.py
146 lines (114 loc) · 4.54 KB
/
gui10.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
import tkinter.font as tkFont
import tkinter.ttk as ttk
from GetAllInformation import getProcessHeader, getProcessInfo
from tkinter import Tk, BOTTOM, BOTH, TOP, LEFT, RIGHT
import psutil
class Process(object):
"""use a ttk.TreeView as a multicolumn ListBox"""
def __init__(self, container):
self.container = container
self.tree = None
self._setup_widgets()
self._build_tree()
def _setup_widgets(self):
s = """\
click on header to sort by that column
to change width of column drag boundary
"""
# container = ttk.Frame(width=800, height=500)
#
# container.pack(fill='both', expand=True)
# create a treeview with dual scrollbars
self.tree = ttk.Treeview(columns=process_header, show="headings")
vsb = ttk.Scrollbar(orient="vertical",
command=self.tree.yview)
hsb = ttk.Scrollbar(orient="horizontal",
command=self.tree.xview)
self.tree.configure(yscrollcommand=vsb.set,
xscrollcommand=hsb.set)
self.tree.grid(column=0, row=0, sticky='nsew', in_=self.container)
vsb.grid(column=1, row=0, sticky='ns', in_=self.container)
hsb.grid(column=0, row=1, sticky='ew', in_=self.container)
self.container.grid_columnconfigure(0, weight=1)
self.container.grid_rowconfigure(0, weight=1)
def _build_tree(self):
for col in process_header:
self.tree.heading(col, text=col.title(),
command=lambda c=col: sortby(self.tree, c, 0))
# adjust the column's width to the header string
self.tree.column(col,
width=tkFont.Font().measure(col.title()))
for item in process_info:
self.tree.insert('', 'end', values=item)
# adjust column's width if necessary to fit each value
for ix, val in enumerate(item):
col_w = tkFont.Font().measure(val)
if self.tree.column(process_header[ix], width=None) < col_w:
self.tree.column(process_header[ix], width=col_w)
def sortby(tree, col, descending):
"""sort tree contents when a column header is clicked on"""
# grab values to sort
data = [(tree.set(child, col), child) \
for child in tree.get_children('')]
# if the data to be sorted is numeric change to float
# data = change_numeric(data)
# now sort the data in place
data.sort(reverse=descending)
for ix, item in enumerate(data):
tree.move(item[1], '', ix)
# switch the heading so it will sort in the opposite direction
tree.heading(col, command=lambda col=col: sortby(tree, col, \
int(not descending)))
class Resource(object):
def __init__(self, container):
pass
class FileSystem(object):
def __init__(self, container):
pass
# the Process Information data ...
process_header = getProcessHeader()#['Process Name', 'User', '% CPU', 'ID', 'Status']
# getting Information about the Process
process_info = getProcessInfo()
# for proc in psutil.process_iter(attrs=['pid', 'name', 'username']):
# list_info = list()
#
# p = psutil.Process(int(proc.info['pid']))
# list_info.append(proc.info['name'])
# list_info.append(proc.info['username'])
# list_info.append(p.cpu_percent())
# list_info.append(proc.info['pid'])
# list_info.append(p.status())
# process_info.append(tuple(list_info))
root = Tk()
root.minsize(width=900, height=400)
root.config(bg='white')
root.wm_title("System Monitor")
top = ttk.Frame(root)
processFrame = ttk.Frame(root)
resouresFrame = ttk.Frame(root)
filesystemFrame = ttk.Frame(root)
top.pack(side=TOP)
Process(processFrame)
Resource(resouresFrame)
FileSystem(filesystemFrame)
def ProcessDisplay():
processFrame.pack(side=BOTTOM, fill=BOTH, expand=True)
resouresFrame.pack_forget()
return
def ResourcesDisplay():
processFrame.pack_forget()
filesystemFrame.pack_forget()
resouresFrame.pack(side=BOTTOM, fill=BOTH, expand=True)
return
def FileSystemDisplay():
processFrame.pack_forget()
filesystemFrame.pack_forget()
root.destroy()
return
btn1 = ttk.Button(root, text="Process", command=ProcessDisplay)
btn2 = ttk.Button(root, text="Resources", command=ResourcesDisplay)
btn3 = ttk.Button(root, text="File System", command=FileSystemDisplay)
btn1.pack(in_=top, side=LEFT, pady=10)
btn2.pack(in_=top, side=LEFT, pady=10)
btn3.pack(in_=top, side=LEFT, pady=10)
root.mainloop()