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

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

QModel items conversion into SasModel? parameters + data display SASVIEW-535

  • Property mode set to 100755
File size: 2.9 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    name = "Fitting" # For displaying in the combo box in DataExplorer
15    def __init__(self, manager=None, parent=None, data=None):
16        super(FittingWindow, self).__init__()
17
18        self.manager = manager
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        # Initialize the first tab
38        self.addFit(None)
39
40        # Deal with signals
41        self.tabCloseRequested.connect(self.tabCloses)
42
43        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
44
45        #self.communicate = GuiUtils.Communicate()
46        self.communicate = self.parent.communicator()
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
57    def tabName(self):
58        """
59        Get the new tab name, based on the number of fitting tabs so far
60        """
61        page_name = "FitPage" + str(self.maxIndex)
62        return page_name
63
64    def tabCloses(self, index):
65        """
66        Update local bookkeeping on tab close
67        """
68        assert len(self.tabs) >= index
69        # don't remove the last tab
70        if len(self.tabs) <= 1:
71            return
72        del self.tabs[index]
73        self.removeTab(index)
74
75    def allowBatch(self):
76        """
77        Tell the caller that we accept multiple data instances
78        """
79        return True
80
81    def setData(self, data_item=None):
82        """
83        Assign new dataset to the fitting instance
84        Obtain a QStandardItem object and dissect it to get Data1D/2D
85        Pass it over to the calculator
86        """
87        assert data_item is not None
88
89        if not isinstance(data_item, list):
90            msg = "Incorrect type passed to the Fitting Perspective"
91            raise AttributeError, msg
92
93        if not isinstance(data_item[0], QtGui.QStandardItem):
94            msg = "Incorrect type passed to the Fitting Perspective"
95            raise AttributeError, msg
96
97        self._model_item = data_item[0]
98
99        # Find the first unassigned tab.
100        # If none, open a new tab.
101        available_tabs = list(map(lambda tab: tab.acceptsData(), self.tabs))
102
103        if numpy.any(available_tabs):
104            self.tabs[available_tabs.index(True)].data = data_item
105        else:
106            self.addFit(data_item)
Note: See TracBrowser for help on using the repository browser.