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

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

Started with unit tests for fitting widget SASVIEW-499

  • Property mode set to 100755
File size: 2.8 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, parent=None, data=None):
16        super(FittingWindow, self).__init__()
17
18        self.parent = parent
19        self._data = data
20
21        # List of active fits
22        self.tabs = []
23
24        # Max index for adding new, non-clashing tab names
25        self.maxIndex = 0
26
27        # Index of the current tab
28        self.currentTab = 0
29
30        # The current optimizer
31        self.optimizer = 'DREAM'
32
33        # The tabs need to be closeable
34        self.setTabsClosable(True)
35
36        self.communicate = self.parent.communicator()
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    def addFit(self, data):
47        """
48        Add a new tab for passed data
49        """
50        tab     = FittingWidget(parent=self.parent, data=data, id=self.maxIndex+1)
51        self.tabs.append(tab)
52        self.maxIndex += 1
53        self.addTab(tab, self.tabName())
54
55    def tabName(self):
56        """
57        Get the new tab name, based on the number of fitting tabs so far
58        """
59        page_name = "FitPage" + str(self.maxIndex)
60        return page_name
61
62    def tabCloses(self, index):
63        """
64        Update local bookkeeping on tab close
65        """
66        assert len(self.tabs) >= index
67        # don't remove the last tab
68        if len(self.tabs) <= 1:
69            return
70        del self.tabs[index]
71        self.removeTab(index)
72
73    def allowBatch(self):
74        """
75        Tell the caller that we accept multiple data instances
76        """
77        return True
78
79    def setData(self, data_item=None):
80        """
81        Assign new dataset to the fitting instance
82        Obtain a QStandardItem object and dissect it to get Data1D/2D
83        Pass it over to the calculator
84        """
85        assert data_item is not None
86
87        if not isinstance(data_item, list):
88            msg = "Incorrect type passed to the Fitting Perspective"
89            raise AttributeError, msg
90
91        if not isinstance(data_item[0], QtGui.QStandardItem):
92            msg = "Incorrect type passed to the Fitting Perspective"
93            raise AttributeError, msg
94
95        self._model_item = data_item[0]
96
97        # Find the first unassigned tab.
98        # If none, open a new tab.
99        available_tabs = list(map(lambda tab: tab.acceptsData(), self.tabs))
100
101        if numpy.any(available_tabs):
102            self.tabs[available_tabs.index(True)].data = data_item
103        else:
104            self.addFit(data_item)
Note: See TracBrowser for help on using the repository browser.