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

Last change on this file since 5dba493 was 53c771e, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Converted unit tests

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