From 7d7d21df3172aaab1769df9170be676d00914887 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Fri, 22 Sep 2023 18:13:01 +0200 Subject: [PATCH] Improved/fixed category manager --- src/sas/qtgui/MainWindow/CategoryManager.py | 9 +++++++-- src/sas/qtgui/MainWindow/GuiManager.py | 19 ------------------- .../Perspectives/Fitting/FittingWidget.py | 3 ++- src/sas/qtgui/Utilities/CategoryInstaller.py | 8 ++++++-- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/sas/qtgui/MainWindow/CategoryManager.py b/src/sas/qtgui/MainWindow/CategoryManager.py index fa9ceabb5d..ecda013a61 100644 --- a/src/sas/qtgui/MainWindow/CategoryManager.py +++ b/src/sas/qtgui/MainWindow/CategoryManager.py @@ -129,7 +129,6 @@ def categoryList(self): return self.category_list - class CategoryManager(QtWidgets.QDialog, Ui_CategoryManagerUI): def __init__(self, parent=None, manager=None): super(CategoryManager, self).__init__(parent) @@ -195,7 +194,8 @@ def initializeModelList(self): empty_item.setEditable(False) # Add a checkbox to it item.setCheckable(True) - item.setCheckState(QtCore.Qt.Checked) + checked = self.categories.model_enabled_dict[model] + item.setCheckState(QtCore.Qt.Checked if checked else QtCore.Qt.Unchecked) item.setEditable(False) current_category = self.categories.modelToCategory()[model] self._category_model.appendRow([item, empty_item]) @@ -217,6 +217,7 @@ def initializeSignals(self): # Signals from the list selectionModel = self.lstCategory.selectionModel() selectionModel.selectionChanged.connect(self.onListSelection) + self._category_model.itemChanged.connect(self.onListChanged) def onClose(self): @@ -229,6 +230,10 @@ def onClose(self): self.close() + def onListChanged(self, item): + # remember the state of the checkbox + self.categories.model_enabled_dict[item.text()] = item.checkState() == QtCore.Qt.Checked + def selectedModels(self): """ Returns a list of selected models diff --git a/src/sas/qtgui/MainWindow/GuiManager.py b/src/sas/qtgui/MainWindow/GuiManager.py index 008baa0011..a63fc012a2 100644 --- a/src/sas/qtgui/MainWindow/GuiManager.py +++ b/src/sas/qtgui/MainWindow/GuiManager.py @@ -98,9 +98,6 @@ def __init__(self, parent=None): # Add signal callbacks self.addCallbacks() - # Assure model categories are available - self.addCategories() - # Create the data manager # TODO: pull out all required methods from DataManager and reimplement self._data_manager = DataManager() @@ -236,21 +233,6 @@ def closeAllPerspectives(self): self.loadedPerspectives = {} self._current_perspective = None - @staticmethod - def addCategories(): - """ - Make sure categories.json exists and if not compile it and install in ~/.sasview - """ - try: - from sas.sascalc.fit.models import ModelManager - from sas.qtgui.Utilities.CategoryInstaller import CategoryInstaller - model_list = ModelManager().cat_model_list() - CategoryInstaller.check_install(model_list=model_list) - except Exception: - import traceback - logger.error("%s: could not load SasView models") - logger.error(traceback.format_exc()) - def updatePlotItems(self, graphs): """ Wrapper for adding/removing actions in the windows menu @@ -263,7 +245,6 @@ def updatePlotItems(self, graphs): else: self.addPlotItemsInWindowsMenu(plot) - def addPlotItemsInWindowsMenu(self, plot): """ Dynamically update the QMenu content and assign signals diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py index fc89951667..4272355929 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py @@ -1681,7 +1681,8 @@ def onSelectCategory(self): # Populate the models combobox self.cbModel.blockSignals(True) self.cbModel.addItem(MODEL_DEFAULT) - self.cbModel.addItems(sorted([model for (model, _) in model_list if model != 'rpa'])) + models_to_show = [m[0] for m in model_list if m[0] != 'rpa' and m[1]] + self.cbModel.addItems(sorted(models_to_show)) self.cbModel.blockSignals(False) def onPolyModelChange(self, top, bottom): diff --git a/src/sas/qtgui/Utilities/CategoryInstaller.py b/src/sas/qtgui/Utilities/CategoryInstaller.py index b2ee7c5418..90e2bb89c7 100644 --- a/src/sas/qtgui/Utilities/CategoryInstaller.py +++ b/src/sas/qtgui/Utilities/CategoryInstaller.py @@ -107,18 +107,22 @@ def check_install(homedir = None, model_list=None): for ind in range(len(master_category_dict[cat])): model_name, enabled = master_category_dict[cat][ind] if model_name not in _model_list: + # if not enabled: del_name = True try: by_model_dict.pop(model_name) - model_enabled_dict.pop(model_name) + if not enabled: + model_enabled_dict.pop(model_name) except: logging.error("CategoryInstaller: %s", sys.exc_info()[1]) else: add_list.remove(model_name) + if not enabled: + model_enabled_dict.pop(model_name) if del_name or (len(add_list) > 0): for model in add_list: model_enabled_dict[model]= True - if _model_dict[model].category is None or len(str(_model_dict[model].category.capitalize())) == 0: + if _model_dict[model].category is None or not _model_dict[model].category: by_model_dict[model].append('Uncategorized') else: category = _model_dict[model].category