source: sasview/src/sas/qtgui/Perspectives/Corfunc/CorfuncPerspective.py @ 59183b7

Last change on this file since 59183b7 was 59183b7, checked in by Adam Washington <adam.washington@…>, 7 years ago

Start setting up Corfunc Models

  • Property mode set to 100644
File size: 3.9 KB
Line 
1# global
2import sys
3from PyQt4 import QtCore
4from PyQt4 import QtGui
5from PyQt4 import QtWebKit
6
7from twisted.internet import threads
8from twisted.internet import reactor
9
10# sas-global
11from sas.qtgui.Plotting.PlotterData import Data1D
12import sas.qtgui.Utilities.GuiUtils as GuiUtils
13
14# local
15from UI.CorfuncPanel import Ui_CorfuncDialog
16# from InvariantDetails import DetailsDialog
17from CorfuncUtils import WIDGETS as W
18
19
20class CorfuncWindow(QtGui.QDialog, Ui_CorfuncDialog):
21    # The controller which is responsible for managing signal slots connections
22    # for the gui and providing an interface to the data model.
23    name = "Corfunc" # For displaying in the combo box
24    #def __init__(self, manager=None, parent=None):
25    def __init__(self, parent=None):
26        #super(InvariantWindow, self).__init__(parent)
27        super(CorfuncWindow, self).__init__()
28        self.setupUi(self)
29
30        self.setWindowTitle("Corfunc Perspective")
31
32        self.model = QtGui.QStandardItemModel(self)
33        self.communicate = GuiUtils.Communicate()
34
35        # Connect buttons to slots.
36        # Needs to be done early so default values propagate properly.
37        self.setupSlots()
38
39        # Set up the model.
40        self.setupModel()
41
42        # Set up the mapper
43        self.setupMapper()
44
45    def setupSlots(self):
46        self.extractBtn.clicked.connect(self.action)
47        self.extrapolateBtn.clicked.connect(self.action)
48        self.transformBtn.clicked.connect(self.action)
49
50        self.hilbertBtn.clicked.connect(self.action)
51        self.fourierBtn.clicked.connect(self.action)
52
53    def setupModel(self):
54        self.model.setItem(W.W_QMIN,
55                           QtGui.QStandardItem("0"))
56        self.model.setItem(W.W_QMAX,
57                           QtGui.QStandardItem("0"))
58        self.model.setItem(W.W_QCUTOFF,
59                           QtGui.QStandardItem("0"))
60        self.model.setItem(W.W_BACKGROUND,
61                           QtGui.QStandardItem("0"))
62        self.model.setItem(W.W_TRANSFORM,
63                           QtGui.QStandardItem("Fourier"))
64
65    def setupMapper(self):
66        self.mapper = QtGui.QDataWidgetMapper(self)
67        self.mapper.setOrientation(QtCore.Qt.Vertical)
68        self.mapper.setModel(self.model)
69
70        self.mapper.addMapping(self.qMin, W.W_QMIN)
71        self.mapper.addMapping(self.qMax1, W.W_QMAX)
72        self.mapper.addMapping(self.qMax2, W.W_QCUTOFF)
73        self.mapper.addMapping(self.bg, W.W_BACKGROUND)
74
75        self.mapper.toFirst()
76
77
78    def action(self):
79        print("Called an action!")
80        print(self.model)
81        print(self.mapper)
82
83    def allowBatch(self):
84        """
85        We cannot perform corfunc analysis in batch at this time.
86        """
87        return False
88
89    def setData(self, data_item, is_batch=False):
90        """
91        Obtain a QStandardItem object and dissect it to get Data1D/2D
92        Pass it over to the calculator
93        """
94        if not isinstance(data_item, list):
95            msg = "Incorrect type passed to the Corfunc Perpsective"
96            raise AttributeError(msg)
97
98        if not isinstance(data_item[0], QtGui.QStandardItem):
99            msg = "Incorrect type passed to the Corfunc Perspective"
100            raise AttributeError(msg)
101
102        self._model_item = data_item[0]
103        data = GuiUtils.dataFromItem(self._model_item)
104
105        # self.model.item(WIDGETS.W_FILENAME).setData(QtCoreQVariant(self._model_item.text()))
106
107    def setClosable(self, value=True):
108        """
109        Allow outsiders close this widget
110        """
111        assert isinstance(value, bool)
112
113        self._allow_close = value
114
115
116if __name__ == "__main__":
117    app = QtGui.QApplication([])
118    import qt4reactor
119    # qt4reactor.install()
120    # DO NOT move the following import to the top!
121    # (unless you know what you're doing)
122    from twisted.internet import reactor
123    dlg = CorfuncWindow(reactor)
124    print(dlg)
125    dlg.show()
126    # print(reactor)
127    # reactor.run()
128    sys.exit(app.exec_())
Note: See TracBrowser for help on using the repository browser.