-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcpumon.py
More file actions
executable file
·45 lines (35 loc) · 1.02 KB
/
Copy pathcpumon.py
File metadata and controls
executable file
·45 lines (35 loc) · 1.02 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
#!/usr/bin/env python
# CPU usage monitor
import pygame, psutil
BLUE = 0, 85, 170
ORANGE = 255, 136, 0
class CPUMon:
def __init__(s):
pygame.init()
s.res = 200, 100
s.screen = pygame.display.set_mode(s.res)
pygame.display.set_caption('cpumon')
s.screen.fill(BLUE)
s.clock = pygame.time.Clock()
def events(s):
for event in pygame.event.get():
if event.type == pygame.QUIT: s.running = False
def run(s):
s.running = True
while s.running:
s.clock.tick(4)
s.events()
s.update()
pygame.quit()
def update(s):
cpu = int(psutil.cpu_percent(interval=None))
s.screen.scroll(dx = -1)
pygame.draw.line(s.screen, BLUE,
((s.res[0]-1), s.res[1]-1),
((s.res[0]-1), 0), 1)
pygame.draw.line(s.screen, ORANGE,
((s.res[0]-1), s.res[1]-1),
((s.res[0]-1), s.res[1]-cpu), 1)
pygame.display.flip()
c = CPUMon()
c.run()