Skip to content

Commit

Permalink
Major update of all demo programs to use new PEP8 bindings, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
PySimpleGUI committed Oct 23, 2019
1 parent 3f7c87c commit 7f52778
Show file tree
Hide file tree
Showing 307 changed files with 19,565 additions and 3,316 deletions.
Binary file added DemoPrograms old/ButtonClick.wav
Binary file not shown.
File renamed without changes
File renamed without changes
54 changes: 54 additions & 0 deletions DemoPrograms old/Demo_All_Widgets.py
@@ -0,0 +1,54 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

sg.ChangeLookAndFeel('GreenTan')

# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
['&Help', '&About...'], ]

# ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='lightblue', justification='center', size=(10, 1))],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]

layout = [
[sg.Menu(menu_def, tearoff=True)],
[sg.Text('(Almost) All widgets in one Window!', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
[sg.Text('Here is some text.... and a place to enter text')],
[sg.InputText('This is my text')],
[sg.Frame(layout=[
[sg.Checkbox('Checkbox', size=(10,1)), sg.Checkbox('My second checkbox!', default=True)],
[sg.Radio('My first Radio! ', "RADIO1", default=True, size=(10,1)), sg.Radio('My second Radio!', "RADIO1")]], title='Options',title_color='red', relief=sg.RELIEF_SUNKEN, tooltip='Use these to set flags')],
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 1)),
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
[sg.InputOptionMenu(('Menu Option 1', 'Menu Option 2', 'Menu Option 3'))],
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
sg.Frame('Labelled Group',[[
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25, tick_interval=25),
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
sg.Column(column1, background_color='lightblue')]])],
[sg.Text('_' * 80)],
[sg.Text('Choose A Folder', size=(35, 1))],
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
sg.InputText('Default Folder'), sg.FolderBrowse()],
[sg.Submit(tooltip='Click to submit this form'), sg.Cancel()]]

window = sg.Window('Everything bagel', default_element_size=(40, 1), grab_anywhere=False).Layout(layout)
event, values = window.Read()

sg.Popup('Title',
'The results of the window.',
'The button clicked was "{}"'.format(event),
'The values are', values)


65 changes: 65 additions & 0 deletions DemoPrograms old/Demo_Animated_GIFs.py

Large diffs are not rendered by default.

File renamed without changes.
40 changes: 40 additions & 0 deletions DemoPrograms old/Demo_Base64_Image_Encoder.py
@@ -0,0 +1,40 @@
import PySimpleGUI as sg
import os
import base64

'''
Base64 Encoder - encodes a folder of PNG files and creates a .py file with definitions
'''

OUTPUT_FILENAME = 'output.py'

def main():
# folder = r'C:\Python\PycharmProjects\GooeyGUI\Uno Cards'
folder=''
folder = sg.PopupGetFolder('Source folder for images\nImages will be encoded and results saved to %s'%OUTPUT_FILENAME,
title='Base64 Encoder',
default_path=folder, initial_folder=folder )

if folder is None or folder == '':
sg.PopupCancel('Cancelled - No valid folder entered')
return
try:
namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico') or f.endswith('.gif')]
except:
sg.PopupCancel('Cancelled - No valid folder entered')
return

outfile = open(os.path.join(folder, OUTPUT_FILENAME), 'w')

for i, file in enumerate(namesonly):
contents = open(os.path.join(folder, file), 'rb').read()
encoded = base64.b64encode(contents)
outfile.write('\n{} = {}\n\n'.format(file[:file.index(".")], encoded))
sg.OneLineProgressMeter('Base64 Encoding', i+1, len(namesonly),key='_METER_')

outfile.close()
sg.Popup('Completed!', 'Encoded %s files'%(i+1))


if __name__ == '__main__':
main()
42 changes: 42 additions & 0 deletions DemoPrograms old/Demo_Borderless_Window.py
@@ -0,0 +1,42 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

"""
Turn off padding in order to get a really tight looking layout.
"""

sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0, 0))

layout = [[sg.T('User:', pad=((3, 0), 0)), sg.OptionMenu(values=('User 1', 'User 2'), size=(20, 1)),
sg.T('0', size=(8, 1))],
[sg.T('Customer:', pad=((3, 0), 0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20, 1)),
sg.T('1', size=(8, 1))],
[sg.T('Notes:', pad=((3, 0), 0)), sg.In(size=(44, 1), background_color='white', text_color='black')],
[sg.Button('Start', button_color=('white', 'black')),
sg.Button('Stop', button_color=('gray50', 'black')),
sg.Button('Reset', button_color=('white', '#9B0023')),
sg.Button('Submit', button_color=('gray60', 'springgreen4')),
sg.Button('Exit', button_color=('white', '#00406B'))]]

window = sg.Window("Borderless Window",
default_element_size=(12, 1),
text_justification='r',
auto_size_text=False,
auto_size_buttons=False,
no_titlebar=True,
grab_anywhere=True,
default_button_element_size=(12, 1))

