source: sasview/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py @ 6c8fb2c

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 6c8fb2c was 6c8fb2c, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fitting options - connected GUI to logic.
Minor UI redesign of fitting options tab.

  • Property mode set to 100755
File size: 3.5 KB
RevLine 
[4c7dd9f]1import sys
[6f7f652]2import numpy
[0efe791]3
[4c7dd9f]4from PyQt4 import QtCore
[60af928]5from PyQt4 import QtGui
[4c7dd9f]6
[5236449]7import sas.qtgui.GuiUtils as GuiUtils
8
[60af928]9from FittingWidget import FittingWidget
[6c8fb2c]10from FitPage import FitPage
[8bdb6f5]11
[60af928]12class FittingWindow(QtGui.QTabWidget):
[0efe791]13    """
14    """
[60af928]15    name = "Fitting" # For displaying in the combo box in DataExplorer
[811bec1]16    def __init__(self, parent=None, data=None):
[f46f6dc]17        super(FittingWindow, self).__init__()
18
19        self.parent = parent
20        self._data = data
21
22        # List of active fits
23        self.tabs = []
24
25        # Max index for adding new, non-clashing tab names
26        self.maxIndex = 0
27
28        # Index of the current tab
29        self.currentTab = 0
30
31        # The current optimizer
32        self.optimizer = 'DREAM'
33
34        # The tabs need to be closeable
35        self.setTabsClosable(True)
[60af928]36
[811bec1]37        self.communicate = self.parent.communicator()
38
[60af928]39        # Initialize the first tab
[f46f6dc]40        self.addFit(None)
41
42        # Deal with signals
43        self.tabCloseRequested.connect(self.tabCloses)
44
[b1e36a3]45        # Perspective window not allowed to close by default
46        self._allow_close = False
47
[f46f6dc]48        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
[60af928]49
[b1e36a3]50    def setClosable(self, value=True):
51        """
52        Allow outsiders close this widget
53        """
54        assert isinstance(value, bool)
55
56        self._allow_close = value
57
58    def closeEvent(self, event):
59        """
60        Overwrite QDialog close method to allow for custom widget close
61        """
62        if self._allow_close:
63            # reset the closability flag
64            self.setClosable(value=False)
65            event.accept()
66        else:
67            event.ignore()
68            # Maybe we should just minimize
69            self.setWindowState(QtCore.Qt.WindowMinimized)
70
[60af928]71    def addFit(self, data):
72        """
73        Add a new tab for passed data
74        """
[811bec1]75        tab     = FittingWidget(parent=self.parent, data=data, id=self.maxIndex+1)
[f46f6dc]76        self.tabs.append(tab)
77        self.maxIndex += 1
78        self.addTab(tab, self.tabName())
79
80    def tabName(self):
81        """
82        Get the new tab name, based on the number of fitting tabs so far
83        """
84        page_name = "FitPage" + str(self.maxIndex)
85        return page_name
86
87    def tabCloses(self, index):
88        """
89        Update local bookkeeping on tab close
90        """
[cbcdd2c]91        assert len(self.tabs) >= index
[f46f6dc]92        # don't remove the last tab
93        if len(self.tabs) <= 1:
94            return
95        del self.tabs[index]
96        self.removeTab(index)
97
98    def allowBatch(self):
99        """
100        Tell the caller that we accept multiple data instances
101        """
102        return True
103
[68c96d3]104    def setData(self, data_item=None):
[f46f6dc]105        """
106        Assign new dataset to the fitting instance
[5236449]107        Obtain a QStandardItem object and dissect it to get Data1D/2D
108        Pass it over to the calculator
[f46f6dc]109        """
[cbcdd2c]110        assert data_item is not None
[68c96d3]111
[5236449]112        if not isinstance(data_item, list):
113            msg = "Incorrect type passed to the Fitting Perspective"
114            raise AttributeError, msg
115
116        if not isinstance(data_item[0], QtGui.QStandardItem):
117            msg = "Incorrect type passed to the Fitting Perspective"
118            raise AttributeError, msg
119
[454670d]120        for data in data_item:
121            # Find the first unassigned tab.
122            # If none, open a new tab.
123            available_tabs = list(map(lambda tab: tab.acceptsData(), self.tabs))
124
125            if numpy.any(available_tabs):
126                self.tabs[available_tabs.index(True)].data = data
127            else:
128                self.addFit(data)
Note: See TracBrowser for help on using the repository browser.