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

Last change on this file since a7067ef2 was cd2cc745, checked in by Piotr Rozyczko <rozyczko@…>, 8 years ago

Workaround for the resource file requirement in each UI directory

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