source: sasview/src/sas/qtgui/SlitSizeCalculator.py @ 253e7170

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 253e7170 was 253e7170, checked in by wojciech, 7 years ago

Loading data using simple loader

  • Property mode set to 100644
File size: 3.9 KB
Line 
1from PyQt4 import QtGui
2from PyQt4 import QtCore
3from UI.SlitSizeCalculator import Ui_SlitSizeCalculator
4from sas.sascalc.dataloader.loader import Loader
5from sas.sasgui.guiframe.dataFitting import Data1D
6from sas.sasgui.guiframe.dataFitting import Data2D
7from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator
8
9import sys
10
11class SlitSizeCalculator(QtGui.QDialog, Ui_SlitSizeCalculator):
12    def __init__(self, parent=None, guimanager=None, manager=None):
13        super(SlitSizeCalculator, self).__init__()
14        self.setupUi(self)
15
16        self.setWindowTitle("Slit Size Calculator")
17        self._parent = parent
18        self._guimanager = guimanager
19        self._manager = manager
20
21        self.thickness = SlitlengthCalculator()
22
23        # signals
24        self.helpButton.clicked.connect(self.onHelp)
25        self.browseButton.clicked.connect(self.onBrowse)
26        self.closeButton.clicked.connect(self.onClose)
27
28        # no reason to have this widget resizable
29        self.setFixedSize(self.minimumSizeHint())
30
31    def onHelp(self):
32        """
33        Bring up the Kiessig fringe calculator Documentation whenever
34        the HELP button is clicked.
35        Calls DocumentationWindow with the path of the location within the
36        documentation tree (after /doc/ ....".
37        """
38        try:
39            location = self._parent.HELP_DIRECTORY_LOCATION + \
40                "/user/sasgui/perspectives/calculator/slit_calculator_help.html"
41
42            self._parent._helpView.load(QtCore.QUrl(location))
43            self._parent._helpView.show()
44        except AttributeError:
45            # No manager defined - testing and standalone runs
46            pass
47
48    def onBrowse(self):
49        """
50        Execute the computation of thickness
51        """
52        path_str = self.chooseFile()
53        if not path_str:
54            return
55        loader = Loader()
56        data = loader.load(path_str)
57
58        self.deltaq_in.setText(path_str)
59        #We are loading data for one model only therefor index 0
60        self.complete_loading(data)
61        #Complete loading here
62
63    def chooseFile(self):
64        """
65        Shows the Open file dialog and returns the chosen path(s)
66        """
67
68        # Location is automatically saved - no need to keep track of the last dir
69        # But only with Qt built-in dialog (non-platform native)
70        path = QtGui.QFileDialog.getOpenFileName(self, "Choose a file", "",
71                "SAS data 1D (*.txt *.TXT *.dat *.DAT)", None,
72                QtGui.QFileDialog.DontUseNativeDialog)
73        if path is None:
74            return
75
76        if isinstance(path, QtCore.QString):
77            path = str(path)
78
79        return path
80
81    def onClose(self):
82        """
83        close the window containing this panel
84        """
85        self.close()
86
87    def complete_loading(self, data=None):
88        """
89            Complete the loading and compute the slit size
90        """
91
92        if data is None:
93            msg = "ERROR: Data hasn't been loaded correctly"
94            raise RuntimeError, msg
95
96        if isinstance(data, Data2D):
97            msg = "Slit Length cannot be computed for 2D Data"
98            raise Exception, msg
99
100        #compute the slit size
101        try:
102             x = data.x
103             y = data.y
104             if x == [] or  x is None or y == [] or y is None:
105                 msg = "The current data is empty please check x and y"
106                 raise ValueError, msg
107             slit_length_calculator = SlitlengthCalculator()
108             slit_length_calculator.set_data(x=x, y=y)
109             slit_length = slit_length_calculator.calculate_slit_length()
110        except:
111             msg = "Slit Size Calculator: %s" % (sys.exc_value)
112             raise RuntimeError, msg
113
114        print("Slit lenght", slit_length)
115        self.lengthscale_out.setText(str(slit_length))
116        #Display unit
117        self.lineEdit.setText("[UNKNOWN]")
118
Note: See TracBrowser for help on using the repository browser.