window.Layout(layout)

while True:
event, values = window.Read()
if event is None or event == 'Exit':
break


33 changes: 33 additions & 0 deletions DemoPrograms old/Demo_Button_Click.py
@@ -0,0 +1,33 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg

if not sys.platform.startswith('win'):
sg.PopupError('Sorry, you gotta be on Windows')
sys.exit()
import winsound


# sg.ChangeLookAndFeel('Dark')
# sg.SetOptions(element_padding=(0,0))

layout = [
[sg.Button('Start', button_color=('white', 'black'), key='start'),
sg.Button('Stop', button_color=('white', 'black'), key='stop'),
sg.Button('Reset', button_color=('white', 'firebrick3'), key='reset'),
sg.Button('Submit', button_color=('white', 'springgreen4'), key='submit')]
]

window = sg.Window("Button Click", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False, default_button_element_size=(12,1), use_default_focus=False).Layout(layout).Finalize()

window.FindElement('submit').Update(disabled=True)

recording = have_data = False
while True:
event, values = window.Read(timeout=100)
if event is None:
sys.exit(69)
winsound.PlaySound("ButtonClick.wav", 1) if event != sg.TIMEOUT_KEY else None
43 changes: 43 additions & 0 deletions DemoPrograms old/Demo_Button_Func_Calls.py
@@ -0,0 +1,43 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg


"""
Demo Button Function Calls
Typically GUI packages in Python (tkinter, Qt, WxPython, etc) will call a user's function
when a button is clicked. This "Callback" model versus "Message Passing" model is a fundamental
difference between PySimpleGUI and all other GUI.
There are NO BUTTON CALLBACKS in the PySimpleGUI Architecture
It is quite easy to simulate these callbacks however. The way to do this is to add the calls
to your Event Loop
"""

def callback_function1():
sg.Popup('In Callback Function 1')
print('In the callback function 1')

def callback_function2():
sg.Popup('In Callback Function 2')
print('In the callback function 2')

layout = [ [sg.Text('Demo of Button Callbacks')],
[sg.Button('Button 1'), sg.Button('Button 2')] ]

window = sg.Window('Button Callback Simulation').Layout(layout)

while True: # Event Loop
event, values = window.Read()
if event is None:
break
elif event == 'Button 1':
callback_function1() # call the "Callback" function
elif event == 'Button 2':
callback_function2() # call the "Callback" function

window.Close()
51 changes: 51 additions & 0 deletions DemoPrograms old/Demo_Button_States.py
@@ -0,0 +1,51 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
"""
Demonstrates using a "tight" layout with a Dark theme.
Shows how button states can be controlled by a user application. The program manages the disabled/enabled
states for buttons and changes the text color to show greyed-out (disabled) buttons
"""

sg.ChangeLookAndFeel('Dark')
sg.SetOptions(element_padding=(0,0))

layout = [[sg.T('User:', pad=((3,0),0)), sg.OptionMenu(values = ('User 1', 'User 2'), size=(20,1)), sg.T('0', size=(8,1))],
[sg.T('Customer:', pad=((3,0),0)), sg.OptionMenu(values=('Customer 1', 'Customer 2'), size=(20,1)), sg.T('1', size=(8,1))],
[sg.T('Notes:', pad=((3,0),0)), sg.In(size=(44,1), background_color='white', text_color='black')],
[sg.Button('Start', button_color=('white', 'black'), key='_Start_'),
sg.Button('Stop', button_color=('white', 'black'), key='_Stop_'),
sg.Button('Reset', button_color=('white', 'firebrick3'), key='_Reset_'),
sg.Button('Submit', button_color=('white', 'springgreen4'), key='_Submit_')]]

window = sg.Window("Time Tracker", default_element_size=(12,1), text_justification='r', auto_size_text=False, auto_size_buttons=False,
default_button_element_size=(12,1)).Layout(layout).Finalize()


for key, state in {'_Start_': False, '_Stop_': True, '_Reset_': True, '_Submit_': True}.items():
window.FindElement(key).Update(disabled=state)

recording = have_data = False
while True:
event, values = window.Read()
print(event)
if event is None:
sys.exit(69)
if event == '_Start_':
for key, state in {'_Start_':True, '_Stop_':False, '_Reset_':False, '_Submit_':True}.items():
window.FindElement(key).Update(disabled=state)
recording = True
elif event == '_Stop_' and recording:
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':False, '_Submit_':False}.items()]
recording = False
have_data = True
elif event == '_Reset_':
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':True}.items()]
recording = False
have_data = False
elif event == '_Submit_' and have_data:
[window.FindElement(key).Update(disabled=value) for key,value in {'_Start_':False, '_Stop_':True, '_Reset_':True, '_Submit_':False}.items()]
recording = False

0 comments on commit 7f52778

Please sign in to comment.