Changeset ff3f5821 in sasview for src/sas/sasgui/perspectives/fitting/simfitpage.py
- Timestamp:
- Oct 7, 2016 12:31:19 PM (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:
- e6de6b8
- Parents:
- 998ca90 (diff), dd72190 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/perspectives/fitting/simfitpage.py
r4cafdff r998ca90 9 9 from wx.lib.scrolledpanel import ScrolledPanel 10 10 11 from sas.sasgui.guiframe.events import StatusEvent 11 from sas.sasgui.guiframe.events import StatusEvent, PanelOnFocusEvent 12 12 from sas.sasgui.guiframe.panel_base import PanelBase 13 from sas.sasgui.guiframe.events import PanelOnFocusEvent14 13 from sas.sasgui.guiframe.utils import IdList 15 14 from sas.sasgui.guiframe.documentation_window import DocumentationWindow 16 15 17 # Control panel width16 # Control panel width 18 17 if sys.platform.count("darwin") == 0: 19 18 PANEL_WID = 420 … … 29 28 'model_cbox param_cbox egal_txt constraint btRemove sizer') 30 29 30 31 31 def get_fittableParam(model): 32 32 """ … … 47 47 return fittable_param 48 48 49 49 50 class SimultaneousFitPage(ScrolledPanel, PanelBase): 50 51 """ … … 53 54 two data members window_name and window_caption 54 55 """ 55 # #Internal name for the AUI manager56 window_name = " simultaneous Fit page"57 # #Title to appear on top of the window56 # Internal name for the AUI manager 57 window_name = "Simultaneous Fit Page" 58 # Title to appear on top of the window 58 59 window_caption = "Simultaneous Fit Page" 59 60 ID_DOC = wx.NewId() … … 74 75 self._ids = iter(self._id_pool) 75 76 self.SetupScrolling() 76 # #Font size77 # Font size 77 78 self.SetWindowVariant(variant=FONT_VARIANT) 78 79 self.uid = wx.NewId() 79 80 self.parent = parent 80 81 self.batch_on = batch_on 81 # #store page_finder82 # store page_finder 82 83 self.page_finder = page_finder 83 # #list containing info to set constraint84 # #look like self.constraint_dict[page_id]= page84 # list containing info to set constraint 85 # look like self.constraint_dict[page_id]= page 85 86 self.constraint_dict = {} 86 # #item list87 # #self.constraints_list=[combobox1, combobox2,=,textcrtl, button ]87 # item list 88 # self.constraints_list=[combobox1, combobox2,=,textcrtl, button ] 88 89 self.constraints_list = [] 89 # #list of current model90 # list of current model 90 91 self.model_list = [] 91 # # selected mdoel to fit92 self.model_to Fit = []93 # #Control the fit state92 # selected model to fit 93 self.model_to_fit = [] 94 # Control the fit state 94 95 self.fit_started = False 95 # #number of constraint96 # number of constraint 96 97 self.nb_constraint = 0 98 self.state = SimFitPageState() 97 99 self.model_cbox_left = None 98 100 self.model_cbox_right = None 99 # #draw page101 # draw page 100 102 self.define_page_structure() 101 103 self.draw_page() … … 107 109 """ 108 110 self.vbox = wx.BoxSizer(wx.VERTICAL) 109 self. sizer1= wx.BoxSizer(wx.VERTICAL)110 self. sizer2= wx.BoxSizer(wx.VERTICAL)111 self. sizer3= wx.BoxSizer(wx.VERTICAL)112 113 self. sizer1.SetMinSize((PANEL_WID, -1))114 self. sizer2.SetMinSize((PANEL_WID, -1))115 self. sizer3.SetMinSize((PANEL_WID, -1))116 self.vbox.Add(self. sizer1)117 self.vbox.Add(self. sizer2)118 self.vbox.Add(self. sizer3)111 self.data_selection_sizer = wx.BoxSizer(wx.VERTICAL) 112 self.constraints_sizer = wx.BoxSizer(wx.VERTICAL) 113 self.run_fit_sizer = wx.BoxSizer(wx.VERTICAL) 114 115 self.data_selection_sizer.SetMinSize((PANEL_WID, -1)) 116 self.constraints_sizer.SetMinSize((PANEL_WID, -1)) 117 self.run_fit_sizer.SetMinSize((PANEL_WID, -1)) 118 self.vbox.Add(self.data_selection_sizer) 119 self.vbox.Add(self.constraints_sizer) 120 self.vbox.Add(self.run_fit_sizer) 119 121 self.SetSizer(self.vbox) 120 122 self.Centre() 123 124 def set_state(self): 125 """ 126 Define a set of state parameters for saving simultaneous fits. 127 """ 128 self._set_constraint() 129 self.state.fit_page_no = self.uid 130 self.state.select_all = self.cb1.GetValue() 131 self.state.model_list = self.model_list 132 self.state.model_to_fit = self.model_to_fit 133 self.state.no_constraint = self.nb_constraint 134 self.state.constraint_dict = self.constraint_dict 135 self.state.constraints_list = self.constraints_list 136 return self.get_state() 137 138 def get_state(self): 139 """ 140 Return the state of the current page 141 :return: self.state 142 """ 143 return self.state 121 144 122 145 def draw_page(self): … … 131 154 # create blank list of constraints 132 155 self.model_list = [] 133 self.model_to Fit = []156 self.model_to_fit = [] 134 157 self.constraints_list = [] 135 158 self.constraint_dict = {} … … 144 167 145 168 #------------------------------------------------------- 146 # #setup sizer1 (which fitpages to include)147 self. sizer1.Clear(True)169 # setup sizer1 (which fitpages to include) 170 self.data_selection_sizer.Clear(True) 148 171 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Combinations") 149 172 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) … … 151 174 sizer_couples = wx.GridBagSizer(5, 5) 152 175 153 # This if statement should be obsolete and can be removed in version 4154 # Leave it here for now as no time to thoroughly test. However if no155 # fit page is found the menu item that calls this page is inactive156 # Nov. 22 2015 --PDB176 # The wx GUI has a flag to enable a menu item, but can still be 177 # reached via scripting. There is no guearantee future GUI 178 # implementations force this check, either. 179 # IMHO, this if statement should stay -- JRK 2016-OCT-05 157 180 if len(self.page_finder) == 0: 158 181 msg = " No fit combinations are found! \n\n" … … 161 184 sizer_title.Add(wx.StaticText(self, wx.ID_ANY, msg)) 162 185 else: 163 # #store model186 # store model 164 187 self._store_model() 165 188 … … 171 194 wx.TOP | wx.BOTTOM | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 172 195 sizer_title.Add(self.cb1, 0, 173 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, border=5) 174 175 ## draw list of model and data names 196 wx.TOP | wx.BOTTOM | wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 197 border=5) 198 199 # draw list of model and data names 176 200 self._fill_sizer_model_list(sizer_couples) 177 201 178 202 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=5) 179 203 boxsizer1.Add(sizer_couples, 1, flag=wx.TOP | wx.BOTTOM, border=5) 180 self. sizer1.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10)181 #self.sizer1.Layout()204 self.data_selection_sizer.Add(boxsizer1, 1, wx.EXPAND | wx.ALL, 10) 205 # self.sizer1.Layout() 182 206 183 207 #-------------------------------------------------------- 184 ## set up the other 2 sizers: the constraints list and the 185 ## buttons (fit, help etc) sizer at the bottom of the page. 186 ## Note: the if statement should be removed along with the above 187 ## if statement as soon as it can be properly tested. 188 ## Nov. 22 2015 --PDB 208 # set up the other 2 sizers: the constraints list and the 209 # buttons (fit, help etc) sizer at the bottom of the page. 210 # Note: the if statement should be removed along with the above 211 # if statement as soon as it can be properly tested. 212 # Nov. 22 2015 --PDB 213 # As above, this page can be accessed through other means than the 214 # base SasView GUI. 215 # Oct. 5, 2016 --JRK 189 216 if len(self.page_finder) > 0: 190 # #draw the sizer containing constraint info217 # draw the sizer containing constraint info 191 218 if not self.batch_on: 192 219 self._fill_sizer_constraint() 193 # #draw fit button sizer220 # draw fit button sizer 194 221 self._fill_sizer_fit() 195 196 222 197 223 def _fill_sizer_model_list(self, sizer): … … 201 227 ix = 0 202 228 iy = 0 203 list = []204 229 sizer.Clear(True) 205 230 … … 209 234 new_name.SetForegroundColour(wx.WHITE) 210 235 sizer.Add(new_name, (iy, ix), (1, 1), 211 236 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 212 237 ix += 2 213 238 model_type = wx.StaticText(self, wx.ID_ANY, ' Model ') … … 215 240 model_type.SetForegroundColour(wx.WHITE) 216 241 sizer.Add(model_type, (iy, ix), (1, 1), 217 242 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 218 243 ix += 1 219 244 data_used = wx.StaticText(self, wx.ID_ANY, ' Data ') … … 221 246 data_used.SetForegroundColour(wx.WHITE) 222 247 sizer.Add(data_used, (iy, ix), (1, 1), 223 248 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 224 249 ix += 1 225 250 tab_used = wx.StaticText(self, wx.ID_ANY, ' FitPage ') … … 302 327 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 303 328 304 self. sizer2.Clear(True)329 self.constraints_sizer.Clear(True) 305 330 if self.batch_on: 306 if self. sizer2.IsShown():307 self. sizer2.Show(False)331 if self.constraints_sizer.IsShown(): 332 self.constraints_sizer.Show(False) 308 333 return 309 334 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit Constraints") 310 box sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL)335 box_sizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 311 336 sizer_title = wx.BoxSizer(wx.HORIZONTAL) 312 337 self.sizer_all_constraints = wx.BoxSizer(wx.HORIZONTAL) … … 338 363 339 364 self.btAdd = wx.Button(self, self.ID_ADD, 'Add') 340 self.btAdd.Bind(wx.EVT_BUTTON, self._on Add_constraint,365 self.btAdd.Bind(wx.EVT_BUTTON, self._on_add_constraint, 341 366 id=self.btAdd.GetId()) 342 367 self.btAdd.SetToolTipString("Add another constraint?") … … 344 369 345 370 text_hint = wx.StaticText(self, wx.ID_ANY, 346 "Example: [M0][param ter] = M1.parameter")371 "Example: [M0][parameter] = M1.parameter") 347 372 sizer_button.Add(text_hint, 0, 348 373 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) … … 350 375 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 10) 351 376 352 boxsizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 353 boxsizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 354 border=10) 355 boxsizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 356 border=10) 357 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 358 359 self.sizer2.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 360 377 box_sizer1.Add(sizer_title, flag=wx.TOP | wx.BOTTOM, border=10) 378 box_sizer1.Add(self.sizer_all_constraints, flag=wx.TOP | wx.BOTTOM, 379 border=10) 380 box_sizer1.Add(self.sizer_constraints, flag=wx.TOP | wx.BOTTOM, 381 border=10) 382 box_sizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 383 384 self.constraints_sizer.Add(box_sizer1, 0, wx.EXPAND | wx.ALL, 10) 361 385 362 386 def _fill_sizer_fit(self): … … 364 388 Draw fit button 365 389 """ 366 self. sizer3.Clear(True)390 self.run_fit_sizer.Clear(True) 367 391 box_description = wx.StaticBox(self, wx.ID_ANY, "Fit ") 368 392 boxsizer1 = wx.StaticBoxSizer(box_description, wx.VERTICAL) 369 393 sizer_button = wx.BoxSizer(wx.HORIZONTAL) 370 394 371 # Fit button395 # Fit button 372 396 self.btFit = wx.Button(self, self.ID_FIT, 'Fit', size=wx.DefaultSize) 373 self.btFit.Bind(wx.EVT_BUTTON, self.on Fit, id=self.btFit.GetId())397 self.btFit.Bind(wx.EVT_BUTTON, self.on_fit, id=self.btFit.GetId()) 374 398 self.btFit.SetToolTipString("Perform fit.") 375 399 376 # General Help button400 # General Help button 377 401 self.btHelp = wx.Button(self, wx.ID_HELP, 'HELP') 378 402 self.btHelp.SetToolTipString("Simultaneous/Constrained Fitting help.") 379 self.btHelp.Bind(wx.EVT_BUTTON, self._on Help)380 381 # hint text on button line403 self.btHelp.Bind(wx.EVT_BUTTON, self._on_help) 404 405 # hint text on button line 382 406 if self.batch_on: 383 407 text = " Fit in Parallel all Data sets\n" … … 393 417 394 418 boxsizer1.Add(sizer_button, flag=wx.TOP | wx.BOTTOM, border=10) 395 self. sizer3.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10)396 397 def on Remove(self, event):419 self.run_fit_sizer.Add(boxsizer1, 0, wx.EXPAND | wx.ALL, 10) 420 421 def on_remove(self, event): 398 422 """ 399 423 Remove constraint fields … … 406 430 return 407 431 wx.CallAfter(self._remove_after, event.GetId()) 408 # self._onAdd_constraint(None)432 # self._onAdd_constraint(None) 409 433 410 434 def _remove_after(self, id): … … 416 440 self.constraints_list.remove(item) 417 441 self.nb_constraint -= 1 418 self. sizer2.Layout()442 self.constraints_sizer.Layout() 419 443 self.FitInside() 420 444 break 421 445 422 def on Fit(self, event):446 def on_fit(self, event): 423 447 """ 424 448 signal for fitting … … 435 459 flag = (self._manager.sim_page.uid == self.uid) 436 460 437 # #making sure all parameters content a constraint461 # making sure all parameters content a constraint 438 462 if not self.batch_on and self.show_constraint.GetValue(): 439 463 if not self._set_constraint(): 440 464 return 441 # #model was actually selected from this page to be fit442 if len(self.model_to Fit) >= 1:465 # model was actually selected from this page to be fit 466 if len(self.model_to_fit) >= 1: 443 467 self.manager._reset_schedule_problem(value=0) 444 468 for item in self.model_list: … … 456 480 msg = "Select at least one model check box to fit " 457 481 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 482 self.set_state() 458 483 459 484 def _on_fit_complete(self): … … 467 492 """ 468 493 Attempt to stop the fitting thread 469 """ 470 if event != None: 494 495 :param event: Event handler when stop fit is clicked 496 """ 497 if event is not None: 471 498 event.Skip() 472 499 self.manager.stop_fit(self.uid) … … 485 512 self.btFit.Enable(True) 486 513 487 def _on Help(self, event):514 def _on_help(self, event): 488 515 """ 489 516 Bring up the simultaneous Fitting Documentation whenever the HELP … … 494 521 versions of Wx (before 2.9) and thus not the release version of 495 522 installers, the help comes up at the top level of the file as 496 web browser does not pass anything past the # to the browser when it is523 web browser does not pass anything past the # to the browser when it is 497 524 running "file:///...." 498 525 499 :param ev t: Triggers on clicking the help button526 :param event: Triggers on clicking the help button 500 527 """ 501 528 _TreeLocation = "user/sasgui/perspectives/fitting/fitting_help.html" … … 510 537 511 538 :param manager: instance of plugin fitting 512 513 539 """ 514 540 self.manager = manager … … 518 544 check all models names 519 545 """ 520 self.model_to Fit = []521 if self.cb1.GetValue() == True:546 self.model_to_fit = [] 547 if self.cb1.GetValue(): 522 548 for item in self.model_list: 523 549 if item[0].IsEnabled(): 524 550 item[0].SetValue(True) 525 self.model_to Fit.append(item)526 527 # #constraint info551 self.model_to_fit.append(item) 552 553 # constraint info 528 554 self._store_model() 529 555 if not self.batch_on: 530 # #display constraint fields556 # display constraint fields 531 557 if (self.show_constraint.GetValue() and 532 558 len(self.constraints_list) == 0): … … 538 564 539 565 if not self.batch_on: 540 # #constraint info566 # constraint info 541 567 self._hide_constraint() 542 568 … … 544 570 self.FitInside() 545 571 546 547 572 def check_model_name(self, event): 548 573 """ 549 574 Save information related to checkbox and their states 550 575 """ 551 self.model_toFit = [] 552 cbox = event.GetEventObject() 576 self.model_to_fit = [] 553 577 for item in self.model_list: 554 if item[0].GetValue() == True:555 self.model_to Fit.append(item)578 if item[0].GetValue(): 579 self.model_to_fit.append(item) 556 580 else: 557 if item in self.model_to Fit:558 self.model_to Fit.remove(item)581 if item in self.model_to_fit: 582 self.model_to_fit.remove(item) 559 583 self.cb1.SetValue(False) 560 584 561 # #display constraint fields562 if len(self.model_to Fit) >= 1:585 # display constraint fields 586 if len(self.model_to_fit) >= 1: 563 587 self._store_model() 564 588 if not self.batch_on and self.show_constraint.GetValue() and\ … … 567 591 self._show_constraint() 568 592 569 elif len(self.model_to Fit) < 1:570 # #constraint info593 elif len(self.model_to_fit) < 1: 594 # constraint info 571 595 self._hide_constraint() 572 596 573 597 self._update_easy_setup_cb() 574 # #set the value of the main check button575 if len(self.model_list) == len(self.model_to Fit):598 # set the value of the main check button 599 if len(self.model_list) == len(self.model_to_fit): 576 600 self.cb1.SetValue(True) 577 601 self.FitInside() … … 585 609 Update easy setup combobox on selecting a model 586 610 """ 587 if self.model_cbox_left == None or self.model_cbox_right ==None:588 return 589 590 models = [(item[3].name, item[3]) for item in self.model_to Fit]611 if self.model_cbox_left is None or self.model_cbox_right is None: 612 return 613 614 models = [(item[3].name, item[3]) for item in self.model_to_fit] 591 615 setComboBoxItems(self.model_cbox_left, models) 592 616 setComboBoxItems(self.model_cbox_right, models) … … 595 619 if self.model_cbox_left.GetSelection() == wx.NOT_FOUND: 596 620 self.model_cbox_left.SetSelection(0) 597 self. sizer2.Layout()621 self.constraints_sizer.Layout() 598 622 599 623 def _store_model(self): … … 601 625 Store selected model 602 626 """ 603 if len(self.model_to Fit) < 1:604 return 605 for item in self.model_to Fit:627 if len(self.model_to_fit) < 1: 628 return 629 for item in self.model_to_fit: 606 630 model = item[3] 607 631 page_id = item[2] … … 612 636 Show fields to add constraint 613 637 """ 614 if len(self.model_to Fit) < 1:638 if len(self.model_to_fit) < 1: 615 639 msg = "Select at least 1 model to add constraint " 616 640 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 617 # #hide button641 # hide button 618 642 self._hide_constraint() 619 643 return … … 632 656 """ 633 657 box_description = wx.StaticBox(self, wx.ID_ANY, "Easy Setup ") 634 box sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL)658 box_sizer = wx.StaticBoxSizer(box_description, wx.HORIZONTAL) 635 659 sizer_constraint = wx.BoxSizer(wx.HORIZONTAL) 636 660 self.model_cbox_left = wx.ComboBox(self, wx.ID_ANY, style=wx.CB_READONLY) … … 650 674 651 675 for id, model in self.constraint_dict.iteritems(): 652 # #check if all parameters have been selected for constraint653 # #then do not allow add constraint on parameters676 # check if all parameters have been selected for constraint 677 # then do not allow add constraint on parameters 654 678 self.model_cbox_left.Append(str(model.name), model) 655 679 self.model_cbox_left.Select(0) 656 680 for id, model in self.constraint_dict.iteritems(): 657 # #check if all parameters have been selected for constraint658 # #then do not allow add constraint on parameters681 # check if all parameters have been selected for constraint 682 # then do not allow add constraint on parameters 659 683 self.model_cbox_right.Append(str(model.name), model) 660 box sizer.Add(self.model_cbox_left,684 box_sizer.Add(self.model_cbox_left, 661 685 flag=wx.RIGHT | wx.EXPAND, border=10) 662 # boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),686 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 663 687 # flag=wx.RIGHT | wx.EXPAND, border=5) 664 box sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5)665 box sizer.Add(self.model_cbox_right,688 box_sizer.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 689 box_sizer.Add(self.model_cbox_right, 666 690 flag=wx.RIGHT | wx.EXPAND, border=10) 667 # boxsizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"),691 # box_sizer.Add(wx.StaticText(self, wx.ID_ANY, ".parameters"), 668 692 # flag=wx.RIGHT | wx.EXPAND, border=5) 669 box sizer.Add((20, -1))670 box sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5)671 sizer_constraint.Add(box sizer, flag=wx.RIGHT | wx.EXPAND, border=5)693 box_sizer.Add((20, -1)) 694 box_sizer.Add(self.set_button, flag=wx.RIGHT | wx.EXPAND, border=5) 695 sizer_constraint.Add(box_sizer, flag=wx.RIGHT | wx.EXPAND, border=5) 672 696 self.sizer_all_constraints.Insert(before=0, 673 697 item=sizer_constraint, … … 699 723 return 700 724 param_list = [] 701 param_list B= []725 param_list_b = [] 702 726 selection = self.model_cbox_left.GetCurrentSelection() 703 727 model_left = self.model_cbox_left.GetValue() 704 728 model = self.model_cbox_left.GetClientData(selection) 705 selection B= self.model_cbox_right.GetCurrentSelection()729 selection_b = self.model_cbox_right.GetCurrentSelection() 706 730 model_right = self.model_cbox_right.GetValue() 707 model B = self.model_cbox_right.GetClientData(selectionB)731 model_b = self.model_cbox_right.GetClientData(selection_b) 708 732 for id, dic_model in self.constraint_dict.iteritems(): 709 733 if model == dic_model: 710 734 param_list = self.page_finder[id].get_param2fit() 711 if model B== dic_model:712 param_list B= self.page_finder[id].get_param2fit()713 if len(param_list) > 0 and len(param_list B) > 0:735 if model_b == dic_model: 736 param_list_b = self.page_finder[id].get_param2fit() 737 if len(param_list) > 0 and len(param_list_b) > 0: 714 738 break 715 739 num_cbox = 0 … … 717 741 for param in param_list: 718 742 num_cbox += 1 719 if param in param_list B:743 if param in param_list_b: 720 744 item = self.constraints_list[-1] 721 745 item.model_cbox.SetStringSelection(model_left) … … 744 768 """ 745 769 Show constraint fields 770 :param dict: dictionary mapping constraint values 746 771 """ 747 772 self.btAdd.Show(True) … … 750 775 for id, model in self.constraint_dict.iteritems(): 751 776 nb_fit_param += len(self.page_finder[id].get_param2fit()) 752 # #Don't add anymore777 # Don't add anymore 753 778 if len(self.constraints_list) == nb_fit_param: 754 779 msg = "Cannot add another constraint. Maximum of number " … … 756 781 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 757 782 self.sizer_constraints.Layout() 758 self. sizer2.Layout()783 self.constraints_sizer.Layout() 759 784 return 760 if len(self.model_to Fit) < 1:785 if len(self.model_to_fit) < 1: 761 786 msg = "Select at least 1 model to add constraint " 762 787 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 763 788 self.sizer_constraints.Layout() 764 self. sizer2.Layout()789 self.constraints_sizer.Layout() 765 790 return 766 791 … … 771 796 model_cbox.Clear() 772 797 for id, model in self.constraint_dict.iteritems(): 773 # #check if all parameters have been selected for constraint774 # #then do not allow add constraint on parameters798 # check if all parameters have been selected for constraint 799 # then do not allow add constraint on parameters 775 800 model_cbox.Append(str(model.name), model) 776 801 wx.EVT_COMBOBOX(model_cbox, wx.ID_ANY, self._on_select_model) … … 789 814 # Remove button 790 815 #btRemove = wx.Button(self, self.ID_REMOVE, 'Remove') 791 bt Remove = wx.Button(self, self._ids.next(), 'Remove')792 bt Remove.Bind(wx.EVT_BUTTON, self.onRemove,793 id=bt Remove.GetId())794 bt Remove.SetToolTipString("Remove constraint.")795 bt Remove.Hide()816 bt_remove = wx.Button(self, self._ids.next(), 'Remove') 817 bt_remove.Bind(wx.EVT_BUTTON, self.on_remove, 818 id=bt_remove.GetId()) 819 bt_remove.SetToolTipString("Remove constraint.") 820 bt_remove.Hide() 796 821 797 822 # Hid the add button, if it exists … … 804 829 sizer_constraint.Add(egal_txt, flag=wx.RIGHT | wx.EXPAND, border=5) 805 830 sizer_constraint.Add(constraint, flag=wx.RIGHT | wx.EXPAND, border=10) 806 sizer_constraint.Add(bt Remove, flag=wx.RIGHT | wx.EXPAND, border=10)831 sizer_constraint.Add(bt_remove, flag=wx.RIGHT | wx.EXPAND, border=10) 807 832 808 833 self.sizer_constraints.Insert(before=self.nb_constraint, … … 810 835 border=5) 811 836 c = ConstraintLine(model_cbox, param_cbox, egal_txt, 812 constraint, bt Remove, sizer_constraint)837 constraint, bt_remove, sizer_constraint) 813 838 self.constraints_list.append(c) 814 839 815 840 self.nb_constraint += 1 816 841 self.sizer_constraints.Layout() 817 self. sizer2.Layout()818 self.Layout 842 self.constraints_sizer.Layout() 843 self.Layout() 819 844 820 845 def _hide_constraint(self): … … 841 866 self.sizer_constraints.Clear(True) 842 867 self.sizer_constraints.Layout() 843 self. sizer2.Layout()844 self.Layout 868 self.constraints_sizer.Layout() 869 self.Layout() 845 870 self.FitInside() 846 871 847 872 def _on_select_model(self, event): 848 873 """ 849 fill combo xbox with list of parameters874 fill combo box with list of parameters 850 875 """ 851 876 if not self.constraints_list: 852 877 return 853 878 854 # #This way PC/MAC both work, instead of using event.GetClientData().879 # This way PC/MAC both work, instead of using event.GetClientData(). 855 880 model_cbox = self.constraints_list[-1].model_cbox 856 881 n = model_cbox.GetCurrentSelection() … … 867 892 param_cbox = self.constraints_list[-1].param_cbox 868 893 param_cbox.Clear() 869 # #insert only fittable paramaters894 # insert only fittable paramaters 870 895 for param in param_list: 871 896 param_cbox.Append(str(param), model) 872 897 param_cbox.Show(True) 873 898 874 bt Remove = self.constraints_list[-1].btRemove875 bt Remove.Show(True)899 bt_remove = self.constraints_list[-1].btRemove 900 bt_remove.Show(True) 876 901 self.btAdd.Show(True) 877 902 # self.Layout() … … 882 907 Store the appropriate constraint in the page_finder 883 908 """ 884 # #This way PC/MAC both work, instead of using event.GetClientData().885 # n = self.param_cbox.GetCurrentSelection()886 # model = self.param_cbox.GetClientData(n)887 # param = event.GetString()909 # This way PC/MAC both work, instead of using event.GetClientData(). 910 # n = self.param_cbox.GetCurrentSelection() 911 # model = self.param_cbox.GetClientData(n) 912 # param = event.GetString() 888 913 889 914 if self.constraints_list: … … 891 916 self.constraints_list[-1].constraint.Show(True) 892 917 893 def _on Add_constraint(self, event):918 def _on_add_constraint(self, event): 894 919 """ 895 920 Add another line for constraint … … 899 924 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 900 925 return 901 # #check that a constraint is added926 # check that a constraint is added 902 927 # before allow to add another constraint 903 928 for item in self.constraints_list: … … 913 938 model = item.param_cbox.GetClientData( 914 939 item.param_cbox.GetCurrentSelection()) 915 if model !=None:940 if model is not None: 916 941 msg = " Enter a constraint for %s.%s! " % (model.name, 917 942 item.param_cbox.GetString(0)) … … 920 945 wx.PostEvent(self.parent.parent, StatusEvent(status=msg)) 921 946 return 922 # #some model or parameters can be constrained947 # some model or parameters can be constrained 923 948 self._show_constraint() 924 949 self.FitInside() … … 980 1005 def on_set_focus(self, event=None): 981 1006 """ 982 The 1007 The derivative class is on focus if implemented 983 1008 """ 984 1009 if self.parent is not None: … … 995 1020 cbox.Append(name, value) 996 1021 cbox.SetStringSelection(selected) 1022 1023 1024 class SimFitPageState: 1025 """ 1026 State of the simultaneous fit page for saving purposes 1027 """ 1028 1029 def __init__(self): 1030 # Sim Fit Page Number 1031 self.fit_page_no = None 1032 # Select all data 1033 self.select_all = False 1034 # Data sets sent to fit page 1035 self.model_list = [] 1036 # Data sets to be fit 1037 self.model_to_fit = [] 1038 # Number of constraints 1039 self.no_constraint = 0 1040 # Dictionary of constraints 1041 self.constraint_dict = {} 1042 # List of constraints 1043 self.constraints_list = [] 1044 1045 def load_from_save_state(self, fit): 1046 """ 1047 Load in a simultaneous/constrained fit from a save state 1048 :param fit: Fitpanel object 1049 :return: None 1050 """ 1051 1052 model_map = {} 1053 if fit.fit_panel.sim_page is None: 1054 fit.fit_panel.add_sim_page() 1055 sim_page = fit.fit_panel.sim_page 1056 1057 # Process each model and associate old M# with new M# 1058 i = 0 1059 for model in sim_page.model_list: 1060 model_id = self._format_id(model[1].keys()[0]) 1061 for saved_model in self.model_list: 1062 save_id = saved_model.pop('name') 1063 saved_model['name'] = save_id 1064 save_id = self._format_id(save_id) 1065 if save_id == model_id: 1066 model_map[saved_model.pop('fit_page_source')] = \ 1067 model[3].name 1068 check = bool(saved_model.pop('checked')) 1069 sim_page.model_list[i][0].SetValue(check) 1070 break 1071 i += 1 1072 sim_page.check_model_name(None) 1073 1074 if len(self.constraints_list) > 0: 1075 sim_page.hide_constraint.SetValue(False) 1076 sim_page.show_constraint.SetValue(True) 1077 sim_page._display_constraint(None) 1078 1079 for index, item in enumerate(self.constraints_list): 1080 model_cbox = item.pop('model_cbox') 1081 if model_cbox != "": 1082 constraint_value = item.pop('constraint') 1083 param = item.pop('param_cbox') 1084 equality = item.pop('egal_txt') 1085 for key, value in model_map.iteritems(): 1086 model_cbox.replace(key, value) 1087 constraint_value.replace(key, value) 1088 1089 sim_page.constraints_list[index][0].SetValue(model_cbox) 1090 sim_page._on_select_model(None) 1091 sim_page.constraints_list[index][1].SetValue(param) 1092 sim_page.constraints_list[index][2].SetLabel(equality) 1093 sim_page.constraints_list[index][3].SetValue(constraint_value) 1094 sim_page._on_add_constraint(None) 1095 1096 def _format_id(self, original_id): 1097 original_id = original_id.rstrip('1234567890.') 1098 new_id_list = original_id.split() 1099 new_id = ' '.join(new_id_list) 1100 return new_id
Note: See TracChangeset
for help on using the changeset viewer.