[4992ff2] | 1 | from PyQt5 import QtCore |
---|
| 2 | from PyQt5 import QtGui |
---|
| 3 | from PyQt5 import QtWidgets |
---|
[cd2cc745] | 4 | |
---|
| 5 | from sas.qtgui.UI import main_resources_rc |
---|
[b3e8629] | 6 | from .UI.KiessigPanel import Ui_KiessigPanel |
---|
[b0c5e8c] | 7 | import sas.qtgui.Utilities.GuiUtils as GuiUtils |
---|
[363fbfa] | 8 | |
---|
| 9 | # sas-global |
---|
| 10 | from sas.sascalc.calculator.kiessig_calculator import KiessigThicknessCalculator |
---|
| 11 | |
---|
| 12 | |
---|
[4992ff2] | 13 | class KiessigPanel(QtWidgets.QDialog, Ui_KiessigPanel): |
---|
[363fbfa] | 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 | |
---|
[040529d] | 23 | self.deltaq_in.setText("0.05") |
---|
| 24 | |
---|
[363fbfa] | 25 | # signals |
---|
[040529d] | 26 | self.helpButton.clicked.connect(self.onHelp) |
---|
| 27 | self.computeButton.clicked.connect(self.onCompute) |
---|
| 28 | self.closeButton.clicked.connect(self.onClose) |
---|
[363fbfa] | 29 | |
---|
| 30 | # no reason to have this widget resizable |
---|
| 31 | self.setFixedSize(self.minimumSizeHint()) |
---|
| 32 | |
---|
[040529d] | 33 | def onHelp(self): |
---|
[363fbfa] | 34 | """ |
---|
| 35 | Bring up the Kiessig fringe calculator Documentation whenever |
---|
| 36 | the HELP button is clicked. |
---|
| 37 | Calls DocumentationWindow with the path of the location within the |
---|
| 38 | documentation tree (after /doc/ ....". |
---|
| 39 | """ |
---|
[aed0532] | 40 | location = "/user/qtgui/Calculators/kiessig_calculator_help.html" |
---|
[e90988c] | 41 | self.manager.showHelp(location) |
---|
[363fbfa] | 42 | |
---|
[040529d] | 43 | def onCompute(self): |
---|
[363fbfa] | 44 | """ |
---|
| 45 | Execute the computation of thickness |
---|
| 46 | """ |
---|
| 47 | try: |
---|
| 48 | self.thickness.set_deltaq(dq=float(self.deltaq_in.text())) |
---|
| 49 | kiessing_result = self.thickness.compute_thickness() |
---|
[fbfc488] | 50 | if kiessing_result: |
---|
| 51 | float_as_str = "{:.3f}".format(kiessing_result) |
---|
| 52 | self.lengthscale_out.setText(float_as_str) |
---|
| 53 | else: |
---|
| 54 | # error or division by zero |
---|
| 55 | self.lengthscale_out.setText("") |
---|
| 56 | |
---|
[363fbfa] | 57 | except (ArithmeticError, ValueError): |
---|
| 58 | self.lengthscale_out.setText("") |
---|
| 59 | |
---|
[040529d] | 60 | def onClose(self): |
---|
[363fbfa] | 61 | """ |
---|
| 62 | close the window containing this panel |
---|
| 63 | """ |
---|
| 64 | self.close() |
---|