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
Line 
1import sys
2import numpy
3
4from PyQt4 import QtCore
5from PyQt4 import QtGui
6
7import sas.qtgui.GuiUtils as GuiUtils
8
9from FittingWidget import FittingWidget
10from FitPage import FitPage
11
12class FittingWindow(QtGui.QTabWidget):
13    """
14    """
15    name = "Fitting" # For displaying in the combo box in DataExplorer
16    def __init__(self, parent=None, data=None):
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)
36
37        self.communicate = self.parent.communicator()
38
39        # Initialize the first tab
40        self.addFit(None)
41
42        # Deal with signals
43        self.tabCloseRequested.connect(self.tabCloses)
44
45        # Perspective window not allowed to close by default
46        self._allow_close = False
47
48        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
49
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
71    def addFit(self, data):
72        """
73        Add a new tab for passed data
74        """
75        tab     = FittingWidget(parent=self.parent, data=data, id=self.maxIndex+1)
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        """
91        assert len(self.tabs) >= index
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
104    def setData(self, data_item=None):
105        """
106        Assign new dataset to the fitting instance
107        Obtain a QStandardItem object and dissect it to get Data1D/2D
108        Pass it over to the calculator
109        """
110        assert data_item is not None
111
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
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.