Changeset 5d98370 in sasview for prview/perspectives/pr
- Timestamp:
- May 25, 2009 4:52:02 PM (16 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, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 6f1f129
- Parents:
- fd4b6f8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
prview/perspectives/pr/inversion_panel.py
r0bae207 r5d98370 6 6 7 7 import wx 8 import os 8 9 from sans.guicomm.events import StatusEvent 10 from inversion_state import InversionState 9 11 10 12 class InversionDlg(wx.Dialog): … … 108 110 ## Oscillation parameters (sin function = 1.1) 109 111 oscillation_max = 1.5 110 111 ## Fraction of P(r) that is positive112 positive = 1.0113 114 ## Fraction of P(r) that is greater than zero by more than 1 sigma115 pos_err = 1.0116 112 117 113 def __init__(self, parent, id = -1, plots = None, standalone=False, **kwargs): … … 135 131 self.qmin_ctl = None 136 132 self.qmax_ctl = None 133 self.swidth_ctl = None 134 self.sheight_ctl = None 137 135 138 136 self.rg_ctl = None … … 157 155 self.standalone = standalone 158 156 157 ## Default file location for save 158 self._default_save_location = os.getcwd() 159 159 160 self._do_layout() 160 161 … … 164 165 """ 165 166 if name=='nfunc': 166 self.nfunc_ctl.SetValue(str( value))167 self.nfunc_ctl.SetValue(str(int(value))) 167 168 elif name=='d_max': 168 169 self.dmax_ctl.SetValue(str(value)) … … 185 186 elif name=='oscillation': 186 187 self.osc_ctl.SetValue("%-5.2g" % value) 188 elif name=='slit_width': 189 self.swidth_ctl.SetValue("%-5.2g" % value) 190 elif name=='slit_height': 191 self.sheight_ctl.SetValue("%-5.2g" % value) 187 192 elif name=='positive': 188 193 self.pos_ctl.SetValue("%-5.2g" % value) … … 234 239 return float(self.chi2_ctl.GetValue()) 235 240 except: 236 return -1.0241 return None 237 242 elif name=='bck': 238 243 try: 239 244 return float(self.bck_ctl.GetValue()) 240 245 except: 241 return -1.0246 return None 242 247 elif name=='q_min': 243 248 try: … … 254 259 return float(self.time_ctl.GetValue()) 255 260 except: 256 return -1.0261 return None 257 262 elif name=='rg': 258 263 try: 259 264 return float(self.rg_ctl.GetValue()) 260 265 except: 261 return -1.0266 return None 262 267 elif name=='iq0': 263 268 try: 264 269 return float(self.iq0_ctl.GetValue()) 265 270 except: 266 return -1.0271 return None 267 272 elif name=='oscillation': 268 273 try: 269 274 return float(self.osc_ctl.GetValue()) 270 275 except: 271 return -1.0 276 return None 277 elif name=='slit_width': 278 try: 279 return float(self.swidth_ctl.GetValue()) 280 except: 281 return None 282 elif name=='slit_height': 283 try: 284 return float(self.sheight_ctl.GetValue()) 285 except: 286 return None 272 287 elif name=='pos': 273 288 try: 274 289 return float(self.pos_ctl.GetValue()) 275 290 except: 276 return -1.0291 return None 277 292 elif name=='pos_err': 278 return self.pos_err_ctl.GetValue() 293 try: 294 return float(self.pos_err_ctl.GetValue()) 295 except: 296 return None 279 297 elif name=='alpha_estimate': 280 return self.alpha_estimate_ctl.GetLabel() 298 try: 299 return float(self.alpha_estimate_ctl.GetLabel()) 300 except: 301 return None 281 302 elif name=='nterms_estimate': 282 return self.nterms_estimate_ctl.GetLabel() 303 try: 304 return int(self.nterms_estimate_ctl.GetLabel()) 305 except: 306 return None 283 307 elif name=='plotname': 284 308 if self.standalone==False: … … 289 313 wx.Panel.__getattr__(self, name) 290 314 315 def _save_state(self, evt=None): 316 """ 317 Method used to create a memento of the current state 318 319 @return: state object 320 """ 321 # Ask the user the location of the file to write to. 322 path = None 323 dlg = wx.FileDialog(self, "Choose a file", self._default_save_location, "", "*.prv", wx.SAVE) 324 if dlg.ShowModal() == wx.ID_OK: 325 path = dlg.GetPath() 326 self._default_save_location = os.path.dirname(path) 327 dlg.Destroy() 328 329 # Construct the state object 330 state = InversionState() 331 332 # Read the panel's parameters 333 flag, alpha, dmax, nfunc, qmin, \ 334 qmax, height, width = self._read_pars() 335 336 state.nfunc = nfunc 337 state.d_max = dmax 338 state.alpha = alpha 339 state.qmin = qmin 340 state.qmax = qmax 341 state.width = width 342 state.height = height 343 344 # Data file 345 state.file = self.data_file.GetValue() 346 347 # Background evaluation checkbox 348 state.estimate_bck = self.bck_chk.IsChecked() 349 350 # Estimates 351 state.nterms_estimate = self.nterms_estimate 352 state.alpha_estimate = self.alpha_estimate 353 354 # Read the output values 355 state.chi2 = self.chi2 356 state.elapsed = self.elapsed 357 state.osc = self.oscillation 358 state.pos = self.pos 359 state.pos_err = self.pos_err 360 state.rg = self.rg 361 state.iq0 = self.iq0 362 state.bck = self.bck 363 364 state.toXML(path) 365 return state 366 367 def set_state(self, state): 368 """ 369 Set the state of the panel and inversion problem to 370 the state passed as a parameter. 371 Execute the inversion immediately after filling the 372 controls. 373 374 @param state: InversionState object 375 """ 376 self.nfunc = state.nfunc 377 self.d_max = state.d_max 378 self.alpha = state.alpha 379 self.q_min = state.qmin 380 self.q_max = state.qmax 381 self.slit_width = state.width 382 self.slit_height = state.height 383 384 # Data file 385 self.data_file.SetValue(str(state.file)) 386 387 # Background evaluation checkbox 388 self.bck_chk.SetValue(state.estimate_bck) 389 390 # Estimates 391 self.nterms_estimate = state.nterms_estimate 392 self.alpha_estimate = state.alpha_estimate 393 394 395 # Read the output values 396 self.chi2 = state.chi2 397 self.elapsed = state.elapsed 398 self.oscillation = state.osc 399 self.positive = state.pos 400 self.pos_err = state.pos_err 401 self.rg = state.rg 402 self.iq0 = state.iq0 403 self.bck = state.bck 404 405 # Check whether the file is accessible, if so, 406 # load it a recompute P(r) using the new parameters 407 if os.path.isfile(state.file): 408 self._change_file(filepath=state.file) 409 self._on_invert(None) 410 else: 411 message = "Could not find [%s] on the file system." % state.file 412 wx.PostEvent(self.manager.parent, StatusEvent(status=message)) 413 414 415 291 416 def set_manager(self, manager): 292 417 self.manager = manager … … 312 437 else: 313 438 self.file_radio = wx.StaticText(self, -1, "Data file:") 314 self.data_file = wx.TextCtrl(self, -1, size=( 100,20))439 self.data_file = wx.TextCtrl(self, -1, size=(220,20)) 315 440 self.data_file.SetEditable(False) 316 441 self.data_file.SetValue("") 317 442 id = wx.NewId() 318 choose_button = wx.Button(self, id, "Choose file")319 self.Bind(wx.EVT_BUTTON, self._change_file, id = id)320 443 pars_sizer.Add(self.file_radio, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 321 #pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 15)322 444 pars_sizer.Add(self.data_file, (iy,1), (1,1), wx.ADJUST_MINSIZE, 15) 323 pars_sizer.Add(choose_button, (iy,3), (1,1), wx.RIGHT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)324 445 325 446 if self.standalone==False: … … 583 704 #button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 584 705 706 id = wx.NewId() 707 button_Save = wx.Button(self, id, "Save") 708 button_Save.SetToolTipString("Save the current P(r) work to file.") 709 self.Bind(wx.EVT_BUTTON, self._save_state, id = id) 710 585 711 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 586 712 sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 713 sizer_button.Add(button_Save, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 587 714 sizer_button.Add(button_Reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 588 715 sizer_button.Add(button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) … … 825 952 wx.PostEvent(self.parent, StatusEvent(status=message)) 826 953 827 def _change_file(self, evt ):954 def _change_file(self, evt=None, filepath=None): 828 955 """ 829 956 Choose a new input file for I(q) … … 831 958 import os 832 959 if not self.manager==None: 833 path = self.manager.choose_file( )960 path = self.manager.choose_file(path=filepath) 834 961 835 962 if path and os.path.isfile(path):
Note: See TracChangeset
for help on using the changeset viewer.