diff --git a/src/sas/qtgui/MainWindow/DataExplorer.py b/src/sas/qtgui/MainWindow/DataExplorer.py index 7170d87258..a74f854d61 100644 --- a/src/sas/qtgui/MainWindow/DataExplorer.py +++ b/src/sas/qtgui/MainWindow/DataExplorer.py @@ -780,6 +780,7 @@ def isItemReady(index): self._perspective().swapData(selected_items[0]) else: self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked()) + except Exception as ex: msg = "%s perspective returned the following message: \n%s\n" % (self._perspective().name, str(ex)) logging.error(ex, exc_info=True) diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py b/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py index 9208469f45..fc7f4ad08b 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py @@ -22,6 +22,12 @@ from sas.qtgui.Utilities.Reports.reportdata import ReportData +from sas import config +import time + +import logging +logger = logging.getLogger(__name__) + class FittingWindow(QtWidgets.QTabWidget, Perspective): """ """ @@ -263,9 +269,27 @@ def addFit(self, data, is_batch=False, tab_index=None): self.addTab(tab, icon, tab_name) # Show the new tab self.setCurrentWidget(tab) + # If configured, plot the current data + self.maybePlotOnLoad(tab) + # Notify listeners self.tabsModifiedSignal.emit() + def maybePlotOnLoad(self,tab): + if tab.data_is_loaded and config.FITTING_PLOT_ON_SEND_DATA: + #First, create model and residuals inside this data. + def tidyup(self): + logger.info(msg='calculation complete, running tidy-up function') + #time.sleep(2) + #tab.onPlot() + #QtWidgets.QApplication.processEvents() + tab.showPlot() + #QtWidgets.QApplication.processEvents() + #time.sleep(2) + tab._model_model.clear() + tab.cmdPlot.setEnabled(False) + tab.SASModelToQModel('porod') + tab.calculateQGridForModelExt(completefn= tidyup) def addConstraintTab(self): """ Add a new C&S fitting tab @@ -431,6 +455,7 @@ def setData(self, data_item=None, is_batch=False, tab_index=None): self.tabs[first_good_tab].data = data tab_name = str(self.tabText(first_good_tab)) self.updateFitDict(data, tab_name) + self.maybePlotOnLoad(self.tabs[first_good_tab]) else: self.addFit(data, is_batch=is_batch) diff --git a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py index b1ac8089f3..cf2b30aa55 100644 --- a/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py +++ b/src/sas/qtgui/Perspectives/Fitting/FittingWidget.py @@ -2238,7 +2238,7 @@ def _requestPlots(self, item_name, item_model): data_shown = False item = None for item, plot in plots.items(): - if fitpage_name in plot.name: + if plot.plot_role != Data1D.ROLE_DATA and fitpage_name in plot.name: data_shown = True self.communicate.plotRequestedSignal.emit([item, plot], self.tab_id) # return the last data item seen, if nothing was plotted; supposed to be just data) diff --git a/src/sas/qtgui/Utilities/Preferences/FittingPreferencesWidget.py b/src/sas/qtgui/Utilities/Preferences/FittingPreferencesWidget.py new file mode 100644 index 0000000000..481a167aac --- /dev/null +++ b/src/sas/qtgui/Utilities/Preferences/FittingPreferencesWidget.py @@ -0,0 +1,11 @@ +from sas.system import config + +from .PreferencesWidget import PreferencesWidget, config_value_setter_generator + + +class FittingPreferencesWidget(PreferencesWidget): + def __init__(self): + super(FittingPreferencesWidget, self).__init__("Fitting Settings") + self.addCheckBox(title="Auto-plot data when sent to fitting perspective", + callback=config_value_setter_generator('FITTING_PLOT_ON_SEND_DATA', dtype=bool), + checked=config.FITTING_PLOT_ON_SEND_DATA) \ No newline at end of file diff --git a/src/sas/qtgui/Utilities/Preferences/PlottingPreferencesWidget.py b/src/sas/qtgui/Utilities/Preferences/PlottingPreferencesWidget.py index 6c500a2ab6..72291d72b1 100644 --- a/src/sas/qtgui/Utilities/Preferences/PlottingPreferencesWidget.py +++ b/src/sas/qtgui/Utilities/Preferences/PlottingPreferencesWidget.py @@ -5,7 +5,7 @@ class PlottingPreferencesWidget(PreferencesWidget): def __init__(self): - super(PlottingPreferencesWidget, self).__init__("Plotting Options") + super(PlottingPreferencesWidget, self).__init__("Plotting Settings") self.addCheckBox(title="Use full-width plot legends (most compatible)?", callback=config_value_setter_generator('FITTING_PLOT_FULL_WIDTH_LEGENDS', dtype=bool), checked=config.FITTING_PLOT_FULL_WIDTH_LEGENDS) diff --git a/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py b/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py index 69220c0399..6483c958e7 100644 --- a/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py +++ b/src/sas/qtgui/Utilities/Preferences/PreferencesPanel.py @@ -7,17 +7,19 @@ from sas.qtgui.Utilities.Preferences.UI.PreferencesUI import Ui_preferencesUI from sas.qtgui.Utilities.Preferences.PreferencesWidget import PreferencesWidget from sas.qtgui.Utilities.Preferences.DisplayPreferencesWidget import DisplayPreferencesWidget - +from sas.qtgui.Utilities.Preferences.PlottingPreferencesWidget import PlottingPreferencesWidget +from sas.qtgui.Utilities.Preferences.FittingPreferencesWidget import FittingPreferencesWidget # The PreferencesPanel object will instantiate all widgets during its instantiation. # e.g: # `from foo.bar import BarWidget # BarWidget is a child of PreferencesWidget` # `BASE_PANELS = {"Bar Widget Options": BarWidget}` # PreferenceWidget Imports go here and then are added to the BASE_PANELS, but not instantiated. -from .PlottingPreferencesWidget import PlottingPreferencesWidget + # Pre-made option widgets BASE_PANELS = {"Plotting Settings":PlottingPreferencesWidget, "Display Settings":DisplayPreferencesWidget, + "Fitting Settings":FittingPreferencesWidget, } # Type: Dict[str, Union[Type[PreferencesWidget], Callable[[],QWidget]] logger = logging.getLogger(__name__) diff --git a/src/sas/system/config/config.py b/src/sas/system/config/config.py index 0508890a18..aaa04de60e 100644 --- a/src/sas/system/config/config.py +++ b/src/sas/system/config/config.py @@ -186,6 +186,9 @@ def __init__(self): self.QT_SCALE_FACTOR = 1.0 self.QT_AUTO_SCREEN_SCALE_FACTOR = False + # Auto-plot when sending data to Fitting + self.FITTING_PLOT_ON_SEND_DATA = True + # If True, use an ugly but more robust legend plotting method in Fitting that results in full- # width legends. self.FITTING_PLOT_FULL_WIDTH_LEGENDS = False