140 self.statuses[index]=b.status() |
140 self.statuses[index]=b.status() |
141 |
141 |
142 menu, state=self.__rebuild_menu() |
142 menu, state=self.__rebuild_menu() |
143 |
143 |
144 self.refresh_timer=None |
144 self.refresh_timer=None |
145 self.logwindow=None |
|
146 |
145 |
147 super().__init__(traynames[state], menu=menu, quit_button=None) |
146 super().__init__(traynames[state], menu=menu, quit_button=None) |
148 |
147 |
149 def __rebuild_menu(self): |
148 def __rebuild_menu(self): |
150 menu=[] |
149 menu=[] |
162 elif this_state>=OFFLINE: |
161 elif this_state>=OFFLINE: |
163 item.state=-1 |
162 item.state=-1 |
164 menu.append(item) |
163 menu.append(item) |
165 state=combine_state(state, this_state) |
164 state=combine_state(state, this_state) |
166 |
165 |
167 menu_log=rumps.MenuItem("Show log", callback=self.showlog) |
166 menu_log=rumps.MenuItem("Show log", callback=lambda _: showlog()) |
168 menu.append(menu_log) |
167 menu.append(menu_log) |
169 |
168 |
170 if not settings['no_quit_menu_entry']: |
169 if not settings['no_quit_menu_entry']: |
171 menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit) |
170 menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit) |
172 menu.append(menu_quit) |
171 menu.append(menu_quit) |
215 except Exception as err: |
214 except Exception as err: |
216 utils.log_exception(logger, err) |
215 utils.log_exception(logger, err) |
217 notification_workaround(borgend.appname_stylised, |
216 notification_workaround(borgend.appname_stylised, |
218 err.__class__.__name__, str(err)) |
217 err.__class__.__name__, str(err)) |
219 |
218 |
220 @rumps.notifications |
219 # |
221 def notification_center(data): |
220 # Log window |
222 pass |
221 # |
223 |
222 |
224 def showlog(self, _): |
223 logwindow=[None] |
225 try: |
224 logwindow_lock=Lock() |
226 if not self.logwindow: |
225 |
|
226 def showlog(): |
|
227 try: |
|
228 w=None |
|
229 with logwindow_lock: |
|
230 if not logwindow[0]: |
227 lines=borgend.fifolog.formatAll() |
231 lines=borgend.fifolog.formatAll() |
228 msg="\n".join(lines[0:]) |
232 msg="\n".join(lines[0:]) |
229 self.logwindow=rumps.Window(title=borgend.appname_stylised+' log', |
233 w=rumps.Window(title=borgend.appname_stylised+' log', |
230 default_text=msg, |
234 default_text=msg, |
231 ok='Close', |
235 ok='Close', |
232 dimensions=(640,320)) |
236 dimensions=(640,320)) |
233 self.logwindow.run() |
237 logwindow[0]=w |
234 # Does not return until closed |
238 if w: |
235 self.logwindow=None |
239 try: |
236 except Exception as err: |
240 w.run() |
237 utils.log_exception(logger, err) |
241 finally: |
238 |
242 with logwindow_lock: |
|
243 logwindow[0]=None |
|
244 except Exception as err: |
|
245 utils.log_exception(logger, err) |
|
246 |
|
247 # |
|
248 # Notification click response => show log window |
|
249 # |
|
250 |
|
251 @rumps.notifications |
|
252 def notification_center(_): |
|
253 showlog() |