| 152 |
153 |
| 153 class BorgendTray(rumps.App): |
154 class BorgendTray(rumps.App): |
| 154 def __init__(self, backups): |
155 def __init__(self, backups): |
| 155 self.lock=Lock() |
156 self.lock=Lock() |
| 156 self.backups=backups |
157 self.backups=backups |
| |
158 self.refresh_timer=None |
| |
159 self.refresh_timer_time=None |
| 157 self.statuses=[None]*len(backups) |
160 self.statuses=[None]*len(backups) |
| 158 |
161 |
| 159 with self.lock: |
162 for index in range(len(backups)): |
| 160 # Initialise reporting callbacks and local status copy |
163 self.statuses[index]=backups[index].status() |
| 161 # (since rumps doesn't seem to be able to update menu items |
164 |
| 162 # without rebuilding the whole menu, and we don't want to lock |
165 menu, title=self.build_menu_and_timer() |
| 163 # when calling Backup.status(), especially as we will be called |
166 |
| 164 # from Backup reporting its status, we keep a copy to allow |
167 super().__init__(title, menu=menu, quit_button=None) |
| 165 # rebuilding the entire menu |
168 |
| 166 for index in range(len(backups)): |
169 for index in range(len(backups)): |
| 167 b=backups[index] |
170 # Python closures suck dog's balls; hence the _index=index hack |
| 168 # Python closures suck dog's balls; hence the _index=index hack |
171 # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/ |
| 169 # See also http://math.andrej.com/2009/04/09/pythons-lambda-is-broken/ |
172 cb=(lambda status, errors=None, _index=index: |
| 170 cb=(lambda status, errors=None, _index=index: |
173 self.__status_callback(_index, status, errorlog=errors)) |
| 171 self.__status_callback(_index, status, errorlog=errors)) |
174 backups[index].set_status_update_callback(cb) |
| 172 b.set_status_update_callback(cb) |
175 |
| 173 self.statuses[index]=b.status() |
176 sleep.add_callback(self, self.refresh_ui) |
| 174 |
|
| 175 self.refresh_timer=None |
|
| 176 self.refresh_timer_time=None |
|
| 177 |
|
| 178 menu, title=self.build_menu_and_timer() |
|
| 179 |
|
| 180 super().__init__(title, menu=menu, quit_button=None) |
|
| 181 |
|
| 182 |
177 |
| 183 def __rebuild_menu(self): |
178 def __rebuild_menu(self): |
| 184 menu=[] |
179 menu=[] |
| 185 state=(backup.State.INACTIVE, backup.Errors.OK) |
180 state=(backup.State.INACTIVE, backup.Errors.OK) |
| 186 need_reconstruct=None |
181 need_reconstruct=None |