source: sasview/src/sas/qtgui/Plotting/PlotProperties.py @ 83eb5208

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

Putting files in more ordered fashion

  • Property mode set to 100644
File size: 3.5 KB
Line 
1from PyQt4 import QtGui
2
3from sas.qtgui.Plotting.PlotUtilities import COLORS, SHAPES
4
5from sas.qtgui.Plotting.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        try:
41            self.cbShape.setCurrentIndex(self._marker)
42        except TypeError:
43            marker_index = self.cbShape.findText(self._marker)
44            self.cbShape.setCurrentIndex(marker_index)
45        if self._legend:
46            self.txtLegend.setText(self._legend)
47        self.sbSize.setValue(self._markersize)
48
49        # Connect slots
50        self.cmdCustom.clicked.connect(self.onColorChange)
51        self.cbColor.currentIndexChanged.connect(self.onColorIndexChange)
52
53    def legend(self):
54        ''' return current legend '''
55        return str(self.txtLegend.text())
56
57    def marker(self):
58        ''' return the current shape index in SHAPE '''
59        return self.cbShape.currentIndex()
60
61    def markersize(self):
62        ''' return marker size (int) '''
63        return self.sbSize.value()
64
65    def color(self):
66        ''' return current color: index in COLORS or a hex string '''
67        if self.custom_color:
68            return self._color
69        else:
70            return self.cbColor.currentIndex()
71
72    def onColorChange(self):
73        """
74        Pop up the standard Qt color change dialog
75        """
76        # Pick up the chosen color
77        proposed_color = QtGui.QColorDialog.getColor(parent=self)
78        # Update the text control
79        if proposed_color.isValid():
80            # Block currentIndexChanged
81            self.cbColor.blockSignals(True)
82            # Add Custom to the color combo box
83            self.cbColor.addItems(["Custom"])
84            self.cbColor.setCurrentIndex(COLORS.keys().index("Custom"))
85            # unblock currentIndexChanged
86            self.cbColor.blockSignals(False)
87            # Save the color as #RRGGBB
88            self.custom_color = True
89            self._color = str(proposed_color.name())
90   
91    def onColorIndexChange(self):
92        """
93        Dynamically add/remove "Custom" color index
94        """
95        # Changed index - assure Custom is deleted
96        custom_index = self.cbColor.findText("Custom")
97        self.custom_color = False
98        if custom_index > -1:
99            self.cbColor.removeItem(custom_index)
100       
Note: See TracBrowser for help on using the repository browser.