The main program that contains the event loop. It will call the make_window function to create the window.
()
| 859 | # --------------------------------- Main Program Layout --------------------------------- |
| 860 | |
| 861 | def main(): |
| 862 | """ |
| 863 | The main program that contains the event loop. |
| 864 | It will call the make_window function to create the window. |
| 865 | """ |
| 866 | |
| 867 | sg.user_settings_filename(filename='psgdemos.json') |
| 868 | |
| 869 | sg.user_settings_filename('psgdemos.json') |
| 870 | sg.set_options(icon=sg.EMOJI_BASE64_HAPPY_IDEA) |
| 871 | find_in_file.file_list_dict = None |
| 872 | |
| 873 | old_typed_value = None |
| 874 | |
| 875 | file_list_dict = get_file_list_dict() |
| 876 | file_list = get_file_list() |
| 877 | window = make_window() |
| 878 | window['-FILTER NUMBER-'].update(f'{len(file_list)} files') |
| 879 | window.force_focus() |
| 880 | window['-FILTER-'].set_focus() |
| 881 | counter = 0 |
| 882 | while True: |
| 883 | event, values = window.read() |
| 884 | # print(event, values) |
| 885 | |
| 886 | counter += 1 |
| 887 | if event in (sg.WINDOW_CLOSED, 'Exit'): |
| 888 | break |
| 889 | if event == '-DEMO LIST-': # if double clicked (used the bind return key parm) |
| 890 | if sg.user_settings_get_entry('-dclick runs-'): |
| 891 | event = 'Run' |
| 892 | elif sg.user_settings_get_entry('-dclick edits-'): |
| 893 | event = 'Edit' |
| 894 | if event == 'Edit': |
| 895 | editor_program = get_editor() |
| 896 | for file in values['-DEMO LIST-']: |
| 897 | if find_in_file.file_list_dict is not None: |
| 898 | full_filename, line = window_choose_line_to_edit(file, find_in_file.file_list_dict[file][0], find_in_file.file_list_dict[file][1], find_in_file.file_list_dict[file][2]) |
| 899 | else: |
| 900 | full_filename, line = get_file_list_dict()[file], 1 |
| 901 | if line is not None: |
| 902 | sg.cprint(f'Editing using {editor_program}', c='white on red', end='') |
| 903 | sg.cprint('') |
| 904 | sg.cprint(f'{full_filename}', c='white on purple') |
| 905 | if not get_editor(): |
| 906 | sg.popup_error_with_traceback('No editor has been configured', 'You need to configure an editor in order to use this feature', 'You can configure the editor in the Demo Brower Settings or the PySimpleGUI Global Settings') |
| 907 | else: |
| 908 | if using_local_editor(): |
| 909 | sg.execute_command_subprocess(editor_program, f'"{full_filename}"') |
| 910 | else: |
| 911 | try: |
| 912 | sg.execute_editor(full_filename, line_number=int(line)) |
| 913 | except: |
| 914 | sg.execute_command_subprocess(editor_program, f'"{full_filename}"') |
| 915 | else: |
| 916 | sg.cprint('Editing canceled') |
| 917 | elif event == 'Run': |
| 918 | sg.cprint('Running....', c='white on green', end='') |
no test coverage detected