source: sasview/src/sas/qtgui/ScaleProperties.py @ 4d457df

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 4d457df was fed94a2, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Improved label formatting in charts

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