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