Changeset 1b14795 in sasview for fittingview/src/sans
- Timestamp:
- Sep 20, 2011 7:27:58 PM (13 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:
- 6774d79
- Parents:
- 1976004
- Location:
- fittingview/src/sans/perspectives/fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fittingview/src/sans/perspectives/fitting/fitpage.py
r7ee79cb r1b14795 2653 2653 event = PageInfoEvent(page = self) 2654 2654 wx.PostEvent(self.parent, event) 2655 2655 param2fit = [] 2656 for item in self.param_toFit: 2657 if item[0]: 2658 param2fit.append(item[1]) 2659 self.parent._manager.set_param2fit(self.uid, param2fit) 2660 2661 2656 2662 def select_param(self,event): 2657 2663 """ … … 2712 2718 event = PageInfoEvent(page = self) 2713 2719 wx.PostEvent(self.parent, event) 2714 2720 2721 param2fit = [] 2722 for item in self.param_toFit: 2723 if item[0]: 2724 param2fit.append(item[1]) 2725 self.parent._manager.set_param2fit(self.uid, param2fit) 2726 2715 2727 def set_model_param_sizer(self, model): 2716 2728 """ -
fittingview/src/sans/perspectives/fitting/fitproblem.py
r05325ec4 r1b14795 67 67 :param name: name of the given parameter 68 68 :param value: value of that parameter 69 """ 70 def set_param2fit(self, list): 71 """ 72 Store param names to fit (checked) 73 :param list: list of the param names 74 """ 75 def get_param2fit(self): 76 """ 77 return the list param names to fit 69 78 """ 70 79 def get_model_param(self): … … 295 304 if fid in self.iterkeys(): 296 305 return self[fid].get_model_param() 297 306 307 def set_param2fit(self, list): 308 """ 309 Store param names to fit (checked) 310 :param list: list of the param names 311 """ 312 self.list_param2fit = list 313 314 def get_param2fit(self): 315 """ 316 return the list param names to fit 317 """ 318 return self.list_param2fit 319 298 320 def schedule_tofit(self, schedule=0): 299 321 """ … … 523 545 """ 524 546 return self.weight 525 547 548 def set_param2fit(self, list): 549 """ 550 Store param names to fit (checked) 551 :param list: list of the param names 552 """ 553 self.list_param2fit = list 554 555 def get_param2fit(self): 556 """ 557 return the list param names to fit 558 """ 559 return self.list_param2fit 560 526 561 def set_model_param(self,name,value=None): 527 562 """ -
fittingview/src/sans/perspectives/fitting/fitting.py
rea8de94 r1b14795 429 429 self.temp_state = [] 430 430 raise 431 431 432 def set_param2fit(self, uid, param2fit): 433 """ 434 Set the list of param names to fit for fitprobelm 435 """ 436 self.page_finder[uid].set_param2fit(param2fit) 437 432 438 def save_fit_state(self, filepath, fitstate): 433 439 """ -
fittingview/src/sans/perspectives/fitting/simfitpage.py
r1976004 r1b14795 22 22 """ 23 23 fittable_param=[] 24 25 24 for item in model.getParamList(): 26 25 if not item in model.getDispParamList(): … … 60 59 ## look like self.constraint_dict[page_id]= page 61 60 self.constraint_dict={} 62 ## item list self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 61 ## item list 62 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 63 63 self.constraints_list=[] 64 64 ## list of current model … … 122 122 sizer.Clear(True) 123 123 self.sizer_constraints.Remove(sizer) 124 125 self.sizer2.Layout() 126 self.SetScrollbars(20,20,25,65) 124 #self.SetScrollbars(20,20,25,65) 127 125 self.constraints_list.remove(item) 128 126 self.nb_constraint -= 1 127 self.sizer2.Layout() 128 self.Layout() 129 129 break 130 130 self._onAdd_constraint(None) 131 131 132 def onFit(self, event): 132 133 """ … … 144 145 if item[0].GetValue(): 145 146 self.manager.schedule_for_fit(value=1, uid=item[2]) 146 self.manager.onFit(uid=self.uid) 147 try: 148 self.manager.onFit(uid=self.uid) 149 except: 150 msg= "Select at least one parameter to fit in the FitPages." 151 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 147 152 else: 148 153 msg= "Select at least one model to fit " 149 wx.PostEvent(self.parent. Parent, StatusEvent(status=msg))154 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 150 155 151 156 def set_manager(self, manager): … … 199 204 if len(self.model_toFit)==2: 200 205 self._store_model() 201 if self.show_constraint.GetValue() and len(self.constraints_list)==0: 206 if self.show_constraint.GetValue() and\ 207 len(self.constraints_list)==0: 202 208 self._show_constraint() 203 209 elif len(self.model_toFit)< 2: … … 235 241 if len(self.page_finder)==0: 236 242 msg = " No fit combinations are found! \n\n" 237 msg += " Please load data and set up at least two fit panels first..." 243 msg += " Please load data and set up " 244 msg += "at least two fit panels first..." 238 245 sizer_title.Add(wx.StaticText(self, -1, msg)) 239 246 else: … … 282 289 if len(self.model_toFit)< 2: 283 290 msg= "Select at least 2 models to add constraint " 284 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))291 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 285 292 ## hide button 286 293 self._hide_constraint() 287 294 return 288 295 if self.show_constraint.GetValue(): 296 self._show_all_constraint() 289 297 self._show_constraint() 290 298 return … … 292 300 self._hide_constraint() 293 301 return 294 302 303 def _show_all_constraint(self): 304 """ 305 Show constraint fields 306 """ 307 #for id, model in self.constraint_dict.iteritems(): 308 box_description= wx.StaticBox(self, -1,"Easy Setup ") 309 boxsizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 310 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL|wx.LEFT|wx.RIGHT|wx.EXPAND) 311 self.model_cbox_left = wx.ComboBox(self, -1, style=wx.CB_READONLY) 312 self.model_cbox_left.Clear() 313 self.model_cbox_right = wx.ComboBox(self, -1, style=wx.CB_READONLY) 314 self.model_cbox_right.Clear() 315 wx.EVT_COMBOBOX(self.model_cbox_left, -1, self._on_select_modelcb) 316 wx.EVT_COMBOBOX(self.model_cbox_right, -1, self._on_select_modelcb) 317 egal_txt= wx.StaticText(self,-1," = ") 318 self.set_button =wx.Button(self, wx.NewId(),'Set All') 319 self.set_button.Bind(wx.EVT_BUTTON, self._on_set_all_equal, 320 id=self.set_button.GetId()) 321 set_tip = "Add constraints for all the adjustable parameters " 322 set_tip += "(checked in FitPages) if exist." 323 self.set_button.SetToolTipString(set_tip) 324 self.set_button.Disable() 325 326 for id, model in self.constraint_dict.iteritems(): 327 ## check if all parameters have been selected for constraint 328 ## then do not allow add constraint on parameters 329 self.model_cbox_left.Append( str(model.name), model) 330 self.model_cbox_left.Select(0) 331 for id, model in self.constraint_dict.iteritems(): 332 ## check if all parameters have been selected for constraint 333 ## then do not allow add constraint on parameters 334 self.model_cbox_right.Append( str(model.name), model) 335 boxsizer.Add(self.model_cbox_left, 336 flag= wx.RIGHT|wx.EXPAND, border=10) 337 boxsizer.Add(wx.StaticText(self, -1,".parameters"), 338 flag= wx.RIGHT|wx.EXPAND, border=5) 339 boxsizer.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND, border=5) 340 boxsizer.Add(self.model_cbox_right, 341 flag= wx.RIGHT|wx.EXPAND, border=10) 342 boxsizer.Add(wx.StaticText(self, -1,".parameters"), 343 flag= wx.RIGHT|wx.EXPAND,border=5) 344 boxsizer.Add((20,-1)) 345 boxsizer.Add(self.set_button, flag= wx.RIGHT|wx.EXPAND, border=5) 346 sizer_constraint.Add(boxsizer, flag= wx.RIGHT|wx.EXPAND, border=5) 347 self.sizer_all_constraints.Insert(before=0, 348 item=sizer_constraint, 349 flag= wx.TOP|wx.BOTTOM|wx.EXPAND, border=5) 350 351 self.sizer_all_constraints.Layout() 352 self.sizer2.Layout() 353 self.SetScrollbars(20,20,25,65) 354 355 def _on_select_modelcb(self, event): 356 """ 357 On select model left or right combobox 358 """ 359 event.Skip() 360 flag = True 361 if self.model_cbox_left.GetValue().strip() == '': 362 flag = False 363 if self.model_cbox_right.GetValue().strip() == '': 364 flag = False 365 if self.model_cbox_left.GetValue() ==\ 366 self.model_cbox_right.GetValue(): 367 flag = False 368 self.set_button.Enable(flag) 369 370 def _on_set_all_equal(self, event): 371 """ 372 On set button 373 """ 374 event.Skip() 375 length = len(self.constraints_list) 376 if length < 1: 377 return 378 param_list = [] 379 param_listB = [] 380 selection = self.model_cbox_left.GetCurrentSelection() 381 model_left = self.model_cbox_left.GetValue() 382 model = self.model_cbox_left.GetClientData(selection) 383 selectionB = self.model_cbox_right.GetCurrentSelection() 384 model_right = self.model_cbox_right.GetValue() 385 modelB = self.model_cbox_right.GetClientData(selectionB) 386 for id, dic_model in self.constraint_dict.iteritems(): 387 if model == dic_model: 388 param_list = self.page_finder[id].get_param2fit() 389 if modelB == dic_model: 390 param_listB = self.page_finder[id].get_param2fit() 391 if len(param_list) > 0 and len(param_listB) > 0: 392 break 393 #param_list= get_fittableParam(model) 394 #param_listB= get_fittableParam(modelB) 395 num_cbox = 0 396 has_param = False 397 for param in param_list: 398 num_cbox += 1 399 if param in param_listB: 400 self.model_cbox.SetStringSelection(model_left) 401 self._on_select_model(None) 402 self.param_cbox.Clear() 403 self.param_cbox.Append( str(param), model) 404 self.param_cbox.SetStringSelection( str(param)) 405 self.ctl2.SetValue(str(model_right + "." + str(param))) 406 has_param = True 407 if num_cbox == len(param_list): 408 break 409 self._show_constraint() 410 411 self.sizer_constraints.Layout() 412 self.sizer2.Layout() 413 414 if not has_param: 415 msg= " There is no adjustable parameter (checked to fit)" 416 msg += " either one of the models." 417 wx.PostEvent(self.parent.parent, StatusEvent(info="warning", 418 status= msg )) 419 else: 420 msg= " The constraints are added." 421 wx.PostEvent(self.parent.parent, StatusEvent(info="info", 422 status= msg )) 295 423 def _show_constraint(self): 296 424 """ … … 300 428 if len(self.constraints_list)!= 0: 301 429 nb_fit_param = 0 302 for model in self.constraint_dict.values():303 nb_fit_param += len( get_fittableParam(model))430 for id, model in self.constraint_dict.iteritems(): 431 nb_fit_param += len(self.page_finder[id].get_param2fit())#len(get_fittableParam(model)) 304 432 ##Don't add anymore 305 433 if len(self.constraints_list) == nb_fit_param: 306 434 msg= "Cannot add another constraint .Maximum of number " 307 435 msg += "Parameters name reached %s"%str(nb_fit_param) 308 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))436 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 309 437 self.sizer_constraints.Layout() 310 438 self.sizer2.Layout() 311 439 self.SetScrollbars(20,20,25,65) 312 440 return 313 314 441 if len(self.model_toFit) < 2 : 315 442 msg= "Select at least 2 model to add constraint " 316 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))443 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 317 444 self.sizer_constraints.Layout() 318 445 self.sizer2.Layout() … … 323 450 model_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) 324 451 model_cbox.Clear() 325 param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY )452 param_cbox = wx.ComboBox(self, -1,style=wx.CB_READONLY, size=(100,-1),) 326 453 param_cbox.Hide() 327 454 … … 330 457 331 458 wx.EVT_COMBOBOX(param_cbox,-1, self._on_select_param) 332 ctl2 = wx.TextCtrl(self, -1)459 self.ctl2 = wx.TextCtrl(self, -1) 333 460 egal_txt= wx.StaticText(self,-1," = ") 334 461 btRemove = wx.Button(self,wx.NewId(),'Remove') … … 336 463 btRemove.SetToolTipString("Remove constraint.") 337 464 338 for id, model in self.constraint_dict.iteritems():465 for id, model in self.constraint_dict.iteritems(): 339 466 ## check if all parameters have been selected for constraint 340 467 ## then do not allow add constraint on parameters … … 345 472 346 473 wx.EVT_COMBOBOX(model_cbox,-1, self._on_select_model) 347 474 sizer_constraint.Add((5,-1)) 348 475 sizer_constraint.Add(model_cbox, flag= wx.RIGHT|wx.EXPAND,border=10) 349 476 sizer_constraint.Add(param_cbox, flag= wx.RIGHT|wx.EXPAND,border=5) 350 477 sizer_constraint.Add(egal_txt, flag= wx.RIGHT|wx.EXPAND,border=5) 351 sizer_constraint.Add( ctl2, flag= wx.RIGHT|wx.EXPAND,border=10)478 sizer_constraint.Add(self.ctl2, flag= wx.RIGHT|wx.EXPAND,border=10) 352 479 sizer_constraint.Add(btRemove, flag= wx.RIGHT|wx.EXPAND,border=10) 353 480 … … 356 483 border=5) 357 484 ##[combobox1, combobox2,=,textcrtl, remove button ] 358 self.constraints_list.append([model_cbox, param_cbox, egal_txt, ctl2,btRemove,sizer_constraint])485 self.constraints_list.append([model_cbox, param_cbox, egal_txt, self.ctl2,btRemove,sizer_constraint]) 359 486 360 487 self.nb_constraint += 1 … … 370 497 self.page_finder[id].clear_model_param() 371 498 372 self.nb_constraint = 0373 self.constraint_dict ={}499 self.nb_constraint = 0 500 self.constraint_dict = {} 374 501 if hasattr(self,"btAdd"): 375 502 self.btAdd.Hide() 376 503 self._store_model() 377 self.constraints_list=[] 504 self.constraints_list = [] 505 self.sizer_all_constraints.Clear(True) 506 self.sizer_all_constraints.Layout() 378 507 self.sizer_constraints.Clear(True) 379 508 self.sizer_constraints.Layout() … … 389 518 n = self.model_cbox.GetCurrentSelection() 390 519 model = self.model_cbox.GetClientData(n) 391 392 param_list= get_fittableParam(model) 520 for id, dic_model in self.constraint_dict.iteritems(): 521 if model == dic_model: 522 param_list = self.page_finder[id].get_param2fit() 523 break 524 #param_list= get_fittableParam(model) 393 525 length = len(self.constraints_list) 394 526 if length < 1: … … 430 562 if not self.show_constraint.GetValue(): 431 563 msg= " Select Yes to add Constraint " 432 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))564 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 433 565 return 434 ## check that a constraint is added before allow to add another cosntraint 566 ## check that a constraint is added 567 # before allow to add another constraint 435 568 for item in self.constraints_list: 436 569 model_cbox = item[0] 437 570 if model_cbox.GetString(0)=="": 438 571 msg= " Select a model Name! " 439 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))572 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 440 573 return 441 574 param_cbox = item[1] 442 575 if param_cbox.GetString(0)=="": 443 576 msg= " Select a parameter Name! " 444 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))577 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 445 578 return 446 579 ctl2 = item[3] 447 580 if ctl2.GetValue().lstrip().rstrip()=="": 448 581 model= param_cbox.GetClientData(param_cbox.GetCurrentSelection()) 449 msg= " Enter a constraint for %s.%s! "%(model.name,param_cbox.GetString(0)) 450 wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) 582 msg= " Enter a constraint for %s.%s! "%(model.name, 583 param_cbox.GetString(0)) 584 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 451 585 return 452 586 ## some model or parameters can be constrained … … 483 617 """ 484 618 msg = "Select at least 2 model to add constraint " 485 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))619 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 486 620 487 621 self.sizer2.Clear(True) … … 489 623 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 490 624 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 625 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) 491 626 self.sizer_constraints = wx.BoxSizer(wx.VERTICAL) 492 627 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 493 628 494 self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), style=wx.RB_GROUP) 629 self.hide_constraint = wx.RadioButton(self, -1, 'No', (10, 10), 630 style=wx.RB_GROUP) 495 631 self.show_constraint = wx.RadioButton(self, -1, 'Yes', (10, 30)) 496 632 self.Bind( wx.EVT_RADIOBUTTON, self._display_constraint, … … 508 644 sizer_title.Add( self.hide_constraint ) 509 645 sizer_title.Add(( 10,10) ) 510 646 511 647 self.btAdd =wx.Button(self,wx.NewId(),'Add') 512 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint,id= self.btAdd.GetId()) 648 self.btAdd.Bind(wx.EVT_BUTTON, self._onAdd_constraint, 649 id=self.btAdd.GetId()) 513 650 self.btAdd.SetToolTipString("Add another constraint?") 514 651 self.btAdd.Hide() 515 652 516 text_hint = wx.StaticText(self,-1,"Example: [M0][paramter] = M1.parameter") 653 text_hint = wx.StaticText(self, -1, 654 "Example: [M0][paramter] = M1.parameter") 517 655 sizer_button.Add(text_hint, 0 , wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 518 656 sizer_button.Add(self.btAdd, 0, wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) 519 657 520 658 boxsizer1.Add(sizer_title, flag= wx.TOP|wx.BOTTOM,border=10) 521 boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM,border=10) 522 boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM,border=10) 659 boxsizer1.Add(self.sizer_all_constraints, flag= wx.TOP|wx.BOTTOM, 660 border=10) 661 boxsizer1.Add(self.sizer_constraints, flag= wx.TOP|wx.BOTTOM, 662 border=10) 663 boxsizer1.Add(sizer_button, flag= wx.TOP|wx.BOTTOM, border=10) 523 664 524 665 self.sizer2.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) … … 530 671 get values from the constrainst textcrtl ,parses them into model name 531 672 parameter name and parameters values. 532 store them in a list self.params .when when params is not empty set_model 533 uses it to reset the appropriate model and its appropriates parameters 673 store them in a list self.params .when when params is not empty 674 set_model uses it to reset the appropriate model 675 and its appropriates parameters 534 676 """ 535 677 for item in self.constraints_list: … … 539 681 if param.lstrip().rstrip()=="": 540 682 param= None 541 msg= " Constraint will be ignored!. missing parameters in combobox"542 msg+= " to set constraint! "543 wx.PostEvent(self.parent. Parent, StatusEvent(status= msg ))683 msg= " Constraint will be ignored!. missing parameters" 684 msg+= " in combobox to set constraint! " 685 wx.PostEvent(self.parent.parent, StatusEvent(status= msg )) 544 686 for id, value in self.constraint_dict.iteritems(): 545 687 if model == value: 546 688 if constraint == "": 547 msg= " Constraint will be ignored!. missing value in textcrtl" 548 msg+= " to set constraint! " 549 wx.PostEvent(self.parent.Parent, StatusEvent(status= msg )) 689 msg= " Constraint will be ignored!. missing value" 690 msg+= " in textcrtl to set constraint! " 691 wx.PostEvent(self.parent.parent, 692 StatusEvent(status= msg )) 550 693 constraint = None 551 694 for fid in self.page_finder[id].iterkeys(): … … 566 709 sizer.Clear(True) 567 710 568 new_name = wx.StaticText(self, -1, 'New Model Name', style=wx.ALIGN_CENTER) 711 new_name = wx.StaticText(self, -1, 'New Model Name', 712 style=wx.ALIGN_CENTER) 569 713 new_name.SetBackgroundColour('orange') 570 714 sizer.Add(new_name,(iy, ix),(1,1),
Note: See TracChangeset
for help on using the changeset viewer.