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

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

Default datasets for fitting SASVIEW-498

  • 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
10
11class FittingWindow(QtGui.QTabWidget):
12    """
13    """
14    updateTheoryFromPerspectiveSignal =  QtCore.pyqtSignal(QtGui.QStandardItem)
15    name = "Fitting" # For displaying in the combo box in DataExplorer
16    def __init__(self, manager=None, parent=None, data=None):
17        super(FittingWindow, self).__init__()
18
19        self.manager = manager
20        self.parent = parent
21        self._data = data
22
23        # List of active fits
24        self.tabs = []
25
26        # Max index for adding new, non-clashing tab names
27        self.maxIndex = 0
28
29        # Index of the current tab
30        self.currentTab = 0
31
32        # The current optimizer
33        self.optimizer = 'DREAM'
34
35        # The tabs need to be closeable
36        self.setTabsClosable(True)
37
38        # Initialize the first tab
39        self.addFit(None)
40
41        # Deal with signals
42        self.tabCloseRequested.connect(self.tabCloses)
43
44        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
45
46        self.communicate = GuiUtils.Communicate()
47
48    def addFit(self, data):
49        """
50        Add a new tab for passed data
51        """
52        tab     = FittingWidget(manager=self.manager, parent=self.parent, data=data, id=self.maxIndex+1)
53        self.tabs.append(tab)
54        self.maxIndex += 1
55        self.addTab(tab, self.tabName())
56        tab.signalTheory.connect(self.passSignal)
57
58    def tabName(self):
59        """
60        Get the new tab name, based on the number of fitting tabs so far
61        """
62        page_name = "FitPage" + str(self.maxIndex)
63        return page_name
64
65    def tabCloses(self, index):
66        """
67        Update local bookkeeping on tab close
68        """
69        assert(len(self.tabs) >= index)
70        # don't remove the last tab
71        if len(self.tabs) <= 1:
72            return
73        del self.tabs[index]
74        self.removeTab(index)
75
76    def allowBatch(self):
77        """
78        Tell the caller that we accept multiple data instances
79        """
80        return True
81
82    def setData(self, data_item=None):
83        """
84        Assign new dataset to the fitting instance
85        Obtain a QStandardItem object and dissect it to get Data1D/2D
86        Pass it over to the calculator
87        """
88        assert(data_item is not None)
89
90        if not isinstance(data_item, list):
91            msg = "Incorrect type passed to the Fitting Perspective"
92            raise AttributeError, msg
93
94        if not isinstance(data_item[0], QtGui.QStandardItem):
95            msg = "Incorrect type passed to the Fitting Perspective"
96            raise AttributeError, msg
97
98        self._model_item = data_item[0]
99
100        # Extract data on 1st child - this is the Data1D/2D component
101        data = GuiUtils.dataFromItem(self._model_item)
102
103        # self.model.item(WIDGETS.W_FILENAME).setData(QtCore.QVariant(self._model_item.text()))
104
105        # Find the first unassigned tab.
106        # If none, open a new tab.
107        available_tabs = list(map(lambda tab:tab.acceptsData(), self.tabs))
108
109        if numpy.any(available_tabs):
110            self.tabs[available_tabs.index(True)].data = data_item
111        else:
112            self.addFit(data_item)
113
114
115    def passSignal(self, theory_item):
116        """
117        """
118        self.updateTheoryFromPerspectiveSignal.emit(theory_item)
119
120if __name__ == "__main__":
121    app = QtGui.QApplication([])
122    dlg = FittingWindow()
123    dlg.show()
124    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.