source: sasview/src/sas/qtgui/PlotProperties.py @ 8595edd

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 8595edd was 0f3c22d, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Code review for SASVIEW-383

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