source: sasview/src/sas/qtgui/PlotProperties.py @ 239214f

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 239214f was 239214f, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Remove graph properties - MPL dialog is enough.
Minor fix in Plot Properties (WP review)

  • Property mode set to 100755
File size: 3.4 KB
Line 
1from PyQt4 import QtGui
2
3import sas.sasview
4
5from sas.qtgui.PlotUtilities import COLORS, SHAPES
6
7from sas.qtgui.UI.PlotPropertiesUI import Ui_PlotPropertiesUI
8
9class PlotProperties(QtGui.QDialog, Ui_PlotPropertiesUI):
10    """ Dialog for modification of single plot properties """
11    def __init__(self,
12                 parent=None,
13                 color=0,
14                 marker=0,
15                 marker_size=5,
16                 legend=""):
17        super(PlotProperties, self).__init__(parent)
18        self.setupUi(self)
19        self.setFixedSize(self.minimumSizeHint())
20
21        self._parent = parent
22        self._marker = marker if marker else 0
23        self._color = color if color else 0
24        self._legend = legend
25        self._markersize = marker_size if marker_size else 5
26        self.custom_color = False
27
28        # Fill out the color combobox
29        self.cbColor.addItems(COLORS.keys()[:-1])
30        # data1d.custom_color can now be a simple integer,
31        # specifying COLORS dict index or a string containing
32        # the hex RGB value, e.g. #00FF00
33        if isinstance(self._color, int):
34            self.cbColor.setCurrentIndex(self._color)
35        else:
36            # Need the Custom entry here. "Custom" is always last.
37            self.cbColor.addItems([COLORS.keys()[-1]])
38            self.cbColor.setCurrentIndex(COLORS.keys().index("Custom"))
39
40        # Fill out the marker combobox
41        self.cbShape.addItems(SHAPES.keys())
42        self.cbShape.setCurrentIndex(self._marker)
43        if self._legend:
44            self.txtLegend.setText(self._legend)
45        self.sbSize.setValue(self._markersize)
46
47        # Connect slots
48        self.cmdCustom.clicked.connect(self.onColorChange)
49        self.cbColor.currentIndexChanged.connect(self.onColorIndexChange)
50
51    def legend(self):
52        ''' return current legend '''
53        return str(self.txtLegend.text())
54
55    def marker(self):
56        ''' return the current shape index in SHAPE '''
57        return self.cbShape.currentIndex()
58
59    def markersize(self):
60        ''' return marker size (int) '''
61        return self.sbSize.value()
62
63    def color(self):
64        ''' return current color: index in COLORS or a hex string '''
65        if self.custom_color:
66            return self._color
67        else:
68            return self.cbColor.currentIndex()
69
70    def onColorChange(self, event):
71        """
72        Pop up the standard Qt color change dialog
73        """
74        # Pick up the chosen color
75        self._color = QtGui.QColorDialog.getColor(parent=self)
76        # Update the text control
77        if self._color.isValid():
78            # Block currentIndexChanged
79            self.cbColor.blockSignals(True)
80            # Add Custom to the color combo box
81            self.cbColor.addItems(["Custom"])
82            self.cbColor.setCurrentIndex(COLORS.keys().index("Custom"))
83            # unblock currentIndexChanged
84            self.cbColor.blockSignals(False)
85            # Save the color as #RRGGBB
86            self.custom_color = True
87            self._color = str(self._color.name())
88   
89    def onColorIndexChange(self, index):
90        """
91        Dynamically add/remove "Custom" color index
92        """
93        # Changed index - assure Custom is deleted
94        custom_index = self.cbColor.findText("Custom")
95        self.custom_color = False
96        if custom_index > -1:
97            self.cbColor.removeItem(custom_index)
98
99        pass # debug hook
100       
Note: See TracBrowser for help on using the repository browser.