ui.py

changeset 76
4b08fca3ce34
parent 75
2a44b9649212
child 78
83b43987e61e
--- a/ui.py	Sat Jan 27 12:19:39 2018 +0000
+++ b/ui.py	Sun Jan 28 00:11:18 2018 +0000
@@ -8,6 +8,7 @@
 import logging
 import borgend
 import backup
+import sleep
 from threading import Lock, Timer
 from config import settings
 import objc
@@ -154,31 +155,25 @@
     def __init__(self, backups):
         self.lock=Lock()
         self.backups=backups
+        self.refresh_timer=None
+        self.refresh_timer_time=None
         self.statuses=[None]*len(backups)
 
-        with self.lock:
-            # Initialise reporting callbacks and local status copy
-            # (since rumps doesn't seem to be able to update menu items
-            # without rebuilding the whole menu, and we don't want to lock
-            # when calling Backup.status(), especially as we will be called
-            # from Backup reporting its status, we keep a copy to allow
-            # rebuilding the entire menu
-            for index in range(len(backups)):
-                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 status, errors=None, _index=index:
-                    self.__status_callback(_index, status, errorlog=errors))
-                b.set_status_update_callback(cb)
-                self.statuses[index]=b.status()
+        for index in range(len(backups)):
+            self.statuses[index]=backups[index].status()
+
+        menu, title=self.build_menu_and_timer()
+
+        super().__init__(title, menu=menu, quit_button=None)
 
-            self.refresh_timer=None
-            self.refresh_timer_time=None
+        for index in range(len(backups)):
+            # 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 status, errors=None, _index=index:
+                self.__status_callback(_index, status, errorlog=errors))
+            backups[index].set_status_update_callback(cb)
 
-            menu, title=self.build_menu_and_timer()
-
-            super().__init__(title, menu=menu, quit_button=None)
-
+        sleep.add_callback(self, self.refresh_ui)
 
     def __rebuild_menu(self):
         menu=[]

mercurial