Changeset b564ea2 in sasview for src/sas/sasgui
- Timestamp:
- Jul 11, 2016 2:36:55 AM (8 years ago)
- Branches:
- master, 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, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3b8efec
- Parents:
- 9c90cf3
- git-author:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/06/16 10:35:37)
- git-committer:
- Lewis O'Driscoll <lewis.o'driscoll@…> (07/11/16 02:36:55)
- Location:
- src/sas/sasgui/perspectives/corfunc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/corfunc/corfunc_panel.py
r9c90cf3 rb564ea2 37 37 self._data = data # The data to be analysed 38 38 self._data_name_box = None # Text box to show name of file 39 self._background_input = None 39 40 self._qmin_input = None 40 41 self._qmax1_input = None … … 42 43 self.qmin = 0 43 44 self.qmax = (0, 0) 45 self.background = 0 44 46 # Dictionary for saving IDs of text boxes used to display output data 45 47 self._output_ids = None … … 47 49 self._do_layout() 48 50 self.set_state() 49 self._qmin_input.Bind(wx.EVT_TEXT, self._on_enter_ qrange)50 self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_ qrange)51 self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_ qrange)51 self._qmin_input.Bind(wx.EVT_TEXT, self._on_enter_input) 52 self._qmax1_input.Bind(wx.EVT_TEXT, self._on_enter_input) 53 self._qmax2_input.Bind(wx.EVT_TEXT, self._on_enter_input) 52 54 53 55 def set_state(self, state=None, data=None): … … 70 72 if self.state.qmax is not None and self.state.qmax != (None, None): 71 73 self.set_qmax(tuple(self.state.qmax)) 74 if self.state.background is not None: 75 self.set_background(self.state.background) 72 76 73 77 def get_state(self): … … 79 83 state.set_saved_state('qmax1_tcl', self.qmax[0]) 80 84 state.set_saved_state('qmax2_tcl', self.qmax[1]) 85 state.set_saved_state('background_tcl', self.background) 81 86 if self._data is not None: 82 87 state.file = self._data.title … … 89 94 if evt is not None: 90 95 evt.Skip() 91 self._validate_ qrange()96 self._validate_inputs() 92 97 93 98 def set_data(self, data=None, set_qrange=True): … … 109 114 self.set_qmin(lower) 110 115 self.set_qmax((upper1, upper2)) 116 self.set_background(0.0) 111 117 112 118 def get_data(self): … … 142 148 self._qmax2_input.SetValue(str(qmax[1])) 143 149 144 145 def _on_enter_qrange(self, event=None): 150 def set_background(self, bg): 151 self.background = bg 152 self._background_input.SetValue(str(bg)) 153 154 155 def _on_enter_input(self, event=None): 146 156 """ 147 157 Read values from input boxes and save to memory. 148 158 """ 149 159 if event is not None: event.Skip() 150 if not self._validate_ qrange():160 if not self._validate_inputs(): 151 161 return 152 new_qmin = float(self._qmin_input.GetValue())162 self.qmin = float(self._qmin_input.GetValue()) 153 163 new_qmax1 = float(self._qmax1_input.GetValue()) 154 164 new_qmax2 = float(self._qmax2_input.GetValue()) 155 self.qmin = new_qmin156 165 self.qmax = (new_qmax1, new_qmax2) 166 self.background = float(self._background_input.GetValue()) 157 167 data_id = self._manager.data_id 158 168 from sas.sasgui.perspectives.corfunc.corfunc import GROUP_ID_IQ_DATA … … 164 174 leftdown=False)) 165 175 166 def _validate_ qrange(self):176 def _validate_inputs(self): 167 177 """ 168 178 Check that the values for qmin and qmax in the input boxes are valid … … 174 184 qmax2_valid = check_float(self._qmax2_input) 175 185 qmax_valid = qmax1_valid and qmax2_valid 176 if not (qmin_valid and qmax_valid): 177 if not qmin_valid: 178 self._qmin_input.SetBackgroundColour('pink') 179 self._qmin_input.Refresh() 180 if not qmax1_valid: 181 self._qmax1_input.SetBackgroundColour('pink') 182 self._qmax1_input.Refresh() 183 if not qmax2_valid: 184 self._qmax2_input.SetBackgroundColour('pink') 185 self._qmax2_input.Refresh() 186 return False 187 qmin = float(self._qmin_input.GetValue()) 188 qmax1 = float(self._qmax1_input.GetValue()) 189 qmax2 = float(self._qmax2_input.GetValue()) 186 background_valid = check_float(self._background_input) 190 187 msg = "" 191 if not qmin > self._data.x.min(): 192 msg = "qmin must be greater than the lowest q value" 193 qmin_valid = False 194 elif qmax2 < qmax1: 195 "qmax1 must be less than qmax2" 196 qmax_valid = False 197 elif qmin > qmax1: 198 "qmin must be less than qmax" 199 qmin_valid = False 200 201 if not (qmin_valid and qmax_valid): 202 if not qmin_valid: 203 self._qmin_input.SetBackgroundColour('pink') 204 if not qmax_valid: 205 self._qmax1_input.SetBackgroundColour('pink') 206 self._qmax2_input.SetBackgroundColour('pink') 207 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 208 else: 188 if (qmin_valid and qmax_valid and background_valid): 189 qmin = float(self._qmin_input.GetValue()) 190 qmax1 = float(self._qmax1_input.GetValue()) 191 qmax2 = float(self._qmax2_input.GetValue()) 192 background = float(self._background_input.GetValue()) 193 if not qmin > self._data.x.min(): 194 msg = "qmin must be greater than the lowest q value" 195 qmin_valid = False 196 elif qmax2 < qmax1: 197 msg = "qmax1 must be less than qmax2" 198 qmax_valid = False 199 elif qmin > qmax1: 200 msg = "qmin must be less than qmax" 201 qmin_valid = False 202 elif background < 0 or background > self._data.y.max(): 203 msg = "background must be positive and less than highest I value" 204 background_valid = False 205 if not qmin_valid: 206 self._qmin_input.SetBackgroundColour('pink') 207 if not qmax_valid: 208 self._qmax1_input.SetBackgroundColour('pink') 209 self._qmax2_input.SetBackgroundColour('pink') 210 if not background_valid: 211 self._background_input.SetBackgroundColour('pink') 212 if msg != "": 213 wx.PostEvent(self._manager.parent, StatusEvent(status=msg)) 214 if (qmin_valid and qmax_valid and background_valid): 209 215 self._qmin_input.SetBackgroundColour(wx.WHITE) 210 216 self._qmax1_input.SetBackgroundColour(wx.WHITE) 211 217 self._qmax2_input.SetBackgroundColour(wx.WHITE) 218 self._background_input.SetBackgroundColour(wx.WHITE) 212 219 self._qmin_input.Refresh() 213 220 self._qmax1_input.Refresh() 214 221 self._qmax2_input.Refresh() 215 return (qmin_valid and qmax_valid )222 return (qmin_valid and qmax_valid and background_valid) 216 223 217 224 def _do_layout(self): … … 259 266 q_sizer.Add(explanation_label, (0,0), (1,4), wx.LEFT | wx.EXPAND, 5) 260 267 268 background_label = wx.StaticText(self, -1, "Background:", size=(80,20)) 269 q_sizer.Add(background_label, (1,0), (1,1), wx.LEFT | wx.EXPAND, 5) 270 271 self._background_input = ModelTextCtrl(self, -1, size=(50,20), 272 style=wx.TE_PROCESS_ENTER, name='background_input', 273 text_enter_callback=self._on_enter_input) 274 self._background_input.SetToolTipString(("A background value to " 275 "subtract from all intensity values")) 276 q_sizer.Add(self._background_input, (1,1), (1,1), wx.RIGHT | wx.EXPAND, 5) 277 261 278 qrange_label = wx.StaticText(self, -1, "Q Range:", size=(50,20)) 262 q_sizer.Add(qrange_label, ( 1,0), (1,1), wx.LEFT | wx.EXPAND, 5)279 q_sizer.Add(qrange_label, (2,0), (1,1), wx.LEFT | wx.EXPAND, 5) 263 280 264 281 # Lower Q Range … … 270 287 self._qmin_input = ModelTextCtrl(self, -1, size=(50, 20), 271 288 style=wx.TE_PROCESS_ENTER, name='qmin_input', 272 text_enter_callback=self._on_enter_ qrange)289 text_enter_callback=self._on_enter_input) 273 290 self._qmin_input.SetToolTipString(("Values with q < qmin will be used " 274 291 "for Guinier back extrapolation")) 275 292 276 q_sizer.Add(qmin_label, ( 2, 0), (1, 1), wx.LEFT | wx.EXPAND, 5)277 q_sizer.Add(qmin_lower, ( 2, 1), (1, 1), wx.LEFT, 5)278 q_sizer.Add(qmin_dash_label, ( 2, 2), (1, 1), wx.CENTER | wx.EXPAND, 5)279 q_sizer.Add(self._qmin_input, ( 2, 3), (1, 1), wx.LEFT, 5)293 q_sizer.Add(qmin_label, (3, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 294 q_sizer.Add(qmin_lower, (3, 1), (1, 1), wx.LEFT, 5) 295 q_sizer.Add(qmin_dash_label, (3, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) 296 q_sizer.Add(self._qmin_input, (3, 3), (1, 1), wx.LEFT, 5) 280 297 281 298 # Upper Q range … … 289 306 self._qmax1_input = ModelTextCtrl(self, -1, size=(50, 20), 290 307 style=wx.TE_PROCESS_ENTER, name="qmax1_input", 291 text_enter_callback=self._on_enter_ qrange)308 text_enter_callback=self._on_enter_input) 292 309 self._qmax1_input.SetToolTipString(qmax_tooltip) 293 310 self._qmax2_input = ModelTextCtrl(self, -1, size=(50, 20), 294 311 style=wx.TE_PROCESS_ENTER, name="qmax2_input", 295 text_enter_callback=self._on_enter_ qrange)312 text_enter_callback=self._on_enter_input) 296 313 self._qmax2_input.SetToolTipString(qmax_tooltip) 297 314 298 q_sizer.Add(qmax_label, ( 3, 0), (1, 1), wx.LEFT | wx.EXPAND, 5)299 q_sizer.Add(self._qmax1_input, ( 3, 1), (1, 1), wx.LEFT, 5)300 q_sizer.Add(qmax_dash_label, ( 3, 2), (1, 1), wx.CENTER | wx.EXPAND, 5)301 q_sizer.Add(self._qmax2_input, ( 3,3), (1, 1), wx.LEFT, 5)315 q_sizer.Add(qmax_label, (4, 0), (1, 1), wx.LEFT | wx.EXPAND, 5) 316 q_sizer.Add(self._qmax1_input, (4, 1), (1, 1), wx.LEFT, 5) 317 q_sizer.Add(qmax_dash_label, (4, 2), (1, 1), wx.CENTER | wx.EXPAND, 5) 318 q_sizer.Add(self._qmax2_input, (4,3), (1, 1), wx.LEFT, 5) 302 319 303 320 qbox_sizer.Add(q_sizer, wx.TOP, 0) -
src/sas/sasgui/perspectives/corfunc/corfunc_state.py
r9c90cf3 rb564ea2 19 19 'qmax1_tcl': None, 20 20 'qmax2_tcl': None, 21 'background_tcl': None 21 22 } 22 23 … … 42 43 self.qmin = None 43 44 self.qmax = [0, 0] 45 self.background = None 44 46 self.outputs = None 45 47 … … 65 67 state += "Qmin: {}\n".format(str(self.qmin)) 66 68 state += "Qmax: {}\n".format(str(self.qmax)) 69 state += "Background: {}\n".format(str(self.background)) 67 70 if self.outputs is None: 68 71 return state … … 89 92 elif name == 'qmax2_tcl': 90 93 self.qmax[1] = value 94 elif name == 'background_tcl': 95 self.background = value 91 96 92 97 def toXML(self, filename='corfunc_state.cor', doc=None, entry_node=None):
Note: See TracChangeset
for help on using the changeset viewer.