NEW Demos - Floating CPU utlization widget, Compound element - Spinner, refresh of the other Demos
This commit is contained in:
parent
18584aa533
commit
57396f3dc1
|
@ -682,7 +682,7 @@ def InputElementUpdate():
|
|||
keys_entered += button # add the new digit
|
||||
elif button is 'Submit':
|
||||
keys_entered = values['input']
|
||||
form.FindElement('outpput').Update(keys_entered) # output the final string
|
||||
form.FindElement('output').Update(keys_entered) # output the final string
|
||||
|
||||
form.FindElement('input').Update(keys_entered) # change the form to reflect current key string
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
import PySimpleGUI as sg
|
||||
import time
|
||||
import psutil
|
||||
|
||||
"""
|
||||
PSUTIL Desktop Widget
|
||||
Creates a floating CPU utilization window that is always on top of other windows
|
||||
You move it by grabbing anywhere on the window
|
||||
Good example of how to do a non-blocking, polling program using PySimpleGUI
|
||||
Use the spinner to adjust the number of seconds between readings of the CPU utilizaiton
|
||||
|
||||
NOTE - you will get a warning message printed when you exit using exit button.
|
||||
It will look something like:
|
||||
invalid command name "1616802625480StopMove"
|
||||
"""
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
sg.ChangeLookAndFeel('Black')
|
||||
form_rows = [[sg.Text('')],
|
||||
[sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center', key='text')],
|
||||
[sg.Exit(button_color=('white', 'firebrick4'), pad=((15,0), 0)), sg.Spin([x+1 for x in range(10)], 1, key='spin')]]
|
||||
# Layout the rows of the form and perform a read. Indicate the form is non-blocking!
|
||||
form = sg.FlexForm('Running Timer', no_titlebar=True, auto_size_buttons=False, keep_on_top=True, grab_anywhere=True)
|
||||
form.Layout(form_rows)
|
||||
|
||||
# ---------------- main loop ----------------
|
||||
while (True):
|
||||
# --------- Read and update window --------
|
||||
button, values = form.ReadNonBlocking()
|
||||
|
||||
# --------- Do Button Operations --------
|
||||
if values is None or button == 'Exit':
|
||||
break
|
||||
try:
|
||||
interval = int(values['spin'])
|
||||
except:
|
||||
interval = 1
|
||||
|
||||
cpu_percent = psutil.cpu_percent(interval=interval)
|
||||
|
||||
# --------- Display timer in window --------
|
||||
|
||||
form.FindElement('text').Update(f'CPU {cpu_percent:02.0f}%')
|
||||
|
||||
|
||||
# --------- After loop --------
|
||||
|
||||
# Broke out of main loop. Close the window.
|
||||
form.CloseNonBlockingForm()
|
|
@ -26,6 +26,20 @@ form = sg.FlexForm("Time Tracker", default_element_size=(12, 1), text_justificat
|
|||
|
||||
form.Layout(layout)
|
||||
|
||||
form.ReadNonBlocking()
|
||||
|
||||
form.FindElement('cbox').Update(disabled=True)
|
||||
form.FindElement('listbox').Update(disabled=True)
|
||||
form.FindElement('radio1').Update(disabled=True)
|
||||
form.FindElement('radio2').Update(disabled=True)
|
||||
form.FindElement('spin').Update(disabled=True)
|
||||
form.FindElement('option').Update(disabled=True)
|
||||
form.FindElement('combo').Update(disabled=True)
|
||||
form.FindElement('reset').Update(disabled=True)
|
||||
form.FindElement('notes').Update(disabled=True)
|
||||
form.FindElement('multi').Update(disabled=True)
|
||||
form.FindElement('slider').Update(disabled=True)
|
||||
|
||||
while True:
|
||||
button, values = form.Read()
|
||||
if button is None or button == 'Exit':
|
||||
|
|
|
@ -35,7 +35,7 @@ def Everything():
|
|||
sg.Text(' ' * 40), sg.ReadFormButton('SaveSettings'), sg.ReadFormButton('LoadSettings')]
|
||||
]
|
||||
|
||||
form = sg.FlexForm('Form Fill Demonstration', default_element_size=(40, 1))
|
||||
form = sg.FlexForm('Form Fill Demonstration', default_element_size=(40, 1), grab_anywhere=False)
|
||||
# button, values = form.LayoutAndRead(layout, non_blocking=True)
|
||||
form.Layout(layout)
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ def main():
|
|||
[sg.ReadFormButton('Exit', size=(10, 2), pad=((600, 0), 3), font='Helvetica 14')]]
|
||||
|
||||
# create the form and show it without the plot
|
||||
form = sg.FlexForm('Demo Application - Embedding Matplotlib In PySimpleGUI', no_titlebar=True, location=(0,0))
|
||||
form = sg.FlexForm('Demo Application - OpenCV Integration', no_titlebar=False, location=(0,0))
|
||||
form.Layout(layout)
|
||||
form.ReadNonBlocking()
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ GPIO.setup(14, GPIO.OUT)
|
|||
|
||||
def SwitchLED():
|
||||
varLEDStatus = GPIO.input(14)
|
||||
|
||||
if varLEDStatus == 0:
|
||||
varLedStatus = 0
|
||||
if varLedStatus == 0:
|
||||
GPIO.output(14, GPIO.HIGH)
|
||||
return "LED is switched ON"
|
||||
else:
|
||||
|
@ -28,32 +28,27 @@ def FlashLED():
|
|||
GPIO.output(14, GPIO.LOW)
|
||||
time.sleep(0.5)
|
||||
|
||||
results_elem = rg.T('', size=(30, 1))
|
||||
|
||||
layout = [[rg.T('Raspberry Pi LEDs')],
|
||||
[results_elem],
|
||||
[rg.T('', size=(14, 1), key='output')],
|
||||
[rg.ReadFormButton('Switch LED')],
|
||||
[rg.ReadFormButton('Flash LED')],
|
||||
[rg.ReadFormButton('Show slider value')],
|
||||
[rg.Slider(range=(0, 100), default_value=0, orientation='h', size=(40, 20), key='slider')],
|
||||
[rg.Exit()]
|
||||
]
|
||||
|
||||
form = rg.FlexForm('Raspberry Pi GUI')
|
||||
form = rg.FlexForm('Raspberry Pi GUI', grab_anywhere=False)
|
||||
form.Layout(layout)
|
||||
|
||||
while True:
|
||||
button, values = form.Read()
|
||||
if button is None:
|
||||
break
|
||||
|
||||
if button is 'Switch LED':
|
||||
results_elem.Update(SwitchLED())
|
||||
form.FindElement('output').Update(SwitchLED())
|
||||
elif button is 'Flash LED':
|
||||
results_elem.Update('LED is Flashing')
|
||||
form.FindElement('output').Update('LED is Flashing')
|
||||
form.ReadNonBlocking()
|
||||
FlashLED()
|
||||
results_elem.Update('')
|
||||
elif button is 'Show slider value':
|
||||
results_elem.Update('Slider = %s'%values['slider'])
|
||||
form.FindElement('output').Update('')
|
||||
|
||||
rg.MsgBox('Done... exiting')
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import PySimpleGUI as sg
|
||||
|
||||
"""
|
||||
Demo of how to combine elements into your own custom element
|
||||
"""
|
||||
|
||||
sg.SetOptions(element_padding=(0,0))
|
||||
sg.ChangeLookAndFeel('Dark')
|
||||
# --- Define our "Big-Button-Spinner" compound element. Has 2 buttons and an input field --- #
|
||||
NewSpinner = [sg.ReadFormButton('-', size=(4,1), font='Any 12'),
|
||||
sg.In('0', size=(5,1), font='Any 14', justification='r', key='spin'),
|
||||
sg.ReadFormButton('+', size=(4,1), font='Any 12')]
|
||||
# --- Define Window --- #
|
||||
layout = [
|
||||
[sg.Text('Spinner simulation')],
|
||||
NewSpinner,
|
||||
[sg.T('')],
|
||||
[sg.Ok()]
|
||||
]
|
||||
|
||||
form = sg.FlexForm('Spinner simulation')
|
||||
form.Layout(layout)
|
||||
|
||||
# --- Event Loop --- #
|
||||
counter = 0
|
||||
while True:
|
||||
button, value = form.Read()
|
||||
|
||||
if button == 'Ok' or button is None: # be nice to your user, always have an exit from your form
|
||||
break
|
||||
|
||||
# --- do spinner stuff --- #
|
||||
counter += 1 if button =='+' else -1 if button == '-' else 0
|
||||
form.FindElement('spin').Update(counter)
|
|
@ -25,7 +25,7 @@ def TableSimulation():
|
|||
sg.In(key='inputrow', justification='right', size=(8,1), pad=(1,1), do_not_clear=True),
|
||||
sg.In(key='inputcol', size=(8,1), pad=(1,1), justification='right', do_not_clear=True),
|
||||
sg.In(key='value', size=(8,1), pad=(1,1), justification='right', do_not_clear=True)],
|
||||
[sg.Column(columm_layout, size=(815,600), scrollable=True)]]
|
||||
[sg.Column(columm_layout, size=(800,600), scrollable=True)]]
|
||||
|
||||
form = sg.FlexForm('Table', return_keyboard_events=True, grab_anywhere=False)
|
||||
form.Layout(layout)
|
||||
|
|
Loading…
Reference in New Issue