-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayout.py
183 lines (162 loc) · 7.29 KB
/
layout.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
import PySimpleGUI as sg
import json
from os import path
import monitor
class Layout:
def __init__(self) -> None:
self.Load_Theme()
self.imagesPath = path.abspath(path.dirname(__file__)) + "/images"
self.cpuLayout = [
[
sg.Frame("", layout =
[
self.Component_Data_Layout("CPU", "-cpu-name-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Physical CPU Cores", "-cpu-cores-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Logical CPU Cores", "-logical-cpu-cores-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Base Frequency", "-cpu-base-frequency-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Architecture", "-cpu-architecture-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout_ProgressBar("CPU Usage", "-CPU-"),
],
size = (555, 232))
],
[
sg.Frame("", layout = [
self.Component_Data_Layout("OS", "-os-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("OS Version", "-os-version-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("System Uptime", "-UPTIME-")
],
size = (555, 232))]
]
self.GPU_Layout()
self.memoryLayout = [
[
sg.Frame("", layout = [
self.Component_Data_Layout("Total Installed Memory", "-total-memory-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Used Memory", "-USED-MEMORY-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Free Memory", "-FREE-MEMORY-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout_ProgressBar("Memory usage", "-MEMORY-")
],
size = (555, 464))
]
]
self.Storage_Layout()
self.Graph_Layout()
self.navigationLayout = [
self.Navigation_Button("CPU/System"),
self.Navigation_Button("Memory"),
self.Navigation_Button("GPU"),
self.Navigation_Button("Storage"),
self.Navigation_Button("Graphs")
]
self.mainLayout = [
sg.Column(self.cpuLayout, key = '-cpu-layout-', size = (600, 480)),
sg.Column(self.memoryLayout, key = "-memory-layout-", visible = False, size = (600, 480)),
sg.Column(self.gpuLayout, key = "-gpu-layout-", visible = False, size = (600, 480)),
sg.Column(self.storageLayout, key = "-storage-layout-", visible = False, size = (600, 480)),
sg.Column(self.graphsLayout, key = "-graphs-layout-", visible = False, size = (600, 480))
]
self.footerLayout = sg.Frame("",layout = [[
self.Footer_Button("{}/github.png".format(self.imagesPath), "-github-"),
self.Footer_Button("{}/settings.png".format(self.imagesPath), "-settings-"),
self.Footer_Button("{}/exit.png".format(self.imagesPath), "-exit-")
]],
size = (600, 50),
relief = "flat",
element_justification = "right")
self.layout = [
[self.navigationLayout],
[self.mainLayout],
[self.footerLayout]
]
def GPU_Layout(self):
gpu = monitor.GPU()
if gpu.gpu != "Unknown GPU":
self.gpuLayout = [
[
sg.Frame("", layout = [
self.Component_Data_Layout("GPU", "-gpu-name-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Total Memory", "-gpu-total-memory-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Used Memory", "-GPU-USED-MEMORY-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Free Memory", "-GPU-FREE-MEMORY-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout("Temperature", "-GPU-TEMPERATURE-")
],
size = (555, 232))
],
[
sg.Frame("",
layout = [
self.Component_Data_Layout_ProgressBar("Load", "-GPU-LOAD-"),
[sg.HorizontalSeparator()],
self.Component_Data_Layout_ProgressBar("Memory Usage", "-GPU-MEMORY-")],
size = (555, 232))
]
]
else:
self.gpuLayout = [
[
sg.Frame("",
layout= [
[sg.Text(gpu.gpu)]],
size=(555, 58),
element_justification="center")
]
]
def Storage_Layout(self):
Drives = monitor.Storage.get_drives()
layout = []
DriveNumber = 0
for drive in Drives:
layout.append(self.Component_Data_Layout("Drive", f"-drive{DriveNumber}-"))
layout.append(self.Component_Data_Layout("Total Storage Capacity", f"-drive{DriveNumber}-capacity-"))
layout.append(self.Component_Data_Layout("Used Storage", f"-USED-STORAGE{DriveNumber}-"))
layout.append(self.Component_Data_Layout("Free Storage", f"-FREE-STORAGE{DriveNumber}-" ))
layout.append([sg.HorizontalSeparator()])
DriveNumber += 1
layout.insert(0, self.Component_Data_Layout("Total Capacity(All Drives)", "-total-storage-"))
layout.insert(1, [sg.HorizontalSeparator()])
DriveNumber = 0
for drive in Drives:
layout.append(self.Component_Data_Layout_ProgressBar(f"{drive[0]} Drive Usage", f"-STORAGE-{DriveNumber}-"))
DriveNumber += 1
self.storageLayout = [[sg.Frame("", layout = layout, size = (555, 464))]]
def Load_Theme(self):
themefile = path.abspath(path.dirname(__file__)) + "/theme.json"
with open(themefile ,"r") as file:
self.theme = json.load(file)["theme"]
sg.theme(self.theme)
def Graph_Layout(self):
GRAPH_SIZE = (540, 200)
self.graphsLayout = [
[sg.Text("CPU usage graph")],
[sg.Push(), sg.Graph(GRAPH_SIZE, (0,0), GRAPH_SIZE, key = "-cpu-graph-", background_color=sg.theme_button_color_background()), sg.Push()],
[sg.HorizontalSeparator()],
[sg.Text("Memory usage graph")],
[sg.Push(), sg.Graph(GRAPH_SIZE, (0,0), GRAPH_SIZE, key = "-memory-graph-", background_color=sg.theme_button_color_background()), sg.Push()],
[sg.Text("60 seconds")]
]
@staticmethod
def Navigation_Button(Title):
return sg.Button(Title, size = (12,2), tooltip = Title, border_width = 0)
@staticmethod
def Footer_Button(ImageSource, Key):
return sg.B("", image_filename = ImageSource, image_size = (30, 30), border_width = 0, button_color= sg.theme_element_background_color(), mouseover_colors= sg.theme_element_background_color(), key = Key)
@staticmethod
def Component_Data_Layout(Title, Key):
return [sg.Text(Title), sg.Push(), sg.Text("", key = Key)]
@staticmethod
def Component_Data_Layout_ProgressBar(Title, Key):
return [sg.Text(Title), sg.Push(), sg.ProgressBar(max_value= 100, orientation = "h",size_px = (380, 20), key = Key + "BAR-"), sg.Text("", key = Key + "PERCENT-")]