The main program. Creates the Window and runs the event loop
()
| 32 | |
| 33 | # ----------------------------- The main program ----------------------------- |
| 34 | def mini_launcher(): |
| 35 | """ |
| 36 | The main program. Creates the Window and runs the event loop |
| 37 | """ |
| 38 | |
| 39 | sg.theme('dark') |
| 40 | sg.set_options(border_width=0) |
| 41 | |
| 42 | # layout is built rather than a static definion |
| 43 | # starting with a blank line. This will give you a place to "grab" the window to move it around on the screen |
| 44 | layout = [[sg.Text(' ' * 10, background_color='black')]] |
| 45 | |
| 46 | # add the buttons to the layout |
| 47 | for button_text in button_dict: |
| 48 | layout += [[sg.Button(button_text)]] |
| 49 | |
| 50 | # complete the layout with a text "X" that will generate an event when clicked |
| 51 | layout += [[sg.T('❎', background_color='black', enable_events=True, key='Exit')]] |
| 52 | |
| 53 | # Create the Window |
| 54 | window = sg.Window('Script launcher', layout, no_titlebar=True, grab_anywhere=True, keep_on_top=True, element_padding=(0, 0), default_button_element_size=(20, 1), location=LOCATION, auto_size_buttons=False, use_default_focus=False, alpha_channel=TRANSPARENCY, background_color='black', ) |
| 55 | |
| 56 | while True: # The Event Loop |
| 57 | event, values = window.read() |
| 58 | if event == 'Exit' or event == sg.WINDOW_CLOSED: |
| 59 | break |
| 60 | |
| 61 | file_to_edit = button_dict.get(event) # Use button to find associated filename |
| 62 | try: |
| 63 | execute_command_blocking(PYCHARM, file_to_edit) # launch PyCharm |
| 64 | except Exception as e: |
| 65 | sg.Print(f'Got an exception {e} trying to open in PyCharm this file:', file_to_edit) |
| 66 | |
| 67 | |
| 68 | def execute_command_blocking(command, *args): |
no test coverage detected