Sat, 20 Jan 2018 20:34:23 +0000
New tray title: B. or B! depending on activity
ui.py | file | annotate | diff | comparison | revisions |
--- a/ui.py Sat Jan 20 19:57:05 2018 +0000 +++ b/ui.py Sat Jan 20 20:34:23 2018 +0000 @@ -8,7 +8,10 @@ import logging from threading import Lock +traynames={False: 'B.', True: 'B!'} + def make_title(status): + active=False if status['type']=='scheduled': # Operation scheduled when=status['when'] @@ -29,13 +32,16 @@ detail='' if 'detail' in status and status['detail']: detail=status['detail']+' ' - return "%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) + title="%s (%s%s %s)" % (status['name'], detail, status['operation'], whenstr) elif status['type']=='current': # Operation running - return "%s (running: %s)" % (status['name'], status['operation']) + title="%s (running: %s)" % (status['name'], status['operation']) + active=True else: # status['type']=='nothing': # Should be unscheduled, nothing running - return status['name'] + title=status['name'] + + return title, active class BorgendTray(rumps.App): @@ -60,15 +66,16 @@ b.set_status_update_callback(cb) self.statuses[index]=b.status() - menu=self.__rebuild_menu() + menu, active=self.__rebuild_menu() - super().__init__(name, menu=menu, quit_button=None) + super().__init__(traynames[active], menu=menu, quit_button=None) def __rebuild_menu(self): menu=[] + active=False for index in range(len(self.backups)): b=self.backups[index] - title=make_title(self.statuses[index]) + title, this_active=make_title(self.statuses[index]) logging.info('TITLE: %s' % title) # Python closures suck dog's balls... # first and the last program I write in Python until somebody @@ -76,11 +83,12 @@ cbm=lambda sender, _b=b: self.__menu_select_backup(sender, _b) item=rumps.MenuItem(title, callback=cbm) menu.append(item) + active=active or this_active menu_quit=rumps.MenuItem("Quit...", callback=self.my_quit) menu.append(menu_quit) - return menu + return menu, active def my_quit(self, _): @@ -97,7 +105,10 @@ self.statuses[index]=status logging.debug('Rebuilding menu') self.menu.clear() - self.menu.update(self.__rebuild_menu()) + menu, active=self.__rebuild_menu() + print(active) + self.menu.update(menu) + self.title=traynames[active]