2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-21 00:42:40 +00:00
|
|
|
import psutil
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
# Yet another usage of CPU data
|
|
|
|
|
2018-09-21 00:42:40 +00:00
|
|
|
# ---------------- Create Form ----------------
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Black')
|
2018-10-08 17:30:33 +00:00
|
|
|
|
|
|
|
layout = [[sg.Text('CPU Utilization')],
|
2019-10-23 20:10:03 +00:00
|
|
|
[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)], 3, key='-spin-')]]
|
2018-10-08 17:30:33 +00:00
|
|
|
|
|
|
|
# Layout the rows of the Window
|
|
|
|
window = sg.Window('CPU Meter',
|
2019-10-23 20:10:03 +00:00
|
|
|
layout,
|
2018-10-08 17:30:33 +00:00
|
|
|
no_titlebar=True,
|
|
|
|
keep_on_top=True,
|
2019-10-23 20:10:03 +00:00
|
|
|
grab_anywhere=True, finalize=True)
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# ---------------- main loop ----------------
|
2018-10-18 18:56:08 +00:00
|
|
|
interval = 10 # For the first one, make it quick
|
2019-10-23 20:10:03 +00:00
|
|
|
while True:
|
2018-09-21 00:42:40 +00:00
|
|
|
# --------- Read and update window --------
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read(timeout=interval)
|
2018-09-21 00:42:40 +00:00
|
|
|
# --------- Do Button Operations --------
|
2020-05-07 10:22:59 +00:00
|
|
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
2018-09-21 00:42:40 +00:00
|
|
|
break
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
interval = int(values['-spin-'])*1000
|
2018-10-18 18:56:08 +00:00
|
|
|
|
|
|
|
cpu_percent = psutil.cpu_percent(interval=1)
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# --------- Display timer in window --------
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window['-text-'].update(f'CPU {cpu_percent:02.0f}%')
|
2018-09-21 00:42:40 +00:00
|
|
|
|
|
|
|
# Broke out of main loop. Close the window.
|
2020-05-07 10:22:59 +00:00
|
|
|
window.close()
|