Changeset 5d89f43 in sasview for src/sas/qtgui/ColorMap.py


Ignore:
Timestamp:
Jan 25, 2017 8:51:26 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
3bdbfcc
Parents:
03c372d
Message:

Code review for ColorMap?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/ColorMap.py

    • Property mode changed from 100755 to 100644
    r03c372d r5d89f43  
    1313from sas.sasgui.guiframe.dataFitting import Data2D 
    1414from sas.qtgui.GuiUtils import formatNumber 
     15from rangeSlider import RangeSlider 
    1516 
    1617DEFAULT_MAP = 'jet' 
     
    2021 
    2122class ColorMap(QtGui.QDialog, Ui_ColorMapUI): 
     23    apply_signal = QtCore.pyqtSignal(tuple, str) 
    2224    def __init__(self, parent=None, cmap=None, vmin=0.0, vmax=100.0, data=None): 
    2325        super(ColorMap, self).__init__() 
     
    3234        self.rmaps = sorted(set(self.all_maps) - set(self.maps)) 
    3335 
    34         self.vmin = vmin 
    35         self.vmax = vmax 
     36        self.vmin = self.vmin_orig = vmin 
     37        self.vmax = self.vmax_orig = vmax 
    3638 
    3739        # Initialize detector labels 
     
    4042        # Initialize the combo box 
    4143        self.initMapCombobox() 
     44 
     45        self.initRangeSlider() 
    4246 
    4347        # Add the color map component 
     
    5256        self.txtMaxAmplitude.setValidator(validator_max) 
    5357 
     58        # Set the initial amplitudes 
     59        self.txtMinAmplitude.setText(formatNumber(self.vmin)) 
     60        self.txtMaxAmplitude.setText(formatNumber(self.vmax)) 
     61 
    5462        # Enforce constant size on the widget 
    5563        self.setFixedSize(self.minimumSizeHint()) 
     
    6169        self.chkReverse.stateChanged.connect(self.onColorMapReversed) 
    6270 
    63         # Handle the reset button click 
     71        # Handle the Reset button click 
    6472        self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(self.onReset) 
     73 
     74        # Handle the Apply button click 
     75        self.buttonBox.button(QtGui.QDialogButtonBox.Apply).clicked.connect(self.onApply) 
    6576 
    6677        # Handle the amplitude setup 
     
    8697        # Go back to original settings 
    8798        self._cmap = self._cmap_orig 
     99        self.vmin = self.vmin_orig 
     100        self.vmax = self.vmax_orig 
    88101        self._norm = mpl.colors.Normalize(vmin=self.vmin, vmax=self.vmax) 
    89         self.txtMaxAmplitude.clear() 
    90         self.txtMinAmplitude.clear() 
     102        self.txtMinAmplitude.setText(formatNumber(self.vmin)) 
     103        self.txtMaxAmplitude.setText(formatNumber(self.vmax)) 
    91104        self.initMapCombobox() 
     105        self.slider.setMinimum(self.vmin) 
     106        self.slider.setMaximum(self.vmax) 
     107        self.slider.setLowValue(self.vmin) 
     108        self.slider.setHighValue(self.vmax) 
    92109        # Redraw the widget 
    93110        self.redrawColorBar() 
    94111        self.canvas.draw() 
     112 
     113    def onApply(self): 
     114        """ 
     115        Respond to the Apply button click. 
     116        Send a signal to the plotter with vmin/vmax/cmap for chart update 
     117        """ 
     118        self.apply_signal.emit(self.norm(), self.cmap()) 
    95119 
    96120    def initDetectorData(self): 
     
    125149        self.cbColorMap.setCurrentIndex(self.cbColorMap.findText(self._cmap)) 
    126150 
     151    def initRangeSlider(self): 
     152        """ 
     153        Create and display the double slider for data range mapping. 
     154        """ 
     155        self.slider = RangeSlider() 
     156        self.slider.setMinimum(self.vmin) 
     157        self.slider.setMaximum(self.vmax) 
     158        self.slider.setLowValue(self.vmin) 
     159        self.slider.setHighValue(self.vmax) 
     160        self.slider.setOrientation(QtCore.Qt.Horizontal) 
     161 
     162        self.slider_label = QtGui.QLabel() 
     163        self.slider_label.setText("Drag the sliders to adjust color range.") 
     164 
     165        def set_vmin(value): 
     166            self.vmin = value 
     167            self.txtMinAmplitude.setText(str(value)) 
     168            self.updateMap() 
     169        def set_vmax(value): 
     170            self.vmax = value 
     171            self.txtMaxAmplitude.setText(str(value)) 
     172            self.updateMap() 
     173 
     174        self.slider.lowValueChanged.connect(set_vmin) 
     175        self.slider.highValueChanged.connect(set_vmin) 
     176 
     177    def updateMap(self): 
     178        self._norm = mpl.colors.Normalize(vmin=self.vmin, vmax=self.vmax) 
     179        self.redrawColorBar() 
     180        self.canvas.draw() 
     181 
    127182    def initColorMap(self): 
    128183        """ 
     
    131186        self.fig = mpl.figure.Figure(figsize=(4, 1)) 
    132187        self.ax1 = self.fig.add_axes([0.05, 0.65, 0.9, 0.15]) 
     188 
    133189        self._norm = mpl.colors.Normalize(vmin=self.vmin, vmax=self.vmax) 
    134190        self.redrawColorBar() 
    135191        self.canvas = FigureCanvas(self.fig) 
     192 
    136193        layout = QtGui.QVBoxLayout() 
     194        layout.addWidget(self.slider_label) 
     195        layout.addWidget(self.slider) 
    137196        layout.addWidget(self.canvas) 
     197 
    138198        self.widget.setLayout(layout) 
    139199 
     
    154214                                            norm=self._norm, 
    155215                                            orientation='horizontal') 
    156         self.cb.set_label('Detector Colors') 
     216        self.cb.set_label('Color map range') 
    157217 
    158218    def onColorMapReversed(self, isChecked): 
     
    177237 
    178238        self._cmap = new_map 
    179         # Clearning the content of the combobox. 
     239        # Clear the content of the combobox. 
    180240        # Needs signal blocking, or else onMapIndexChange() spoils it all 
    181241        self.cbColorMap.blockSignals(True) 
Note: See TracChangeset for help on using the changeset viewer.