2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-08-30 00:50:10 +00:00
|
|
|
import glob
|
|
|
|
import ntpath
|
2018-08-09 15:53:42 +00:00
|
|
|
import subprocess
|
2018-08-09 10:53:13 +00:00
|
|
|
|
2018-09-08 03:23:45 +00:00
|
|
|
LOCATION_OF_YOUR_SCRIPTS = ''
|
2018-08-30 00:50:10 +00:00
|
|
|
|
|
|
|
# Execute the command. Will not see the output from the command until it completes.
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
|
2018-08-30 00:50:10 +00:00
|
|
|
def execute_command_blocking(command, *args):
|
2018-09-08 03:23:45 +00:00
|
|
|
expanded_args = []
|
|
|
|
for a in args:
|
|
|
|
expanded_args.append(a)
|
|
|
|
# expanded_args += a
|
2018-08-09 15:53:42 +00:00
|
|
|
try:
|
2019-10-23 20:10:03 +00:00
|
|
|
sp = subprocess.Popen([command, expanded_args], shell=True,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2018-08-09 15:53:42 +00:00
|
|
|
out, err = sp.communicate()
|
|
|
|
if out:
|
|
|
|
print(out.decode("utf-8"))
|
|
|
|
if err:
|
|
|
|
print(err.decode("utf-8"))
|
2018-09-04 23:43:22 +00:00
|
|
|
except:
|
|
|
|
out = ''
|
|
|
|
return out
|
2018-08-09 10:53:13 +00:00
|
|
|
|
2018-08-30 00:50:10 +00:00
|
|
|
# Executes command and immediately returns. Will not see anything the script outputs
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
|
2018-08-30 00:50:10 +00:00
|
|
|
def execute_command_nonblocking(command, *args):
|
2018-09-08 03:23:45 +00:00
|
|
|
expanded_args = []
|
|
|
|
for a in args:
|
|
|
|
expanded_args += a
|
2018-08-30 00:50:10 +00:00
|
|
|
try:
|
2019-10-23 20:10:03 +00:00
|
|
|
sp = subprocess.Popen([command, expanded_args], shell=True,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2018-08-30 00:50:10 +00:00
|
|
|
|
|
|
|
def Launcher2():
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('GreenTan')
|
2018-08-30 00:50:10 +00:00
|
|
|
|
|
|
|
filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS+'*.py')
|
|
|
|
namesonly = []
|
|
|
|
for file in filelist:
|
|
|
|
namesonly.append(ntpath.basename(file))
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
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')],
|
|
|
|
]
|
2018-08-30 00:50:10 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('Script launcher', layout)
|
2018-08-30 00:50:10 +00:00
|
|
|
|
2018-10-08 17:30:33 +00:00
|
|
|
# ---===--- Loop taking in user input --- #
|
2018-08-30 00:50:10 +00:00
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
2018-10-15 20:07:23 +00:00
|
|
|
if event in ('EXIT', None):
|
2018-08-30 00:50:10 +00:00
|
|
|
break # exit button clicked
|
2018-10-15 20:07:23 +00:00
|
|
|
if event in ('Shortcut 1', 'Fav Program'):
|
2018-08-30 00:50:10 +00:00
|
|
|
print('Quickly launch your favorite programs using these shortcuts')
|
2019-10-23 20:10:03 +00:00
|
|
|
print('''
|
|
|
|
Or copy files to your github folder.
|
|
|
|
Or anything else you type on the command line''')
|
2018-08-30 00:50:10 +00:00
|
|
|
# copyfile(source, dest)
|
2019-06-26 15:09:42 +00:00
|
|
|
elif event == 'Run':
|
2018-10-15 20:07:23 +00:00
|
|
|
for index, file in enumerate(values['demolist']):
|
2019-10-23 20:10:03 +00:00
|
|
|
print('Launching %s' % file)
|
|
|
|
window.refresh() # make the print appear immediately
|
2018-10-15 20:07:23 +00:00
|
|
|
if values['wait']:
|
2018-08-30 01:00:08 +00:00
|
|
|
execute_command_blocking(LOCATION_OF_YOUR_SCRIPTS + file)
|
|
|
|
else:
|
2019-10-23 20:10:03 +00:00
|
|
|
execute_command_nonblocking(
|
|
|
|
LOCATION_OF_YOUR_SCRIPTS + file)
|
|
|
|
|
|
|
|
window.close()
|
2018-08-30 00:50:10 +00:00
|
|
|
|
2018-08-09 10:53:13 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-08-30 00:50:10 +00:00
|
|
|
Launcher2()
|