Merge pull request #3855 from PySimpleGUI/Dev-latest

Make backwards compatible with older PySimpleGUI versions
This commit is contained in:
PySimpleGUI 2021-01-30 19:10:25 -05:00 committed by GitHub
commit 6a90390f44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 5 deletions

View File

@ -1,7 +1,6 @@
import os.path import os.path
import subprocess import subprocess
import sys import sys
from idlelib import tooltip
import PySimpleGUI as sg import PySimpleGUI as sg
@ -129,7 +128,7 @@ def settings_window():
sg.user_settings_set_entry('-demos folder-', values['-DEMOS-']) sg.user_settings_set_entry('-demos folder-', values['-DEMOS-'])
new_editor = editor_program if not values['-EDITOR PROGRAM-'] else values['-EDITOR PROGRAM-'] new_editor = editor_program if not values['-EDITOR PROGRAM-'] else values['-EDITOR PROGRAM-']
sg.user_settings_set_entry('-editor program-', new_editor) sg.user_settings_set_entry('-editor program-', new_editor)
new_theme = sg.theme_global() if values['-THEME-'] == '' else values['-THEME-'] new_theme = get_theme() if values['-THEME-'] == '' else values['-THEME-']
sg.user_settings_set_entry('-theme-', new_theme) sg.user_settings_set_entry('-theme-', new_theme)
return True return True
@ -203,7 +202,7 @@ def main():
sg.cprint(f'Editing using {editor_program}', text_color='white', background_color='red', end='') sg.cprint(f'Editing using {editor_program}', text_color='white', background_color='red', end='')
sg.cprint('') sg.cprint('')
sg.cprint(f'{demo_files_dict[file]}', text_color='white', background_color='purple') sg.cprint(f'{demo_files_dict[file]}', text_color='white', background_color='purple')
sg.execute_subprocess_nonblocking(f'{editor_program}', f'"{demo_files_dict[file]}"') execute_command_subprocess(f'{editor_program}', f'"{demo_files_dict[file]}"')
elif event == 'Run': elif event == 'Run':
sg.cprint('Running....', c='white on green', end='') sg.cprint('Running....', c='white on green', end='')
sg.cprint('') sg.cprint('')
@ -211,11 +210,11 @@ def main():
for file in values['-DEMO LIST-']: for file in values['-DEMO LIST-']:
file_to_run = str(demo_files_dict[file]) file_to_run = str(demo_files_dict[file])
sg.cprint(file_to_run,text_color='white', background_color='purple') sg.cprint(file_to_run,text_color='white', background_color='purple')
sg.execute_subprocess_nonblocking('python' if sg._running_windows() else 'python3', f'"{file_to_run}"') execute_command_subprocess('python', f'{file_to_run}')
# run_py(file_to_run) # run_py(file_to_run)
elif event.startswith('Edit Me'): elif event.startswith('Edit Me'):
sg.cprint(f'opening using {editor_program}\nThis file - {__file__}', text_color='white', background_color='green', end='') sg.cprint(f'opening using {editor_program}\nThis file - {__file__}', text_color='white', background_color='green', end='')
sg.execute_subprocess_nonblocking(f'{editor_program}', f'"{__file__}"') execute_command_subprocess(f'{editor_program}', f'"{__file__}"')
elif event == '-FILTER-': elif event == '-FILTER-':
new_list = [i for i in demo_files if values['-FILTER-'].lower() in i.lower()] new_list = [i for i in demo_files if values['-FILTER-'].lower() in i.lower()]
window['-DEMO LIST-'].update(new_list) window['-DEMO LIST-'].update(new_list)
@ -245,6 +244,25 @@ def main():
window.close() window.close()
def execute_command_subprocess(command, *args, wait=False):
if sys.platform == 'linux':
arg_string = ''
for arg in args:
arg_string += ' ' + str(arg)
sp = subprocess.Popen(['python3' + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
expanded_args = ' '.join(args)
sp = subprocess.Popen([command, expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if wait:
out, err = sp.communicate()
if out:
print(out.decode("utf-8"))
if err:
print(err.decode("utf-8"))
if __name__ == '__main__': if __name__ == '__main__':