source: sasview/src/sas/qtgui/PlotProperties.py @ db5cd8d

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

Added tests for PlotProperties?

  • Property mode set to 100755
File size: 3.3 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            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, event):
69        """
70        Pop up the standard Qt color change dialog
71        """
72        # Pick up the chosen color
73        self._color = QtGui.QColorDialog.getColor(parent=self)
74        # Update the text control
75        if self._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(self._color.name())
86   
87    def onColorIndexChange(self, index):
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
97        pass # debug hook
98       
Note: See TracBrowser for help on using the repository browser.