Changeset 5d89f43 in sasview
- Timestamp:
- Jan 25, 2017 6:51:26 AM (8 years ago)
- 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
- Location:
- src/sas/qtgui
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/ColorMap.py
- Property mode changed from 100755 to 100644
r03c372d r5d89f43 13 13 from sas.sasgui.guiframe.dataFitting import Data2D 14 14 from sas.qtgui.GuiUtils import formatNumber 15 from rangeSlider import RangeSlider 15 16 16 17 DEFAULT_MAP = 'jet' … … 20 21 21 22 class ColorMap(QtGui.QDialog, Ui_ColorMapUI): 23 apply_signal = QtCore.pyqtSignal(tuple, str) 22 24 def __init__(self, parent=None, cmap=None, vmin=0.0, vmax=100.0, data=None): 23 25 super(ColorMap, self).__init__() … … 32 34 self.rmaps = sorted(set(self.all_maps) - set(self.maps)) 33 35 34 self.vmin = vmin35 self.vmax = vmax36 self.vmin = self.vmin_orig = vmin 37 self.vmax = self.vmax_orig = vmax 36 38 37 39 # Initialize detector labels … … 40 42 # Initialize the combo box 41 43 self.initMapCombobox() 44 45 self.initRangeSlider() 42 46 43 47 # Add the color map component … … 52 56 self.txtMaxAmplitude.setValidator(validator_max) 53 57 58 # Set the initial amplitudes 59 self.txtMinAmplitude.setText(formatNumber(self.vmin)) 60 self.txtMaxAmplitude.setText(formatNumber(self.vmax)) 61 54 62 # Enforce constant size on the widget 55 63 self.setFixedSize(self.minimumSizeHint()) … … 61 69 self.chkReverse.stateChanged.connect(self.onColorMapReversed) 62 70 63 # Handle the reset button click71 # Handle the Reset button click 64 72 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) 65 76 66 77 # Handle the amplitude setup … … 86 97 # Go back to original settings 87 98 self._cmap = self._cmap_orig 99 self.vmin = self.vmin_orig 100 self.vmax = self.vmax_orig 88 101 self._norm = mpl.colors.Normalize(vmin=self.vmin, vmax=self.vmax) 89 self.txtM axAmplitude.clear()90 self.txtM inAmplitude.clear()102 self.txtMinAmplitude.setText(formatNumber(self.vmin)) 103 self.txtMaxAmplitude.setText(formatNumber(self.vmax)) 91 104 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) 92 109 # Redraw the widget 93 110 self.redrawColorBar() 94 111 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()) 95 119 96 120 def initDetectorData(self): … … 125 149 self.cbColorMap.setCurrentIndex(self.cbColorMap.findText(self._cmap)) 126 150 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 127 182 def initColorMap(self): 128 183 """ … … 131 186 self.fig = mpl.figure.Figure(figsize=(4, 1)) 132 187 self.ax1 = self.fig.add_axes([0.05, 0.65, 0.9, 0.15]) 188 133 189 self._norm = mpl.colors.Normalize(vmin=self.vmin, vmax=self.vmax) 134 190 self.redrawColorBar() 135 191 self.canvas = FigureCanvas(self.fig) 192 136 193 layout = QtGui.QVBoxLayout() 194 layout.addWidget(self.slider_label) 195 layout.addWidget(self.slider) 137 196 layout.addWidget(self.canvas) 197 138 198 self.widget.setLayout(layout) 139 199 … … 154 214 norm=self._norm, 155 215 orientation='horizontal') 156 self.cb.set_label(' Detector Colors')216 self.cb.set_label('Color map range') 157 217 158 218 def onColorMapReversed(self, isChecked): … … 177 237 178 238 self._cmap = new_map 179 # Clear ningthe content of the combobox.239 # Clear the content of the combobox. 180 240 # Needs signal blocking, or else onMapIndexChange() spoils it all 181 241 self.cbColorMap.blockSignals(True) -
src/sas/qtgui/Plotter2D.py
r03c372d r5d89f43 29 29 # Default scale 30 30 self.scale = 'log_{10}' 31 self.vmin = None 32 self.vmax = None 31 33 32 34 @property … … 208 210 data=self.data) 209 211 212 color_map_dialog.apply_signal.connect(self.onApplyMap) 213 210 214 if color_map_dialog.exec_() == QtGui.QDialog.Accepted: 211 self.cmap = color_map_dialog.cmap() 212 self.vmin, self.vmax = color_map_dialog.norm() 213 # Redraw the chart with new cmap 214 self.plot() 215 pass 215 self.onApplyMap(color_map_dialog.norm(), color_map_dialog.cmap()) 216 217 def onApplyMap(self, v_values, cmap): 218 """ 219 Update the chart color map based on data passed from the widget 220 """ 221 self.cmap = str(cmap) 222 self.vmin, self.vmax = v_values 223 # Redraw the chart with new cmap 224 self.plot() 216 225 217 226 def showPlot(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax, … … 261 270 self.figure.subplots_adjust(left=0.2, right=.8, bottom=.2) 262 271 272 zmax_temp = self.zmax 273 if self.vmin is not None: 274 zmin_temp = self.vmin 275 zmax_temp = self.vmax 276 263 277 im = self.ax.imshow(output, interpolation='nearest', 264 278 origin='lower', 265 vmin=zmin_temp, vmax= self.zmax,279 vmin=zmin_temp, vmax=zmax_temp, 266 280 cmap=self.cmap, 267 281 extent=(self.xmin, self.xmax, … … 301 315 302 316 ax = Axes3D(self.figure) 303 #cbax = self.figure.add_axes([0.84, 0.1, 0.02, 0.8])304 317 305 318 # Disable rotation for large sets. -
src/sas/qtgui/UI/ColorMapUI.ui
r092a3d9 r5d89f43 56 56 </property> 57 57 <property name="standardButtons"> 58 <set>QDialogButtonBox:: Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>58 <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set> 59 59 </property> 60 60 </widget> … … 147 147 <item row="0" column="0"> 148 148 <widget class="QLabel" name="label_4"> 149 <property name="toolTip"> 150 <string><html><head/><body><p>Detector width.</p></body></html></string> 151 </property> 149 152 <property name="text"> 150 153 <string>Width in pixels</string> … … 161 164 <item row="1" column="0"> 162 165 <widget class="QLabel" name="label_5"> 166 <property name="toolTip"> 167 <string><html><head/><body><p>Detector height.</p></body></html></string> 168 </property> 163 169 <property name="text"> 164 170 <string>Height in pixels</string> … … 175 181 <item row="2" column="0"> 176 182 <widget class="QLabel" name="label_6"> 177 <property name="text"> 178 <string>Q max</string> 183 <property name="toolTip"> 184 <string><html><head/><body><p>Maximum absolute Q<span style=" vertical-align:sub;">x,y</span> value.</p></body></html></string> 185 </property> 186 <property name="text"> 187 <string><html><head/><body><p>Q<span style=" vertical-align:sub;">max</span></p></body></html></string> 179 188 </property> 180 189 </widget> … … 189 198 <item row="3" column="0"> 190 199 <widget class="QLabel" name="label_7"> 200 <property name="toolTip"> 201 <string><html><head/><body><p>Minimum value of Q<span style=" vertical-align:sub;">x</span> in units of Q.</p></body></html></string> 202 </property> 191 203 <property name="text"> 192 204 <string>Beam stop radius</string> -
src/sas/qtgui/UnitTesting/ColorMapTest.py
r03c372d r5d89f43 13 13 import sas.qtgui.Plotter2D as Plotter2D 14 14 from UnitTesting.TestUtils import WarningTestNotImplemented 15 from UnitTesting.TestUtils import QtSignalSpy 15 16 16 17 # Local … … 65 66 self.assertIsInstance(self.widget.txtMaxAmplitude.validator(), QtGui.QDoubleValidator) 66 67 68 # Ranges 69 self.assertEqual(self.widget.txtMinAmplitude.text(), "0") 70 self.assertEqual(self.widget.txtMaxAmplitude.text(), "100") 71 self.assertIsInstance(self.widget.slider, QtGui.QSlider) 72 67 73 def testOnReset(self): 68 74 '''Check the dialog reset function''' … … 78 84 self.assertEqual(self.widget.cbColorMap.currentIndex(), 20) 79 85 self.assertFalse(self.widget.chkReverse.isChecked()) 80 self.assertEqual(self.widget.txtMinAmplitude.text(), "") 86 self.assertEqual(self.widget.txtMinAmplitude.text(), "0") 87 88 def testOnApply(self): 89 '''Check the dialog apply function''' 90 # Set some controls to non-default state 91 self.widget.show() 92 self.widget.cbColorMap.setCurrentIndex(20) # PuRd_r 93 self.widget.chkReverse.setChecked(True) 94 self.widget.txtMinAmplitude.setText("20.0") 95 96 spy_apply = QtSignalSpy(self.widget, self.widget.apply_signal) 97 # Reset the widget state 98 self.widget.onApply() 99 100 # Assure the widget is still up and the signal was sent. 101 self.assertTrue(self.widget.isVisible()) 102 self.assertEqual(spy_apply.count(), 1) 103 self.assertIn('PuRd_r', spy_apply.called()[0]['args'][1]) 81 104 82 105 def testInitMapCombobox(self): … … 97 120 self.assertTrue(self.widget.chkReverse.isChecked()) 98 121 122 def testInitRangeSlider(self): 123 '''Test the range slider initializer''' 124 # Set a color map from the direct list 125 self.widget._cmap = "gnuplot" 126 self.widget.initRangeSlider() 127 128 # Check the values 129 self.assertEqual(self.widget.slider.minimum(), 0) 130 self.assertEqual(self.widget.slider.maximum(), 100) 131 self.assertEqual(self.widget.slider.orientation(), 1) 132 133 # Emit new low value 134 self.widget.slider.lowValueChanged.emit(5) 135 # Assure the widget received changes 136 self.assertEqual(self.widget.txtMinAmplitude.text(), "5") 137 138 # Emit new high value 139 self.widget.slider.highValueChanged.emit(45) 140 # Assure the widget received changes 141 self.assertEqual(self.widget.txtMinAmplitude.text(), "45") 99 142 100 143 def testOnMapIndexChange(self):
Note: See TracChangeset
for help on using the changeset viewer.