ui.py

changeset 21
c36e549a7f12
parent 20
fdfbe5d7b677
child 27
a347387868be
--- a/ui.py	Sat Jan 20 23:50:36 2018 +0000
+++ b/ui.py	Sun Jan 21 00:58:06 2018 +0000
@@ -7,6 +7,7 @@
 import datetime
 import logging
 from threading import Lock
+import objc
 
 INACTIVE=0
 ACTIVE=1
@@ -74,7 +75,7 @@
         # Operation running
         progress=''
         if 'progress_current' in status and 'progress_total' in status:
-            progress=' %d%%' % (status.progress_current/status.progress_total)
+            progress=' %d%%' % (status['progress_current']/status['progress_total'])
         elif 'original_size' in status and 'deduplicated_size' in status:
             progress=' %s→%s' % (humanbytes(status['original_size']),
                                  humanbytes(status['deduplicated_size']))
@@ -107,8 +108,8 @@
                 b=backups[index]
                 # Python closures suck dog's balls; hence the _index=index hack
                 # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/
-                cb=(lambda obj, status, _index=index:
-                    self.__status_callback(obj, _index, status))
+                cb=(lambda obj, status, _index=index, errors=None:
+                    self.__status_callback(obj, _index, status, errors))
                 b.set_status_update_callback(cb)
                 self.statuses[index]=b.status()
 
@@ -144,8 +145,9 @@
         logging.debug("Manually backup '%s'", b.name)
         b.create(None)
 
-    def __status_callback(self, obj, index, status):
+    def __status_callback(self, obj, index, status, errorlog):
         logging.debug('Status callbackup %s' % str(status))
+
         with self.lock:
             self.statuses[index]=status
             logging.debug('Rebuilding menu')
@@ -154,5 +156,25 @@
             self.menu.update(menu)
             self.title=traynames[active]
 
+        if errorlog:
+            if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str):
+                msgid='UnknownError'
+            else:
+                msgid=errorlog['msgid']
+
+            logging.debug('Opening notification for error')
+
+            # Workaround to rumps brokenness
+            # See https://github.com/jaredks/rumps/issues/59
+            NSDictionary = objc.lookUpClass("NSDictionary")
+            d=NSDictionary()
+
+            rumps.notification('Borgend', msgid, errorlog['message'], data=d)
+
+    @rumps.notifications
+    def notification_center(data):
+        pass
 
 
+
+

mercurial