Skip to content

Commit

Permalink
Merge pull request #2721 from SasView/2712-annoying-behaviour-when-op…
Browse files Browse the repository at this point in the history
…ening-a-project

2712 annoying behaviour when opening a project
  • Loading branch information
lucas-wilkins committed Jan 17, 2024
2 parents 4f23e38 + dd14070 commit cc09ed0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
15 changes: 11 additions & 4 deletions src/sas/qtgui/MainWindow/GuiManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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)
Expand All @@ -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"
Expand Down

0 comments on commit cc09ed0

Please sign in to comment.