ui.py

changeset 50
2d8947351727
parent 49
db33dfa64ad6
child 51
1614b2184bb4
equal deleted inserted replaced
49:db33dfa64ad6 50:2d8947351727
5 import rumps 5 import rumps
6 import time 6 import time
7 import datetime 7 import datetime
8 import logging 8 import logging
9 import borgend 9 import borgend
10 import utils
11 import backup 10 import backup
12 from threading import Lock, Timer 11 from threading import Lock, Timer
13 from config import settings 12 from config import settings
14 import objc 13 import objc
15 14
43 NSDictionary = objc.lookUpClass("NSDictionary") 42 NSDictionary = objc.lookUpClass("NSDictionary")
44 d=NSDictionary() 43 d=NSDictionary()
45 44
46 rumps.notification(title, subtitle, message, data=d) 45 rumps.notification(title, subtitle, message, data=d)
47 except Exception as err: 46 except Exception as err:
48 utils.log_exception(logger, err, 47 logger.exception("Failed to display notification")
49 detail='Unable to display notification')
50 48
51 # Based on code snatched from 49 # Based on code snatched from
52 # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 50 # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778
53 def humanbytes(B): 51 def humanbytes(B):
54 'Return the given bytes as a human friendly KB, MB, GB, or TB string' 52 'Return the given bytes as a human friendly KB, MB, GB, or TB string'
69 elif TB <= B: 67 elif TB <= B:
70 return '{0:.2f}TB'.format(B/TB) 68 return '{0:.2f}TB'.format(B/TB)
71 69
72 def make_title(status): 70 def make_title(status):
73 state=status['state'] 71 state=status['state']
72 detail=''
74 if status['type']=='scheduled': 73 if status['type']=='scheduled':
75 # Operation scheduled 74 # Operation scheduled
76 when=status['when'] 75 when=status['when']
77 now=time.time() 76 now=time.time()
78 if when<now: 77 if when<now:
176 self.menu.clear() 175 self.menu.clear()
177 self.menu.update(menu) 176 self.menu.update(menu)
178 self.title=traynames[active] 177 self.title=traynames[active]
179 178
180 def __status_callback(self, obj, index, status, errorlog): 179 def __status_callback(self, obj, index, status, errorlog):
181 logger.debug('Status callbackup %s' % str(status)) 180 logger.debug('Status callback: %s' % str(status))
182 181
183 with self.lock: 182 with self.lock:
184 self.statuses[index]=status 183 self.statuses[index]=status
185 if self.refresh_timer==None: 184 if self.refresh_timer==None:
186 self.refresh_timer=Timer(refresh_interval, self.refresh_ui) 185 self.refresh_timer=Timer(refresh_interval, self.refresh_ui)
206 #sender.state=not sender.state 205 #sender.state=not sender.state
207 logger.debug("Manually backup '%s'", b.name) 206 logger.debug("Manually backup '%s'", b.name)
208 try: 207 try:
209 b.create() 208 b.create()
210 except Exception as err: 209 except Exception as err:
211 utils.log_exception(logger, err) 210 logger.exception("Failure to initialise backup")
212 notification_workaround(borgend.appname_stylised, 211 notification_workaround(borgend.appname_stylised,
213 err.__class__.__name__, str(err)) 212 err.__class__.__name__, str(err))
214 213
215 # 214 #
216 # Log window 215 # Log window
236 w.run() 235 w.run()
237 finally: 236 finally:
238 with logwindow_lock: 237 with logwindow_lock:
239 logwindow[0]=None 238 logwindow[0]=None
240 except Exception as err: 239 except Exception as err:
241 utils.log_exception(logger, err) 240 logger.exception("Failed to display log")
242 241
243 # 242 #
244 # Notification click response => show log window 243 # Notification click response => show log window
245 # 244 #
246 245
247 @rumps.notifications 246 @rumps.notifications
248 def notification_center(_): 247 def notification_center(_):
249 showlog() 248 showlog()
249

mercurial