Major update of all demo programs to use new PEP8 bindings, etc
This commit is contained in:
parent
3f7c87c562
commit
7f52778bcc
307 changed files with 19546 additions and 3297 deletions
|
@ -1,45 +1,41 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
|
||||
# Yet another usage of CPU data
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
sg.ChangeLookAndFeel('Black')
|
||||
sg.change_look_and_feel('Black')
|
||||
|
||||
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)], 3, key='_spin_')]]
|
||||
[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-')]]
|
||||
|
||||
# Layout the rows of the Window
|
||||
window = sg.Window('CPU Meter',
|
||||
layout,
|
||||
no_titlebar=True,
|
||||
keep_on_top=True,
|
||||
grab_anywhere=True).Layout(layout).Finalize()
|
||||
grab_anywhere=True, finalize=True)
|
||||
|
||||
# ---------------- main loop ----------------
|
||||
interval = 10 # For the first one, make it quick
|
||||
while (True):
|
||||
while True:
|
||||
# --------- Read and update window --------
|
||||
event, values = window.Read(timeout=interval)
|
||||
event, values = window.read(timeout=interval)
|
||||
# --------- Do Button Operations --------
|
||||
if event is None or event == 'Exit':
|
||||
if event in (None, 'Exit'):
|
||||
break
|
||||
|
||||
interval = int(values['_spin_'])*1000
|
||||
|
||||
|
||||
interval = int(values['-spin-'])*1000
|
||||
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
|
||||
# --------- Display timer in window --------
|
||||
|
||||
window.FindElement('_text_').Update(f'CPU {cpu_percent:02.0f}%')
|
||||
window['-text-'].update(f'CPU {cpu_percent:02.0f}%')
|
||||
|
||||
# Broke out of main loop. Close the window.
|
||||
window.CloseNonBlocking()
|
||||
window.CloseNonBlocking()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue