Added ability to use older versions of PySimpleGUI by trying sg.execute_editor and launching manually if it fails. Added quotes around __file__ when self-editing

This commit is contained in:
PySimpleGUI 2021-03-17 10:31:53 -04:00
parent c18c8cc03d
commit 04379b930d
1 changed files with 11 additions and 4 deletions

View File

@ -123,6 +123,10 @@ def get_editor():
return user_editor return user_editor
def using_local_editor():
user_editor = sg.user_settings_get_entry('-editor program-', None)
return get_editor() == user_editor
def get_explorer(): def get_explorer():
""" """
@ -507,10 +511,13 @@ def main():
sg.cprint('') sg.cprint('')
sg.cprint(f'{full_filename}', c='white on purple') sg.cprint(f'{full_filename}', c='white on purple')
# if line != 1: # if line != 1:
try: if using_local_editor():
sg.execute_editor(full_filename, line_number=int(line))
except:
execute_command_subprocess(editor_program, full_filename) execute_command_subprocess(editor_program, full_filename)
else:
try:
sg.execute_editor(full_filename, line_number=int(line))
except:
execute_command_subprocess(editor_program, full_filename)
# else: # else:
# sg.execute_editor(full_filename) # sg.execute_editor(full_filename)
else: else:
@ -543,7 +550,7 @@ def main():
editor_program = get_editor() editor_program = get_editor()
sg.cprint(f'opening using {editor_program}:') sg.cprint(f'opening using {editor_program}:')
sg.cprint(f'{__file__}', text_color='white', background_color='red', end='') sg.cprint(f'{__file__}', text_color='white', background_color='red', end='')
execute_command_subprocess(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 file_list if values['-FILTER-'].lower() in i.lower()] new_list = [i for i in file_list if values['-FILTER-'].lower() in i.lower()]
window['-DEMO LIST-'].update(new_list) window['-DEMO LIST-'].update(new_list)