ui.py

changeset 32
06fc14211ba9
parent 31
b4b4bb7a2ec5
child 33
91421eeb4426
equal deleted inserted replaced
31:b4b4bb7a2ec5 32:06fc14211ba9
27 # Refresh the menu at most once a second to reduce flicker 27 # Refresh the menu at most once a second to reduce flicker
28 refresh_interval=1.0 28 refresh_interval=1.0
29 29
30 def combine_state(state1, state2): 30 def combine_state(state1, state2):
31 return max(state1, state2) 31 return max(state1, state2)
32
33 # Workaround to rumps brokenness;
34 # see https://github.com/jaredks/rumps/issues/59
35 def notification_workaround(title, subtitle, message):
36 NSDictionary = objc.lookUpClass("NSDictionary")
37 d=NSDictionary()
38
39 rumps.notification(title, subtitle, message, data=d)
32 40
33 # Based on code snatched from 41 # Based on code snatched from
34 # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778 42 # https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb/37423778
35 def humanbytes(B): 43 def humanbytes(B):
36 'Return the given bytes as a human friendly KB, MB, GB, or TB string' 44 'Return the given bytes as a human friendly KB, MB, GB, or TB string'
167 if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str): 175 if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str):
168 msgid='UnknownError' 176 msgid='UnknownError'
169 else: 177 else:
170 msgid=errorlog['msgid'] 178 msgid=errorlog['msgid']
171 179
172 logger.debug('Opening notification for error') 180 logger.debug("Opening notification for error %s '%s'",
173 181 msgid, errorlog['message'])
174 # Workaround to rumps brokenness 182
175 # See https://github.com/jaredks/rumps/issues/59 183 notification_workaround('Borgend', msgid, errorlog['message'])
176 NSDictionary = objc.lookUpClass("NSDictionary")
177 d=NSDictionary()
178
179 rumps.notification('Borgend', msgid, errorlog['message'], data=d)
180 184
181 def my_quit(self, _): 185 def my_quit(self, _):
182 rumps.quit_application() 186 rumps.quit_application()
183 187
184 def __menu_select_backup(self, sender, b): 188 def __menu_select_backup(self, sender, b):
185 #sender.state=not sender.state 189 #sender.state=not sender.state
186 logger.debug("Manually backup '%s'", b.name) 190 logger.debug("Manually backup '%s'", b.name)
187 b.create(None) 191 try:
192 b.create(None)
193 except Exception as err:
194 logger.debug("Opening notification for exception %s '%s'",
195 err.__class__.__name__, str(err))
196 notification_workaround('Borgend', err.__class__.__name__, str(err))
188 197
189 @rumps.notifications 198 @rumps.notifications
190 def notification_center(data): 199 def notification_center(data):
191 pass 200 pass
192 201
193
194
195

mercurial