Fixed flicker problem!!! Updated all of the PySimpleGUIWeb demos
This commit is contained in:
parent
f0e1642437
commit
a2443c63ad
14 changed files with 413 additions and 298 deletions
|
@ -1,6 +1,4 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
import sys
|
||||
import PySimpleGUIWeb as sg
|
||||
import psutil
|
||||
import time
|
||||
|
@ -26,6 +24,7 @@ g_cpu_percent = 0
|
|||
g_procs = None
|
||||
g_exit = False
|
||||
|
||||
|
||||
def CPU_thread(args):
|
||||
global g_interval, g_cpu_percent, g_procs, g_exit
|
||||
|
||||
|
@ -41,30 +40,30 @@ def main():
|
|||
global g_interval, g_procs, g_exit
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
sg.ChangeLookAndFeel('Black')
|
||||
layout = [[sg.Text('', size=(8,1), font=('Helvetica', 20),text_color=sg.YELLOWS[0],
|
||||
justification='center', key='text')],
|
||||
[sg.Text('', size=(30, 8), font=('Courier New', 12),text_color='white', justification='left', key='processes')],
|
||||
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0), size=(9,1)),]
|
||||
]
|
||||
sg.change_look_and_feel('Black')
|
||||
layout = [[sg.Text('', size=(8, 1), font=('Helvetica', 20), text_color=sg.YELLOWS[0],
|
||||
justification='center', key='text')],
|
||||
[sg.Text('', size=(30, 8), font=('Courier New', 12),
|
||||
text_color='white', justification='left', key='processes')],
|
||||
[sg.Exit(button_color=('white', 'firebrick4'),
|
||||
pad=((15, 0), 0), size=(9, 1)), ]
|
||||
]
|
||||
|
||||
window = sg.Window('CPU Utilization',
|
||||
no_titlebar=True,
|
||||
keep_on_top=True,
|
||||
alpha_channel=.8,
|
||||
grab_anywhere=True).Layout(layout)
|
||||
window = sg.Window('CPU Utilization', layout,
|
||||
no_titlebar=True, keep_on_top=True, alpha_channel=.8, grab_anywhere=True)
|
||||
|
||||
# start cpu measurement thread
|
||||
thread = Thread(target=CPU_thread,args=(None,), daemon=True)
|
||||
thread = Thread(target=CPU_thread, args=(None,), daemon=True)
|
||||
thread.start()
|
||||
timeout_value = 1 # make first read really quick
|
||||
g_interval = 1
|
||||
# ---------------- main loop ----------------
|
||||
while (True):
|
||||
while True:
|
||||
# --------- Read and update window --------
|
||||
event, values = window.Read(timeout=timeout_value, timeout_key='Timeout')
|
||||
event, values = window.read(
|
||||
timeout=timeout_value, timeout_key='Timeout')
|
||||
# --------- Do Button Operations --------
|
||||
if event is None or event == 'Exit':
|
||||
if event in (None, 'Exit'):
|
||||
break
|
||||
|
||||
timeout_value = 1000
|
||||
|
@ -74,11 +73,12 @@ def main():
|
|||
if g_procs:
|
||||
# --------- Create list of top % CPU porocesses --------
|
||||
try:
|
||||
top = {proc.name() : proc.cpu_percent() for proc in g_procs}
|
||||
except: pass
|
||||
top = {proc.name(): proc.cpu_percent() for proc in g_procs}
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
top_sorted = sorted(top.items(), key=operator.itemgetter(1), reverse=True)
|
||||
top_sorted = sorted(
|
||||
top.items(), key=operator.itemgetter(1), reverse=True)
|
||||
if top_sorted:
|
||||
top_sorted.pop(0)
|
||||
display_string = ''
|
||||
|
@ -86,10 +86,11 @@ def main():
|
|||
display_string += '{:2.2f} {}\n'.format(cpu/10, proc)
|
||||
|
||||
# --------- Display timer and proceses in window --------
|
||||
window.FindElement('text').Update('CPU {}'.format(cpu_percent))
|
||||
window.FindElement('processes').Update(display_string)
|
||||
window['text'].update('CPU {}'.format(cpu_percent))
|
||||
window['processes'].update(display_string)
|
||||
|
||||
window.close()
|
||||
|
||||
window.Close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue