|
4 | 4 |
|
5 | 5 | from constants.log import LOG |
6 | 6 | from constants.resources import UI_PROCESS_LIST |
7 | | -from constants.threads import THREAD_PROCESS_LIST |
8 | | -from constants.ui import UI_PADDING, ActionEvents |
| 7 | +from constants.threads import THREAD_PROCESS_LIST_DATA |
| 8 | +from constants.ui import UI_PADDING, ActionEvents, ERROR_TRYING_UPDATE_TERMINATED_TKINTER_INSTANCE |
9 | 9 | from enums.rules import RuleType |
10 | 10 | from enums.selector import SelectorType |
11 | 11 | from model.process import Process |
@@ -43,9 +43,6 @@ def __init__(self, master: Notebook, process_rules_list: RulesList, service_rule |
43 | 43 |
|
44 | 44 | super().__init__(master) |
45 | 45 |
|
46 | | - self._is_close = False |
47 | | - self.bind("<Destroy>", self._on_close) |
48 | | - |
49 | 46 | self._create_process_list() |
50 | 47 | self._create_progress_bar() |
51 | 48 | self._create_actions() |
@@ -74,64 +71,64 @@ def load_from_config(self, config: dict): |
74 | 71 | self._refresh() |
75 | 72 |
|
76 | 73 | def _update_process_list(self): |
77 | | - filter_by_type = self.actions.filterByType.get_enum_value() |
78 | | - search_query = self.actions.search.get().strip().lower() |
79 | | - |
80 | | - self.process_list.set_filter(filter_by_type, search_query) |
81 | | - self.process_list.update_ui() |
| 74 | + try: |
| 75 | + filter_by_type = self.actions.filterByType.get_enum_value() |
| 76 | + search_query = self.actions.search.get().strip().lower() |
82 | 77 |
|
83 | | - def _on_close(self, _=None): |
84 | | - self._is_close = True |
| 78 | + self.process_list.set_filter(filter_by_type, search_query) |
| 79 | + self.process_list.update_ui() |
| 80 | + except BaseException as e: |
| 81 | + if ERROR_TRYING_UPDATE_TERMINATED_TKINTER_INSTANCE not in str(e): |
| 82 | + LOG.exception("Update process list error") |
85 | 83 |
|
86 | 84 | def _refresh(self): |
87 | | - main_thread_not_in_mainloop_message = 'main thread is not in main loop' |
| 85 | + LOG.info("Refreshing process list...") |
| 86 | + |
| 87 | + def update_process_list(): |
| 88 | + LOG.info("Updating process list...") |
| 89 | + |
| 90 | + try: |
| 91 | + self._update_process_list() |
| 92 | + finally: |
| 93 | + self._refresh_state() |
| 94 | + |
| 95 | + def load_data(): |
| 96 | + LOG.info("Loading data...") |
| 97 | + |
| 98 | + try: |
| 99 | + self.process_list.set_data(ProcessesInfoService.get_processes(False)) |
| 100 | + self.after(0, update_process_list) |
| 101 | + except BaseException as e: |
| 102 | + if ERROR_TRYING_UPDATE_TERMINATED_TKINTER_INSTANCE not in str(e): |
| 103 | + LOG.exception("Load data error") |
| 104 | + |
| 105 | + self._refresh_state() |
88 | 106 |
|
89 | 107 | try: |
90 | 108 | self._refresh_state(True) |
91 | 109 | self.process_list.clear() |
92 | 110 |
|
93 | | - def load(): |
94 | | - try: |
95 | | - try: |
96 | | - self.process_list.set_data(ProcessesInfoService.get_processes(False)) |
97 | | - |
98 | | - def do_ui_update(): |
99 | | - if self._is_close: |
100 | | - return |
101 | | - |
102 | | - try: |
103 | | - try: |
104 | | - self._update_process_list() |
105 | | - finally: |
106 | | - self._refresh_state() |
107 | | - except BaseException as e: |
108 | | - if str(e) != main_thread_not_in_mainloop_message: |
109 | | - LOG.exception("Refresh error") |
110 | | - |
111 | | - if self._is_close: |
112 | | - return |
113 | | - |
114 | | - self.after(0, do_ui_update) |
115 | | - finally: |
116 | | - self._refresh_state() |
117 | | - except BaseException as e: |
118 | | - if str(e) != main_thread_not_in_mainloop_message: |
119 | | - LOG.exception("Refresh error") |
120 | | - |
121 | | - TaskScheduler.schedule_task(THREAD_PROCESS_LIST, load) |
122 | | - except: |
| 111 | + TaskScheduler.schedule_task(THREAD_PROCESS_LIST_DATA, load_data) |
| 112 | + except BaseException as e: |
| 113 | + if ERROR_TRYING_UPDATE_TERMINATED_TKINTER_INSTANCE not in str(e): |
| 114 | + LOG.exception("Refresh error") |
| 115 | + |
123 | 116 | self._refresh_state() |
124 | | - LOG.exception("Refresh error") |
125 | 117 |
|
126 | 118 | def _refresh_state(self, lock: bool = False): |
127 | | - actions = self.actions |
128 | | - actions.refresh['state'] = DISABLED if lock else NORMAL |
129 | | - |
130 | | - progress_bar = self._progress_bar |
131 | | - if lock: |
132 | | - progress_bar.place(relx=0.5, rely=0.5, anchor=CENTER) |
133 | | - else: |
134 | | - progress_bar.place_forget() |
| 119 | + try: |
| 120 | + actions = self.actions |
| 121 | + actions.refresh['state'] = DISABLED if lock else NORMAL |
| 122 | + |
| 123 | + progress_bar = self._progress_bar |
| 124 | + |
| 125 | + if lock: |
| 126 | + progress_bar.place(relx=0.5, rely=0.5, anchor=CENTER) |
| 127 | + else: |
| 128 | + progress_bar.place_forget() |
| 129 | + except BaseException as e: |
| 130 | + if ERROR_TRYING_UPDATE_TERMINATED_TKINTER_INSTANCE not in str(e): |
| 131 | + LOG.exception("Refresh state error") |
135 | 132 |
|
136 | 133 | def save_to_config(self, config: dict): |
137 | 134 | pass |
|
0 commit comments