From c7e0549ad44a0cc3c1acd6848b8b64c23294c2ad Mon Sep 17 00:00:00 2001 From: lucas-wilkins Date: Wed, 17 Jan 2024 04:20:22 +0000 Subject: [PATCH 1/2] Fixed bug with perspective choice on project load --- src/sas/qtgui/MainWindow/DataExplorer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sas/qtgui/MainWindow/DataExplorer.py b/src/sas/qtgui/MainWindow/DataExplorer.py index 112164eac4..01bca279aa 100644 --- a/src/sas/qtgui/MainWindow/DataExplorer.py +++ b/src/sas/qtgui/MainWindow/DataExplorer.py @@ -1030,6 +1030,10 @@ def updatePerspectiveCombo(self, index): Notify the gui manager about the new perspective chosen. """ + # Check that a valid index has been chosen, can happen in some cases such a loading projects + if index < 0: + return + # Notify via communicator self.communicator.perspectiveChangedSignal.emit(self.cbFitting.itemText(index)) From dd1407087fd22bf65e2cb592fab0a73687cd3a32 Mon Sep 17 00:00:00 2001 From: lucas-wilkins Date: Wed, 17 Jan 2024 05:04:53 +0000 Subject: [PATCH 2/2] Fix multiple copies of preference panels --- src/sas/qtgui/MainWindow/GuiManager.py | 15 +++++++++++---- .../Utilities/Preferences/PreferencesPanel.py | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/sas/qtgui/MainWindow/GuiManager.py b/src/sas/qtgui/MainWindow/GuiManager.py index 64237b234c..655a7f628e 100644 --- a/src/sas/qtgui/MainWindow/GuiManager.py +++ b/src/sas/qtgui/MainWindow/GuiManager.py @@ -207,20 +207,27 @@ def addWidgets(self): self.WhatsNew = WhatsNew(self) def loadAllPerspectives(self): + """ Load all the perspectives""" # Close any existing perspectives to prevent multiple open instances self.closeAllPerspectives() # Load all perspectives - loaded_dict = {} + loaded_dict = {} # dictionary that will ultimately keep track of all perspective instances for name, perspective in Perspectives.PERSPECTIVES.items(): try: + # Instantiate perspective loaded_perspective = perspective(parent=self) + + # Save in main dict loaded_dict[name] = loaded_perspective - pref_widgets = loaded_perspective.preferences - for widget in pref_widgets: - self.preferences.addWidget(widget) + + # Register the perspective with the prefernce object + self.preferences.registerPerspectivePreferences(loaded_perspective) + except Exception as e: logger.error(f"Unable to load {name} perspective.\n{e}") logger.error(e, exc_info=True) + + # attach loaded perspectives to this class self.loadedPerspectives = loaded_dict def closeAllPerspectives(self): diff --git a/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py b/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py index 784598996d..001d54bdb5 100644 --- a/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py +++ b/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py @@ -7,6 +7,9 @@ from typing import Optional, Callable, Dict, Any, Union, List from sas.system import config + +from sas.qtgui.Perspectives.perspective import Perspective + from sas.qtgui.Utilities.Preferences.UI.PreferencesUI import Ui_preferencesUI from sas.qtgui.Utilities.Preferences.PreferencesWidget import PreferencesWidget @@ -56,6 +59,8 @@ def __init__(self, parent: Optional[Any] = None): self.buttonBox.button(QDialogButtonBox.Help).clicked.connect(self.help) self._set_accept() + self.registered_perspectives: list[str] = [] + def addWidgets(self, widgets: Dict[str, Callable]): """Add a list of named widgets to the window""" for name, widget in widgets.items(): @@ -169,6 +174,7 @@ def close(self): def addWidget(self, widget: QWidget, name: Optional[str] = None): """Add a single widget to the panel""" + # Set the parent of the new widget to the parent of this window widget.parent = self self.stackedWidget.addWidget(widget) @@ -177,8 +183,19 @@ def addWidget(self, widget: QWidget, name: Optional[str] = None): name = name if name is not None else getattr(widget, 'name', None) name = name if name is not None else "Generic Preferences" # Add the widget default reset method to the global set + self.listWidget.addItem(name) + def registerPerspectivePreferences(self, perspective: Perspective): + """ Register preferences from a perspective""" + + if perspective.name not in self.registered_perspectives: + + for preference_widget in perspective.preferences: + + self.addWidget(preference_widget) + self.registered_perspectives.append(perspective.name) + def help(self): """Open the help window associated with the preferences window""" tree_location = "/user/qtgui/MainWindow/preferences_help.html"