--- a/ui.py Sun Jan 21 02:44:52 2018 +0000 +++ b/ui.py Sun Jan 21 11:57:47 2018 +0000 @@ -6,7 +6,7 @@ import time import datetime import logging -from threading import Lock +from threading import Lock, Timer import objc INACTIVE=0 @@ -21,6 +21,9 @@ ERRORS: 'B?' } +# Refresh the menu at most once a second to reduce flicker +refresh_interval=1.0 + def combine_state(state1, state2): return max(state1, state2) @@ -115,6 +118,8 @@ menu, state=self.__rebuild_menu() + self.refresh_timer=None + super().__init__(traynames[state], menu=menu, quit_button=None) def __rebuild_menu(self): @@ -145,16 +150,24 @@ logging.debug("Manually backup '%s'", b.name) b.create(None) + + def refresh_ui(self): + with self.lock: + self.refresh_timer=None + logging.debug('Rebuilding menu') + self.menu.clear() + menu, active=self.__rebuild_menu() + self.menu.update(menu) + self.title=traynames[active] + 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') - self.menu.clear() - menu, active=self.__rebuild_menu() - self.menu.update(menu) - self.title=traynames[active] + if self.refresh_timer==None: + self.refresh_timer=Timer(refresh_interval, self.refresh_ui) + self.refresh_timer.start() if errorlog: if 'msgid' not in errorlog or not isinstance(errorlog['msgid'], str):