Major update of all demo programs to use new PEP8 bindings, etc

This commit is contained in:
PySimpleGUI 2019-10-23 16:10:03 -04:00
parent 3f7c87c562
commit 7f52778bcc
307 changed files with 19546 additions and 3297 deletions

View file

@ -1,9 +1,5 @@
#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
import PySimpleGUI as sg
else:
import PySimpleGUI27 as sg
import PySimpleGUI as sg
import glob
import ntpath
import subprocess
@ -11,13 +7,16 @@ import subprocess
LOCATION_OF_YOUR_SCRIPTS = ''
# Execute the command. Will not see the output from the command until it completes.
def execute_command_blocking(command, *args):
expanded_args = []
for a in args:
expanded_args.append(a)
# expanded_args += a
try:
sp = subprocess.Popen([command,expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
sp = subprocess.Popen([command, expanded_args], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = sp.communicate()
if out:
print(out.decode("utf-8"))
@ -28,50 +27,60 @@ def execute_command_blocking(command, *args):
return out
# Executes command and immediately returns. Will not see anything the script outputs
def execute_command_nonblocking(command, *args):
expanded_args = []
for a in args:
expanded_args += a
try:
sp = subprocess.Popen([command,expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except: pass
sp = subprocess.Popen([command, expanded_args], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except:
pass
def Launcher2():
sg.ChangeLookAndFeel('GreenTan')
window = sg.Window('Script launcher')
sg.change_look_and_feel('GreenTan')
filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS+'*.py')
namesonly = []
for file in filelist:
namesonly.append(ntpath.basename(file))
layout = [
[sg.Listbox(values=namesonly, size=(30, 19), select_mode=sg.SELECT_MODE_EXTENDED, key='demolist'), sg.Output(size=(88, 20), font='Courier 10')],
[sg.Checkbox('Wait for program to complete', default=False, key='wait')],
[sg.Button('Run'), sg.Button('Shortcut 1'), sg.Button('Fav Program'), sg.Button('EXIT')],
]
layout = [
[sg.Listbox(values=namesonly, size=(30, 19),
select_mode=sg.SELECT_MODE_EXTENDED, key='demolist'),
sg.Output(size=(88, 20), font='Courier 10')],
[sg.CBox('Wait for program to complete', default=False, key='wait')],
[sg.Button('Run'), sg.Button('Shortcut 1'), sg.Button('Fav Program'), sg.Button('EXIT')],
]
window.Layout(layout)
window = sg.Window('Script launcher', layout)
# ---===--- Loop taking in user input --- #
while True:
event, values = window.Read()
event, values = window.read()
if event in ('EXIT', None):
break # exit button clicked
if event in ('Shortcut 1', 'Fav Program'):
print('Quickly launch your favorite programs using these shortcuts')
print('Or copy files to your github folder. Or anything else you type on the command line')
print('''
Or copy files to your github folder.
Or anything else you type on the command line''')
# copyfile(source, dest)
elif event == 'Run':
for index, file in enumerate(values['demolist']):
print('Launching %s'%file)
window.Refresh() # make the print appear immediately
print('Launching %s' % file)
window.refresh() # make the print appear immediately
if values['wait']:
execute_command_blocking(LOCATION_OF_YOUR_SCRIPTS + file)
else:
execute_command_nonblocking(LOCATION_OF_YOUR_SCRIPTS + file)
execute_command_nonblocking(
LOCATION_OF_YOUR_SCRIPTS + file)
window.close()
if __name__ == '__main__':
Launcher2()