Imrpoved spiffy launcher!!
This commit is contained in:
parent
a27240f146
commit
2afef635f2
|
@ -1,7 +1,11 @@
|
|||
import PySimpleGUI as sg
|
||||
import glob
|
||||
import ntpath
|
||||
import subprocess
|
||||
|
||||
def Launcher():
|
||||
LOCATION_OF_YOUR_SCRIPTS = 'C:/Python/PycharmProjects/GooeyGUI/'
|
||||
|
||||
def Launcher1():
|
||||
|
||||
form = sg.FlexForm('Script launcher')
|
||||
|
||||
|
@ -20,14 +24,15 @@ def Launcher():
|
|||
if button == 'EXIT' or button is None:
|
||||
break # exit button clicked
|
||||
if button == 'script1':
|
||||
ExecuteCommandSubprocess('pip','list')
|
||||
execute_command_blocking('pip', 'list')
|
||||
elif button == 'script2':
|
||||
ExecuteCommandSubprocess('python', '--version')
|
||||
execute_command_blocking('python', '--version')
|
||||
elif button == 'Run':
|
||||
ExecuteCommandSubprocess(value[0]) # send string without carriage return on end
|
||||
execute_command_blocking(value[0]) # send string without carriage return on end
|
||||
|
||||
|
||||
def ExecuteCommandSubprocess(command, *args):
|
||||
# Execute the command. Will not see the output from the command until it completes.
|
||||
def execute_command_blocking(command, *args):
|
||||
try:
|
||||
sp = subprocess.Popen([command,*args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
out, err = sp.communicate()
|
||||
|
@ -37,7 +42,45 @@ def ExecuteCommandSubprocess(command, *args):
|
|||
print(err.decode("utf-8"))
|
||||
except: pass
|
||||
|
||||
# Executes command and immediately returns. Will not see anything the script outputs
|
||||
def execute_command_nonblocking(command, *args):
|
||||
try:
|
||||
sp = subprocess.Popen([command,*args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
except: pass
|
||||
|
||||
def Launcher2():
|
||||
sg.ChangeLookAndFeel('GreenTan')
|
||||
form = sg.FlexForm('Script launcher')
|
||||
|
||||
filelist = glob.glob(LOCATION_OF_YOUR_SCRIPTS+'*.py')
|
||||
namesonly = []
|
||||
for file in filelist:
|
||||
namesonly.append(ntpath.basename(file))
|
||||
|
||||
layout = [
|
||||
[sg.Text('Script output....', size=(40, 1))],
|
||||
[sg.Listbox(values=namesonly, size=(30, 19), select_mode=sg.SELECT_MODE_EXTENDED, key='demolist'), sg.Output(size=(88, 20), font='Courier 10')],
|
||||
[sg.ReadFormButton('Run'), sg.ReadFormButton('Shortcut 1'), sg.ReadFormButton('Fav Program'), sg.SimpleButton('EXIT')],
|
||||
]
|
||||
|
||||
form.Layout(layout)
|
||||
|
||||
# ---===--- Loop taking in user input and using it to query HowDoI --- #
|
||||
while True:
|
||||
(button, value) = form.Read()
|
||||
if button in ('EXIT', None):
|
||||
break # exit button clicked
|
||||
if button 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')
|
||||
# copyfile(source, dest)
|
||||
elif button is 'Run':
|
||||
for index, file in enumerate(value['demolist']):
|
||||
print('Launching %s'%file)
|
||||
form.Refresh() # make the print appear immediately
|
||||
execute_command_nonblocking(LOCATION_OF_YOUR_SCRIPTS + file)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
Launcher()
|
||||
Launcher2()
|
||||
|
||||
|
|
Loading…
Reference in New Issue