source: sasview/src/sas/qtgui/Perspectives/Fitting/FittingPerspective.py @ 68c96d3

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 68c96d3 was 68c96d3, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

fix the data passing to fitting

  • Property mode set to 100755
File size: 2.4 KB
Line 
1import sys
2
3from PyQt4 import QtCore
4from PyQt4 import QtGui
5
6from FittingWidget import FittingWidget
7
8class FittingWindow(QtGui.QTabWidget):
9    """
10    """
11    name = "Fitting" # For displaying in the combo box in DataExplorer
12    def __init__(self, manager=None, parent=None, data=None):
13        super(FittingWindow, self).__init__()
14
15        self.manager = manager
16        self.parent = parent
17        self._data = data
18
19        # List of active fits
20        self.tabs = []
21
22        # Max index for adding new, non-clashing tab names
23        self.maxIndex = 0
24
25        # Index of the current tab
26        self.currentTab = 0
27
28        # The current optimizer
29        self.optimizer = 'DREAM'
30
31        # The tabs need to be closeable
32        self.setTabsClosable(True)
33
34        # Initialize the first tab
35        self.addFit(None)
36
37        # Deal with signals
38        self.tabCloseRequested.connect(self.tabCloses)
39
40        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
41
42    def addFit(self, data):
43        """
44        Add a new tab for passed data
45        """
46        tab     = FittingWidget(manager=self.manager, parent=self.parent, data=data)
47        self.tabs.append(tab)
48        self.maxIndex += 1
49        self.addTab(tab, self.tabName())
50
51    def tabName(self):
52        """
53        Get the new tab name, based on the number of fitting tabs so far
54        """
55        page_name = "FitPage" + str(self.maxIndex)
56        return page_name
57
58    def tabCloses(self, index):
59        """
60        Update local bookkeeping on tab close
61        """
62        assert(len(self.tabs) >= index)
63        # don't remove the last tab
64        if len(self.tabs) <= 1:
65            return
66        del self.tabs[index]
67        self.removeTab(index)
68
69    def allowBatch(self):
70        """
71        Tell the caller that we accept multiple data instances
72        """
73        return True
74
75    def setData(self, data_item=None):
76        """
77        Assign new dataset to the fitting instance
78        """
79        assert(data_item is not None)
80
81        # Find an unassigned tab.
82        # If none, open a new tab.
83        available_tabs = list(map(lambda tab:tab.acceptsData(), self.tabs))
84
85        if True in available_tabs:
86            self.tabs[available_tabs.index(True)].data = data_item
87        else:
88            self.addFit(data_item)
89
90
91if __name__ == "__main__":
92    app = QtGui.QApplication([])
93    dlg = FittingWindow()
94    dlg.show()
95    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.