2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2018-09-28 18:57:37 +00:00
|
|
|
import sys
|
|
|
|
if sys.version_info[0] >= 3:
|
2018-09-27 20:24:09 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-28 18:57:37 +00:00
|
|
|
else:
|
|
|
|
import PySimpleGUI27 as sg
|
2018-09-27 20:24:09 +00:00
|
|
|
|
2018-09-21 00:42:40 +00:00
|
|
|
import psutil
|
|
|
|
|
|
|
|
# ---------------- Create Form ----------------
|
|
|
|
sg.ChangeLookAndFeel('Black')
|
2018-10-08 17:30:33 +00:00
|
|
|
|
|
|
|
layout = [[sg.Text('CPU Utilization')],
|
|
|
|
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='_text_')],
|
|
|
|
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0), size=(9,1)),
|
|
|
|
sg.Spin([x + 1 for x in range(10)], 1, key='_spin_')]]
|
|
|
|
|
|
|
|
# Layout the rows of the Window
|
|
|
|
window = sg.Window('CPU Meter',
|
|
|
|
no_titlebar=True,
|
|
|
|
keep_on_top=True,
|
|
|
|
grab_anywhere=True).Layout(layout)
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# ---------------- main loop ----------------
|
|
|
|
while (True):
|
|
|
|
# --------- Read and update window --------
|
2018-09-24 22:01:00 +00:00
|
|
|
button, values = window.ReadNonBlocking()
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# --------- Do Button Operations --------
|
|
|
|
if values is None or button == 'Exit':
|
|
|
|
break
|
|
|
|
try:
|
2018-10-08 17:30:33 +00:00
|
|
|
interval = int(values['_spin_'])
|
2018-09-21 00:42:40 +00:00
|
|
|
except:
|
|
|
|
interval = 1
|
|
|
|
|
|
|
|
cpu_percent = psutil.cpu_percent(interval=interval)
|
|
|
|
|
|
|
|
# --------- Display timer in window --------
|
|
|
|
|
2018-10-08 17:30:33 +00:00
|
|
|
window.FindElement('_text_').Update(f'CPU {cpu_percent:02.0f}%')
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# Broke out of main loop. Close the window.
|
2018-09-24 22:01:00 +00:00
|
|
|
window.CloseNonBlocking()
|