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

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

Allow for multiple datasets to be opened by the fitting perspective

  • Property mode set to 100755
File size: 3.5 KB
RevLine 
[4c7dd9f]1import sys
[6f7f652]2import numpy
[0efe791]3
[4c7dd9f]4from PyQt4 import QtCore
[60af928]5from PyQt4 import QtGui
[4c7dd9f]6
[5236449]7import sas.qtgui.GuiUtils as GuiUtils
8
[60af928]9from FittingWidget import FittingWidget
[8bdb6f5]10
[60af928]11class FittingWindow(QtGui.QTabWidget):
[0efe791]12    """
13    """
[60af928]14    name = "Fitting" # For displaying in the combo box in DataExplorer
[811bec1]15    def __init__(self, parent=None, data=None):
[f46f6dc]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)
[60af928]35
[811bec1]36        self.communicate = self.parent.communicator()
37
[60af928]38        # Initialize the first tab
[f46f6dc]39        self.addFit(None)
40
41        # Deal with signals
42        self.tabCloseRequested.connect(self.tabCloses)
43
[b1e36a3]44        # Perspective window not allowed to close by default
45        self._allow_close = False
46
[f46f6dc]47        self.setWindowTitle('Fit panel - Active Fitting Optimizer: %s' % self.optimizer)
[60af928]48
[b1e36a3]49    def setClosable(self, value=True):
50        """
51        Allow outsiders close this widget
52        """
53        assert isinstance(value, bool)
54
55        self._allow_close = value
56
57    def closeEvent(self, event):
58        """
59        Overwrite QDialog close method to allow for custom widget close
60        """
61        if self._allow_close:
62            # reset the closability flag
63            self.setClosable(value=False)
64            event.accept()
65        else:
66            event.ignore()
67            # Maybe we should just minimize
68            self.setWindowState(QtCore.Qt.WindowMinimized)
69
[60af928]70    def addFit(self, data):
71        """
72        Add a new tab for passed data
73        """
[811bec1]74        tab     = FittingWidget(parent=self.parent, data=data, id=self.maxIndex+1)
[f46f6dc]75        self.tabs.append(tab)
76        self.maxIndex += 1
77        self.addTab(tab, self.tabName())
78
79    def tabName(self):
80        """
81        Get the new tab name, based on the number of fitting tabs so far
82        """
83        page_name = "FitPage" + str(self.maxIndex)
84        return page_name
85
86    def tabCloses(self, index):
87        """
88        Update local bookkeeping on tab close
89        """
[cbcdd2c]90        assert len(self.tabs) >= index
[f46f6dc]91        # don't remove the last tab
92        if len(self.tabs) <= 1:
93            return
94        del self.tabs[index]
95        self.removeTab(index)
96
97    def allowBatch(self):
98        """
99        Tell the caller that we accept multiple data instances
100        """
101        return True
102
[68c96d3]103    def setData(self, data_item=None):
[f46f6dc]104        """
105        Assign new dataset to the fitting instance
[5236449]106        Obtain a QStandardItem object and dissect it to get Data1D/2D
107        Pass it over to the calculator
[f46f6dc]108        """
[cbcdd2c]109        assert data_item is not None
[68c96d3]110
[5236449]111        if not isinstance(data_item, list):
112            msg = "Incorrect type passed to the Fitting Perspective"
113            raise AttributeError, msg
114
115        if not isinstance(data_item[0], QtGui.QStandardItem):
116            msg = "Incorrect type passed to the Fitting Perspective"
117            raise AttributeError, msg
118
[454670d]119        for data in data_item:
120            # Find the first unassigned tab.
121            # If none, open a new tab.
122            available_tabs = list(map(lambda tab: tab.acceptsData(), self.tabs))
123
124            if numpy.any(available_tabs):
125                self.tabs[available_tabs.index(True)].data = data
126            else:
127                self.addFit(data)
Note: See TracBrowser for help on using the repository browser.