LOTS of changes and new additions
Text justification for Text Elems NEW Image Element OutputFlush renamed to Refresh More shorthand functions - Combo, Dropdown, Drop, EasyPrint - output of stdout, stderr to a window
This commit is contained in:
parent
fb2fe90d37
commit
f331661a3a
3 changed files with 352 additions and 147 deletions
|
@ -1,19 +1,21 @@
|
|||
import time
|
||||
from random import randint
|
||||
import random
|
||||
import string
|
||||
import PySimpleGUI as SG
|
||||
|
||||
|
||||
def SourceDestFolders():
|
||||
with SG.FlexForm('Demo Source / Destination Folders', auto_size_text=True) as form:
|
||||
form_rows = [[SG.Text('Enter the Source and Destination folders')],
|
||||
[SG.Text('Choose Source and Destination Folders')],
|
||||
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False), SG.InputText('Source'), SG.FolderBrowse()],
|
||||
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False), SG.InputText('Dest'), SG.FolderBrowse()],
|
||||
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Source')],
|
||||
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False, justification='right'), SG.InputText('Dest'), SG.FolderBrowse()],
|
||||
[SG.Submit(), SG.Cancel()]]
|
||||
|
||||
(button, (source, dest)) = form.LayoutAndShow(form_rows)
|
||||
button, (source, dest) = form.LayoutAndShow(form_rows)
|
||||
if button == 'Submit':
|
||||
# do something useful with the inputs
|
||||
SG.MsgBox('Submitted', 'The user entered source:', source, 'Destination folder:', dest)
|
||||
SG.MsgBox('Submitted', 'The user entered source:', source, 'Destination folder:', dest, 'Using button', button)
|
||||
else:
|
||||
SG.MsgBoxError('Cancelled', 'User Cancelled')
|
||||
|
||||
|
@ -33,9 +35,9 @@ def Everything_NoContextManager():
|
|||
[SG.SimpleButton('Your very own button', button_color=('white', 'green'))],
|
||||
[SG.Submit(), SG.Cancel()]]
|
||||
|
||||
(button, (values)) = form.LayoutAndShow(layout)
|
||||
button, (values) = form.LayoutAndShow(layout)
|
||||
|
||||
SG.MsgBox('Title', 'Typical message box', 'The results of the form are a lot of data! Get ready... ', 'The button clicked was "{}"'.format(button), 'The values are', values)
|
||||
SG.MsgBox('Title', 'Typical message box', 'Here are the restults! There is one entry per input field ', 'The button clicked was "{}"'.format(button), 'The values are', values)
|
||||
|
||||
|
||||
def Everything():
|
||||
|
@ -45,16 +47,18 @@ def Everything():
|
|||
[SG.InputText()],
|
||||
[SG.Checkbox('My first checkbox!'), SG.Checkbox('My second checkbox!', default=True)],
|
||||
[SG.Radio('My first Radio!', "RADIO1", default=True), SG.Radio('My second Radio!', "RADIO1")],
|
||||
[SG.Spin(values=(1,2,3), initial_value=1, size=(2,1)), SG.T('Spinner 1', size=(20,1)),
|
||||
SG.Spin(values=(1,2,3), initial_value=1, size=(2,1)),SG.T('Spinner 2')],
|
||||
[SG.Multiline(default_text='This is the default Text should you decide not to type anything', scale=(2, 10))],
|
||||
[SG.InputCombo(['choice 1', 'choice 2'], size=(20, 3))],
|
||||
[SG.Text('_' * 100, size=(70, 1))],
|
||||
[SG.Text('Choose Source and Destination Folders', size=(35, 1))],
|
||||
[SG.Text('Source Folder', size=(15, 1), auto_size_text=False), SG.InputText('Source'), SG.FolderBrowse()],
|
||||
[SG.Text('Destination Folder', size=(15, 1), auto_size_text=False), SG.InputText('Dest'), SG.FolderBrowse()],
|
||||
[SG.SimpleButton('Your very own button', button_color=('white', 'green'))],
|
||||
[SG.SimpleButton('Custom Button', button_color=('white', 'green'))],
|
||||
[SG.Submit(), SG.Cancel()]]
|
||||
|
||||
(button, (values)) = form.LayoutAndShow(layout)
|
||||
button, (values) = form.LayoutAndShow(layout)
|
||||
|
||||
SG.MsgBox('Title', 'Typical message box', 'The results of the form are a lot of data! Get ready... ', 'The button clicked was "{}"'.format(button), 'The values are', values)
|
||||
|
||||
|
@ -62,6 +66,26 @@ def ProgressMeter():
|
|||
for i in range(1,10000):
|
||||
if not SG.EasyProgressMeter('My Meter', i+1, 10000): break
|
||||
|
||||
def RunningTimer():
|
||||
with SG.FlexForm('Running Timer', auto_size_text=True) as form:
|
||||
output_element = SG.Text('', size=(8, 2), font=('Helvetica', 20))
|
||||
form_rows = [[SG.Text('Non-blocking GUI with updates')],
|
||||
[output_element],
|
||||
[SG.SimpleButton('Quit')]]
|
||||
|
||||
form.AddRows(form_rows)
|
||||
form.Show(non_blocking=True)
|
||||
for i in range(1, 100):
|
||||
output_element.Update('{:02d}:{:02d}.{:02d}'.format(*divmod(int(i/100), 60), i%100))
|
||||
rc = form.Refresh()
|
||||
if rc is None or rc[0] == 'Quit':
|
||||
break
|
||||
time.sleep(.01)
|
||||
else:
|
||||
form.CloseNonBlockingForm()
|
||||
|
||||
|
||||
|
||||
|
||||
# Persistant form. Does not close when Send button is clicked.
|
||||
# Normally all Simple Buttons cause forms to close
|
||||
|
@ -70,7 +94,7 @@ def ChatBot():
|
|||
form.AddRow(SG.Text('This is where standard out is being routed', size=[40, 1]))
|
||||
form.AddRow(SG.Output(size=(80, 20)))
|
||||
form.AddRow(SG.Multiline(size=(70, 5), enter_submits=True), SG.ReadFormButton('SEND', button_color=(SG.YELLOWS[0], SG.BLUES[0])), SG.SimpleButton('EXIT', button_color=(SG.YELLOWS[0], SG.GREENS[0])))
|
||||
(button, value) = form.Read()
|
||||
button, value = form.Read()
|
||||
|
||||
# ---===--- Loop taking in user input and using it to query HowDoI web oracle --- #
|
||||
while True:
|
||||
|
@ -78,22 +102,22 @@ def ChatBot():
|
|||
print(value)
|
||||
else:
|
||||
break
|
||||
(button, value) = form.Read()
|
||||
button, value = form.Read()
|
||||
|
||||
|
||||
def NonBlockingPeriodicUpdateForm_ContextManager():
|
||||
# Show a form that's a running counter
|
||||
with SG.FlexForm('Running Timer', auto_size_text=True) as form:
|
||||
output_element = SG.Text('',size=(8,2), font=('Helvetica', 20), text_color='red')
|
||||
form_rows = [[SG.Text('None blocking GUI with updates')],
|
||||
output_element = SG.Text('',size=(10,2), font=('Helvetica', 20), text_color='red', justification='center')
|
||||
form_rows = [[SG.Text('Non blocking GUI with updates', justification='center')],
|
||||
[output_element],
|
||||
[SG.Quit()]]
|
||||
[SG.T(' '*15), SG.Quit()]]
|
||||
form.AddRows(form_rows)
|
||||
form.Show(non_blocking=True)
|
||||
|
||||
for i in range(1,500):
|
||||
output_element.Update('{:02d}:{:02d}.{:02d}'.format(*divmod(int(i/100), 60), i%100))
|
||||
rc = form.OutputFlush()
|
||||
rc = form.Refresh()
|
||||
if rc is None: # if user closed the window using X
|
||||
break
|
||||
button, values = rc
|
||||
|
@ -117,11 +141,8 @@ def NonBlockingPeriodicUpdateForm():
|
|||
|
||||
for i in range(1,50000):
|
||||
output_element.Update(f'{(i/100)/60:02d}:{(i/100)%60:02d}.{i%100:02d}')
|
||||
rc = form.OutputFlush()
|
||||
if rc is None: # if user closed the window using X
|
||||
break
|
||||
button, values = rc
|
||||
if button == 'Quit':
|
||||
rc = form.Refresh()
|
||||
if rc is None or rc[0] == 'Quit': # if user closed the window using X or clicked Quit button
|
||||
break
|
||||
time.sleep(.01)
|
||||
else:
|
||||
|
@ -129,40 +150,24 @@ def NonBlockingPeriodicUpdateForm():
|
|||
form.CloseNonBlockingForm()
|
||||
|
||||
|
||||
def NonBlockingScrolledPrintForm():
|
||||
# Show a form that's a running counter
|
||||
form = SG.FlexForm('Scrolled Print', auto_size_text=True, font=('Courier New', 12))
|
||||
output_element = SG.Output(size=(42,10))
|
||||
form_rows = [[SG.Text('Scrolled print output')],
|
||||
[output_element],
|
||||
[SG.Quit()]]
|
||||
form.AddRows(form_rows)
|
||||
form.Show(non_blocking=True) # Show a ;non-blocking form, returns immediately
|
||||
|
||||
for i in range(1,50000):
|
||||
print(f'{i} ', end="") # all print output will go to the scrolled text box
|
||||
# must call OutputFlush on a periodic basis to keep GUI alive
|
||||
rc = form.OutputFlush()
|
||||
if rc is None: # if user closed the window using X
|
||||
break
|
||||
button, values = rc
|
||||
if button == 'Quit': # if user cliced Quit button
|
||||
break
|
||||
else: # if the loop finished then need to close the form for the user
|
||||
form.CloseNonBlockingForm()
|
||||
def DebugTest():
|
||||
# SG.Print('How about we print a bunch of random numbers?', , size=(90,40))
|
||||
for i in range (1,300):
|
||||
SG.Print(i, randint(1, 1000), end='', sep='-')
|
||||
|
||||
# SG.PrintClose()
|
||||
|
||||
|
||||
def main():
|
||||
SG.SetOptions(border_width=4, element_padding=(4,6), font=("Helvetica", 10), button_color=('white', SG.BLUES[0]),
|
||||
progress_meter_border_depth=4)
|
||||
SG.SetOptions(border_width=1, element_padding=(4,6), font=("Helvetica", 10), button_color=('white', SG.BLUES[0]),
|
||||
progress_meter_border_depth=0)
|
||||
SourceDestFolders()
|
||||
Everything()
|
||||
NonBlockingPeriodicUpdateForm_ContextManager()
|
||||
ProgressMeter()
|
||||
ChatBot()
|
||||
NonBlockingScrolledPrintForm()
|
||||
NonBlockingPeriodicUpdateForm_ContextManager()
|
||||
Everything_NoContextManager()
|
||||
Everything()
|
||||
DebugTest()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
exit(69)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue