(silent=False)
| 136 | pass |
| 137 | |
| 138 | def main(silent=False): |
| 139 | if silent: |
| 140 | kill_all(python_only=True) |
| 141 | sg.popup_auto_close('Killed everything....', 'This window autocloses') |
| 142 | sys.exit() |
| 143 | # ---------------- Create Form ---------------- |
| 144 | sg.theme('Dark Grey 9') |
| 145 | sg.set_options(icon=icon) |
| 146 | |
| 147 | window = make_window() |
| 148 | current_display_list = display_list = show_list_by_name(window['-PYTHON ONLY-'].get()) |
| 149 | window['-PROCESSES-'].update(display_list) |
| 150 | name_sorted = True |
| 151 | |
| 152 | # ---------------- main loop ---------------- |
| 153 | while True: |
| 154 | # --------- Read and update window -------- |
| 155 | event, values = window.read() |
| 156 | if event in (sg.WIN_CLOSED, 'Exit'): |
| 157 | break |
| 158 | |
| 159 | # skip mouse, control key and shift key events entirely |
| 160 | if 'Mouse' in event or 'Control' in event or 'Shift' in event: |
| 161 | continue |
| 162 | |
| 163 | # --------- Do Button Operations -------- |
| 164 | if event == 'Sort by Name': |
| 165 | window['-PROCESSES-'].update(show_list_by_name(values['-PYTHON ONLY-'])) |
| 166 | name_sorted = True |
| 167 | elif event.startswith('Kill'): |
| 168 | if event.startswith('Kill All'): |
| 169 | processes_to_kill = show_list_by_name(values['-PYTHON ONLY-']) |
| 170 | else: |
| 171 | processes_to_kill = values['-PROCESSES-'] |
| 172 | for proc in processes_to_kill: |
| 173 | pid = int(proc[0:5]) |
| 174 | try: |
| 175 | kill_proc(pid=pid) |
| 176 | # kill_proc_tree(pid=pid) |
| 177 | except Exception as e: |
| 178 | if event.endswith('Selected'): # only show the error if trying to kill only 1 process |
| 179 | sg.popup_no_wait('Error killing process', e, auto_close_duration=2, auto_close=True, keep_on_top=True) |
| 180 | current_display_list = show_list_by_name(values['-PYTHON ONLY-']) if name_sorted else show_list_by_cpu(values['-PYTHON ONLY-']) |
| 181 | window['-PROCESSES-'].update(current_display_list) |
| 182 | if event.endswith('Exit'): |
| 183 | break |
| 184 | elif event == 'Sort by % CPU': |
| 185 | window['-PROCESSES-'].update(show_list_by_cpu(values['-PYTHON ONLY-'])) |
| 186 | name_sorted = False |
| 187 | elif event == 'Show Open Files': |
| 188 | for proc in values['-PROCESSES-']: |
| 189 | pid = int(proc[0:5]) |
| 190 | parent = psutil.Process(pid) |
| 191 | file_list = parent.open_files() |
| 192 | out = '' |
| 193 | for f in file_list: |
| 194 | out += f'{f}\n' |
| 195 | sg.popup_scrolled(out, non_blocking=True, keep_on_top=True,size=(100,30)) |
no test coverage detected