source: sasview/src/sas/qtgui/Calculators/KiessigPanel.py @ ccdee50

ESS_GUIESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_openclESS_GUI_sync_sascalc
Last change on this file since ccdee50 was ccdee50, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 5 years ago

Set focus away from the Close button. SASVIEW-1161

  • Property mode set to 100644
File size: 2.3 KB
Line 
1from PyQt5 import QtCore
2from PyQt5 import QtGui
3from PyQt5 import QtWidgets
4
5from sas.qtgui.UI import main_resources_rc
6from .UI.KiessigPanel import Ui_KiessigPanel
7import sas.qtgui.Utilities.GuiUtils as GuiUtils
8
9# sas-global
10from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator
11
12
13class KiessigPanel(QtWidgets.QDialog, Ui_KiessigPanel):
14    def __init__(self, parent=None):
15        super(KiessigPanel, self).__init__()
16        self.setupUi(self)
17
18        self.setWindowTitle("Kiessig Thickness Calculator")
19
20        self.manager = parent
21        self.thickness = KiessigThicknessCalculator()
22
23        rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?")
24        self.deltaq_in.setValidator(QtGui.QRegExpValidator(rx, self.deltaq_in))
25
26        # signals
27        self.helpButton.clicked.connect(self.onHelp)
28        self.computeButton.setVisible(False)
29        self.closeButton.clicked.connect(self.onClose)
30        self.deltaq_in.textChanged.connect(self.onCompute)
31        self.deltaq_in.setText("0.05")
32
33        # Set focus away from Close
34        self.computeButton.setFocus()
35
36        # no reason to have this widget resizable
37        self.setFixedSize(self.minimumSizeHint())
38
39    def onHelp(self):
40        """
41        Bring up the Kiessig fringe calculator Documentation whenever
42        the HELP button is clicked.
43        Calls DocumentationWindow with the path of the location within the
44        documentation tree (after /doc/ ....".
45        """
46        location = "/user/qtgui/Calculators/kiessig_calculator_help.html"
47        self.manager.showHelp(location)
48
49    def onCompute(self):
50        """
51        Execute the computation of thickness
52        """
53        try:
54            self.thickness.set_deltaq(dq=float(self.deltaq_in.text()))
55            kiessing_result = self.thickness.compute_thickness()
56            if kiessing_result:
57                float_as_str = "{:.3f}".format(kiessing_result)
58                self.lengthscale_out.setText(float_as_str)
59            else:
60                # error or division by zero
61                self.lengthscale_out.setText("")
62
63        except (ArithmeticError, ValueError):
64            self.lengthscale_out.setText("")
65
66    def onClose(self):
67        """
68        close the window containing this panel
69        """
70        self.close()
Note: See TracBrowser for help on using the repository browser.