1 | from PyQt4 import QtGui |
---|
2 | from PyQt4 import QtCore |
---|
3 | from UI.SlitSizeCalculator import Ui_SlitSizeCalculator |
---|
4 | |
---|
5 | # sas-global |
---|
6 | from sas.sascalc.calculator.slit_length_calculator import SlitlengthCalculator |
---|
7 | |
---|
8 | |
---|
9 | class SlitSizeCalculator(QtGui.QDialog, Ui_SlitSizeCalculator): |
---|
10 | def __init__(self, parent=None): |
---|
11 | super(SlitSizeCalculator, self).__init__() |
---|
12 | self.setupUi(self) |
---|
13 | |
---|
14 | self.setWindowTitle("Slit Size Calculator") |
---|
15 | self._parent = parent |
---|
16 | |
---|
17 | self.thickness = SlitlengthCalculator() |
---|
18 | |
---|
19 | # signals |
---|
20 | self.helpButton.clicked.connect(self.onHelp) |
---|
21 | self.browseButton.clicked.connect(self.onBrowse) |
---|
22 | self.closeButton.clicked.connect(self.onClose) |
---|
23 | |
---|
24 | # no reason to have this widget resizable |
---|
25 | self.setFixedSize(self.minimumSizeHint()) |
---|
26 | |
---|
27 | def onHelp(self): |
---|
28 | """ |
---|
29 | Bring up the Kiessig fringe calculator Documentation whenever |
---|
30 | the HELP button is clicked. |
---|
31 | Calls DocumentationWindow with the path of the location within the |
---|
32 | documentation tree (after /doc/ ....". |
---|
33 | """ |
---|
34 | try: |
---|
35 | location = self._parent.HELP_DIRECTORY_LOCATION + \ |
---|
36 | "/user/sasgui/perspectives/calculator/slit_lenght_calculator.html" |
---|
37 | |
---|
38 | self._parent._helpView.load(QtCore.QUrl(location)) |
---|
39 | self._parent._helpView.show() |
---|
40 | except AttributeError: |
---|
41 | # No manager defined - testing and standalone runs |
---|
42 | pass |
---|
43 | |
---|
44 | def onBrowse(self): |
---|
45 | """ |
---|
46 | Execute the computation of thickness |
---|
47 | """ |
---|
48 | path_str = self.chooseFiles() |
---|
49 | if not path_str: |
---|
50 | return |
---|
51 | self.loadFromURL(path_str) |
---|
52 | |
---|
53 | def loadFromURL(self, url): |
---|
54 | """ |
---|
55 | Threaded file load |
---|
56 | """ |
---|
57 | load_thread = threads.deferToThread(self.readData, url) |
---|
58 | load_thread.addCallback(self.loadComplete) |
---|
59 | |
---|
60 | def chooseFiles(self): |
---|
61 | """ |
---|
62 | Shows the Open file dialog and returns the chosen path(s) |
---|
63 | """ |
---|
64 | |
---|
65 | # Location is automatically saved - no need to keep track of the last dir |
---|
66 | # But only with Qt built-in dialog (non-platform native) |
---|
67 | paths = QtGui.QFileDialog.getOpenFileNames(self, "Choose a file", "", |
---|
68 | "Scattering data (*.DAT, *.dat)", None, QtGui.QFileDialog.DontUseNativeDialog) |
---|
69 | if paths is None: |
---|
70 | return |
---|
71 | |
---|
72 | if isinstance(paths, QtCore.QStringList): |
---|
73 | paths = [str(f) for f in paths] |
---|
74 | |
---|
75 | if not isinstance(paths, list): |
---|
76 | paths = [paths] |
---|
77 | |
---|
78 | return paths |
---|
79 | |
---|
80 | def onClose(self): |
---|
81 | """ |
---|
82 | close the window containing this panel |
---|
83 | """ |
---|
84 | self.close() |
---|