From d458e1e416b0f8a6d5de25be8c158c2099ff06f4 Mon Sep 17 00:00:00 2001 From: Matt Clifford Date: Tue, 6 Aug 2024 13:22:49 +0100 Subject: [PATCH] keep checked menu items on loading new --- IQM_Vis/UI/main.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/IQM_Vis/UI/main.py b/IQM_Vis/UI/main.py index 0779671..337b130 100644 --- a/IQM_Vis/UI/main.py +++ b/IQM_Vis/UI/main.py @@ -184,33 +184,48 @@ def closeEvent(self, event): def get_menu_checkboxes(self): ''' list all trans/metrics in the menu drop downs ''' - # transformations self.menu_options = {'transforms': {}, 'metrics': {}, 'metric_images': {}} + # check if we need to restore current checked + if hasattr(self, 'restore_checked_menu_items'): + restrict_options = self.restore_checked_menu_items + else: # or building for the first time + restrict_options = self.restrict_options + + # make menus set_checked_menu_from_iterable(self.menu_bar, self.transformations, 'Transforms', self.menu_options['transforms'], self.construct_UI, - self.restrict_options['transforms']) + restrict_options['transforms']) set_checked_menu_from_iterable(self.menu_bar, self.data_stores[0].metric_images, 'Metric Images', self.menu_options['metric_images'], self.construct_UI, - self.restrict_options['metric_images']) + restrict_options['metric_images']) set_checked_menu_from_iterable(self.menu_bar, self.data_stores[0].metrics, 'Metrics', self.menu_options['metrics'], self.construct_UI, - self.restrict_options['metrics']) + restrict_options['metrics']) def _remake_menu(self): + self._save_checked_menu_items() self.menu_bar.clear() self.make_menu() + def _save_checked_menu_items(self): + self.restore_checked_menu_items = {} + for menu in ['transforms', 'metric_images', 'metrics']: + self.restore_checked_menu_items[menu] = {} + for item in self.menu_options[menu]: + self.restore_checked_menu_items[menu][item] = self.menu_options[menu][item].isChecked() + + def make_status_bar(self): self.status_bar = self.statusBar() self.pbar = ProgressBar(self, minimum=0, maximum=100, textVisible=False, @@ -332,5 +347,10 @@ def set_checked_menu_from_iterable(main_menu, iterable, name, action_store, conn action_store[trans].setChecked(True) else: action_store[trans].setChecked(False) + elif isinstance(restrict_options, dict): + if trans in restrict_options.keys(): + action_store[trans].setChecked(restrict_options[trans]) + else: + action_store[trans].setChecked(False) else: action_store[trans].setChecked(True)