Changed what gets executed when buttons pushed

This commit is contained in:
MikeTheWatchGuy 2018-08-09 11:53:42 -04:00
parent 9c1ebeb0b4
commit 4bb89514cb
1 changed files with 16 additions and 9 deletions

View File

@ -1,5 +1,5 @@
import PySimpleGUI as sg import PySimpleGUI as sg
import os import subprocess
def Launcher(): def Launcher():
@ -8,7 +8,8 @@ def Launcher():
layout = [ layout = [
[sg.Text('Script output....', size=(40, 1))], [sg.Text('Script output....', size=(40, 1))],
[sg.Output(size=(88, 20))], [sg.Output(size=(88, 20))],
[sg.ReadFormButton('script1'), sg.ReadFormButton('script2'), sg.SimpleButton('EXIT')] [sg.ReadFormButton('script1'), sg.ReadFormButton('script2'), sg.SimpleButton('EXIT')],
[sg.Text('Manual command', size=(15,1)), sg.InputText(focus=True), sg.ReadFormButton('Run', bind_return_key=True)]
] ]
form.Layout(layout) form.Layout(layout)
@ -19,16 +20,22 @@ def Launcher():
if button == 'EXIT' or button is None: if button == 'EXIT' or button is None:
break # exit button clicked break # exit button clicked
if button == 'script1': if button == 'script1':
ExecuteCommandOS('python SimScript.py') ExecuteCommandSubprocess('pip','list')
elif button == 'script2': elif button == 'script2':
ExecuteCommandOS('python SimScript.py') ExecuteCommandSubprocess('python', '--version')
elif button == 'Enter': elif button == 'Run':
ExecuteCommandOS(value[0]) # send string without carriage return on end ExecuteCommandSubprocess(value[0]) # send string without carriage return on end
def ExecuteCommandOS(command): def ExecuteCommandSubprocess(command, *args):
output = os.popen(command).read() try:
print(output) sp = subprocess.Popen([command,*args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = sp.communicate()
if out:
print(out.decode("utf-8"))
if err:
print(err.decode("utf-8"))
except: pass
if __name__ == '__main__': if __name__ == '__main__':