Skip to content

Commit

Permalink
Improved/fixed category manager
Browse files Browse the repository at this point in the history
  • Loading branch information
rozyczko committed Sep 22, 2023
1 parent d4e3a80 commit 7d7d21d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
9 changes: 7 additions & 2 deletions src/sas/qtgui/MainWindow/CategoryManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand All @@ -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):
Expand All @@ -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
Expand Down
19 changes: 0 additions & 19 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -263,7 +245,6 @@ def updatePlotItems(self, graphs):
else:
self.addPlotItemsInWindowsMenu(plot)


def addPlotItemsInWindowsMenu(self, plot):
"""
Dynamically update the QMenu content and assign signals
Expand Down
3 changes: 2 additions & 1 deletion src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions src/sas/qtgui/Utilities/CategoryInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d7d21d

Please sign in to comment.