[4992ff2] | 1 | from PyQt5 import QtCore |
---|
| 2 | from PyQt5 import QtGui |
---|
| 3 | from PyQt5 import QtWidgets |
---|
[ef01be4] | 4 | |
---|
| 5 | import sas.sasview |
---|
[cd2cc745] | 6 | from sas.qtgui.UI import main_resources_rc |
---|
[ef01be4] | 7 | |
---|
[cd2cc745] | 8 | from sas.qtgui.UI import main_resources_rc |
---|
[83eb5208] | 9 | from sas.qtgui.Plotting.UI.ScalePropertiesUI import Ui_scalePropertiesUI |
---|
[ef01be4] | 10 | |
---|
| 11 | x_values = ["x", "x^(2)", "x^(4)", "ln(x)", "log10(x)", "log10(x^(4))"] |
---|
| 12 | y_values = ["y", "1/y", "ln(y)", "y^(2)", "y*x^(2)", "y*x^(4)", "1/sqrt(y)", |
---|
| 13 | "log10(y)", "ln(y*x)", "ln(y*x^(2))", "ln(y*x^(4))", "log10(y*x^(4))"] |
---|
[54492dc] | 14 | view_values = ["--", "Linear y vs x", "log(y) vs log(x)", "Guinier lny vs x^(2)", |
---|
[ef01be4] | 15 | "XS Guinier ln(y*x) vs x^(2)", "Porod y*x^(4) vs x^(4)", "Kratky y*x^(2) vs x"] |
---|
| 16 | view_to_xy = { |
---|
| 17 | view_values[0]: [None, None], # custom |
---|
| 18 | view_values[1]: [0, 0], # linear |
---|
[54492dc] | 19 | view_values[2]: [4, 7], # log |
---|
| 20 | view_values[3]: [1, 2], # Guinier |
---|
| 21 | view_values[4]: [1, 8], # XS Guinier |
---|
| 22 | view_values[5]: [2, 5], # Porod |
---|
| 23 | view_values[6]: [0, 4], # Kratky |
---|
[ef01be4] | 24 | } |
---|
[4992ff2] | 25 | class ScaleProperties(QtWidgets.QDialog, Ui_scalePropertiesUI): |
---|
[3b7b218] | 26 | def __init__(self, parent=None, init_scale_x='x', init_scale_y='y'): |
---|
[ef01be4] | 27 | super(ScaleProperties, self).__init__(parent) |
---|
| 28 | self.setupUi(self) |
---|
| 29 | |
---|
| 30 | # Set up comboboxes |
---|
| 31 | self.cbX.addItems(x_values) |
---|
| 32 | self.cbY.addItems(y_values) |
---|
| 33 | self.cbView.addItems(view_values) |
---|
| 34 | # Resize the dialog only AFTER the boxes are populated |
---|
| 35 | self.setFixedSize(self.minimumSizeHint()) |
---|
| 36 | |
---|
[3b7b218] | 37 | # Set up the initial values for x and y. |
---|
| 38 | # This avoids keeping a QModel instance here. |
---|
| 39 | if init_scale_x in x_values and init_scale_y in y_values: |
---|
| 40 | self.cbX.setCurrentIndex(x_values.index(init_scale_x)) |
---|
| 41 | self.cbY.setCurrentIndex(y_values.index(init_scale_y)) |
---|
| 42 | |
---|
[ef01be4] | 43 | # Connect combobox index change to a custom method |
---|
| 44 | self.cbView.currentIndexChanged.connect(self.viewIndexChanged) |
---|
[6d05e1d] | 45 | self.cbX.currentIndexChanged.connect(self.xyIndexChanged) |
---|
| 46 | self.cbY.currentIndexChanged.connect(self.xyIndexChanged) |
---|
[ef01be4] | 47 | |
---|
| 48 | def getValues(self): |
---|
| 49 | """ |
---|
| 50 | Return current values from comboboxes |
---|
| 51 | """ |
---|
[fed94a2] | 52 | return str(self.cbX.currentText()), str(self.cbY.currentText()) |
---|
[ef01be4] | 53 | |
---|
| 54 | def viewIndexChanged(self, index): |
---|
| 55 | """ |
---|
| 56 | Update X and Y labels based on the "View" index |
---|
| 57 | """ |
---|
| 58 | if index > 0: |
---|
[6d05e1d] | 59 | # Disable signals so xyIndexChanged() doesn't get called |
---|
| 60 | self.cbX.blockSignals(True) |
---|
| 61 | self.cbY.blockSignals(True) |
---|
| 62 | |
---|
| 63 | # Update the sub-controls |
---|
[ef01be4] | 64 | self.cbX.setCurrentIndex(view_to_xy[view_values[index]][0]) |
---|
| 65 | self.cbY.setCurrentIndex(view_to_xy[view_values[index]][1]) |
---|
[6d05e1d] | 66 | # Re-enable the signals |
---|
| 67 | |
---|
| 68 | self.cbX.blockSignals(False) |
---|
| 69 | self.cbY.blockSignals(False) |
---|
| 70 | |
---|
| 71 | def xyIndexChanged(self, index): |
---|
| 72 | """ |
---|
| 73 | Update View label based on the "X" and "Y" index |
---|
| 74 | """ |
---|
| 75 | self.cbView.setCurrentIndex(0) |
---|